#include<stdio.h>
#include<string.h>
int main()
{
long long n,a[222],f[222][222],j,i,k,max,e=0;
memset(a,0,sizeof(a));
memset(f,0,sizeof(f));
scanf("%lld",&n);
for(i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
a[n+i]=a[i];
}
for(j=2;j<=2*n;j++)//形成环结构
{
for(i=j-1;i>=1&&i>j-n;i--) //要求在n个的范围内,保证其循环
{
max=0;
for(k=i;k<j;k++)
{
if(max<f[i][k]+f[k+1][j]+a[i]*a[k+1]*a[j+1])
max=f[i][k]+f[k+1][j]+a[i]*a[k+1]*a[j+1];
}
f[i][j]=max;
if(e<f[i][j]) e=f[i][j];
}
}
printf("%lld",e);
return 0;
}