#include"bits/stdc++.h"using namespace std;const int N = 310;int w[N];int f[N][N][N];int n;int dp(int l, int r, int p) { if(l > r) return 0; if(f[l][r][p] != -1) return f[l][r][p]; int ret = 2e9; for(int i = l; i<=r ; i++) { int left = dp(l,i-1,i); int right = dp(i+1,r,i); ret = min(ret,left + right + w[i]*w[p]); } f[l][r][p] = ret; return ret;}int main() { cin >> n; memset(f,-1,sizeof f); for(int i = 1; i<=n ; i++) cin >> w[i]; cout << dp(1,n,0); return 0;}