#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=210;
int n,i,f[maxn][maxn],a[maxn],N=0;
int read(){
int x,f=1;char ch;
while(ch=getchar(),(ch>'9'||ch<'0')&&ch!='-');
if(ch=='-'){ch=getchar();f=-1;}x=ch-'0';
while(ch=getchar(),ch<='9'&&ch>='0')x=x*10+ch-'0';
return x*f;
}
inline int Init(){
n=read();N=n<<1;
for(i=1;i<=n;i++){a[i]=read(),a[i+n]=a[i];}
a[N+1]=a[1];
}
inline int MAX(int x,int y){return x>y?x:y;}
inline int Winner(){
int ans=0;
for(int d=2;d<=n;d++)
for(i=1;i<=N-d+1;i++){
int j=i+d-1,k,kk=i;
for(int k=i;k<j;k++){
f[i][j]=MAX(f[i][j],f[i][k]+f[k+1][j]+a[i]*a[k+1]*a[j+1]);
ans=MAX(ans,f[i][i+n-1]);
}
}
printf("%d\n",ans);
return 0;
}
int MY(){
freopen("energy.in","r",stdin);
freopen("energy.out","w",stdout);
int main=Init();
int Loser=Winner();
return 0;
}int YOU=MY();
int main(){;}