#include <cstdio> #include <algorithm> using namespace std; const int maxn = 222; int a[maxn]; int dp[maxn][maxn]; int n; int main() { int i, k, len, l, r; scanf("%d", &n); for(i = 1; i <= n; ++i) scanf("%d", &a[i]), a[n+i]=a[i];//环转环链技巧 int ans = 0; for(len = 2; len <= n; ++len)//枚举区间长度 for(l = 1; l+len-1 < 2*n; ++l)//枚举区间左端点 { r = l + len - 1;//区间右端点 for(k = l; k < r; ++k)//枚举断点 dp[l][r] = max(dp[l][r], dp[l][k]+dp[k+1][r]+a[l]*a[k+1]*a[r+1]); ans = max(ans, dp[l][r]); } printf("%d\n", ans); return 0; }