#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll N=100,INF=1LL<<63,M=500; ll f[N][N]; int n; ll a[N]; bool cmp(vector<ll>& a,vector<ll>& b) { while(a.size()&&a.back()==0) a.pop_back(); while(b.size()&&b.back()==0) b.pop_back(); if(a.size()<b.size()) { return false; }else if(a.size()>b.size()) { return true; }else { for(int i=a.size()-1;i>=0;i--) { if(a[i]>b[i]) return 1; else if(a[i]<b[i]) return 0; } } return 0; } vector<ll>mul(vector<ll>A,ll b) { vector<ll>C; ll r=0; for(int i=0;i<A.size();i++) { A[i]=A[i]*b; } for(int i=0;i<A.size();i++) { r=r+A[i]; C.push_back((r)%10); r/=10; } while(r) { C.push_back(r%10); r/=10; } while(C.size()&&C.back()==0) C.pop_back(); return C; } vector<ll>add(vector<ll>&A,vector<ll>&B) { ll r=0; vector<ll>C; for(int i=0;i<A.size()||i<B.size();i++) { if(i<A.size()) r+=A[i]; if(i<B.size()) r+=B[i]; C.push_back(r%10); r/=10; } if(r) C.push_back(r); while(C.size()&&C.back()==0) C.pop_back(); return C; } int main() { cin>>n; vector<ll>f[n+1][n+1]; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) f[i][j].resize(M+1); } for(int i=1;i<=n;i++) { cin>>a[i]; } vector<ll>temp; temp.push_back(1); for(int len=3;len<=n;len++) { for(int i=1;i+len-1<=n;i++) { int j=i+len-1; f[i][j][M]=1; for(int k=i+1;k<j;k++) { while(temp.size()) temp.pop_back(); temp.push_back(1); temp=mul(temp,a[k]); temp=mul(temp,a[i]); temp=mul(temp,a[j]); temp=add(temp,f[i][k]); temp=add(temp,f[k][j]); if(cmp(f[i][j],temp)) { f[i][j]=temp; } // f[i][j]=min(f[i][j],f[i][k]+f[k][j]+1LL*a[k]*a[i]*a[j]); } } } for(int i=f[1][n].size()-1;i>=0;i--) { cout<<f[1][n][i]; } //cout<<f[1][n]<<endl; }