#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[205],dp[205][205];
ll n,sum;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i],a[i+n]=a[i];
}
a[2*n+1]=a[1];
for(int i=2;i<n;i++){
for(int lt=1;lt+i<=2*n;lt++){
int rt=lt+i;
for(int k=lt;k<rt;k++){
dp[lt][rt]=max(dp[lt][rt],dp[lt][k]+dp[k+1][rt]+a[lt]*a[k+1]*a[rt+1]);
sum=max(sum,dp[lt][rt]);
}
}
}
cout<<sum;
return 0;
}