#include<stdio.h>
#include<vector>
using namespace std;
#define ll long long
const ll MAX=1LL<<60;
int n;
ll a[505][505];
vector <int> b;
int main()
{
//freopen("podm.in","r",stdin);
//freopen("podm.out","w",stdout);
scanf("%d",&n);
for(int i=0;i<=n;i++)
{
int x;
scanf("%d",&x);
b.push_back(x);
}
for(int l=1;l<=n;l++)
{
for(int i=1;i+l<=n;i++)
{
int j=i+l;
a[i][j]=MAX;
for(int k=i;k<j;k++)
{
a[i][j]=min(a[i][k]+a[k+1][j]+(ll)b[i-1]*b[k]*b[j],a[i][j]);
}
}
}
printf("%Ld\n",a[1][n]);
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIGxsIGxvbmcgbG9uZwpjb25zdCBsbCBNQVg9MUxMPDw2MDsKaW50IG47CmxsIGFbNTA1XVs1MDVdOwp2ZWN0b3IgPGludD4gYjsKaW50IG1haW4oKQp7CgkvL2ZyZW9wZW4oInBvZG0uaW4iLCJyIixzdGRpbik7CgkKCS8vZnJlb3BlbigicG9kbS5vdXQiLCJ3IixzdGRvdXQpOwoJCglzY2FuZigiJWQiLCZuKTsKCQoJZm9yKGludCBpPTA7aTw9bjtpKyspCgl7CgkJaW50IHg7CgkJc2NhbmYoIiVkIiwmeCk7CgkJYi5wdXNoX2JhY2soeCk7Cgl9CgkKCWZvcihpbnQgbD0xO2w8PW47bCsrKQoJewoJCWZvcihpbnQgaT0xO2krbDw9bjtpKyspCgkJewoJCQlpbnQgaj1pK2w7CgkJCWFbaV1bal09TUFYOwoJCQlmb3IoaW50IGs9aTtrPGo7aysrKQoJCQl7CgkJCQlhW2ldW2pdPW1pbihhW2ldW2tdK2FbaysxXVtqXSsobGwpYltpLTFdKmJba10qYltqXSxhW2ldW2pdKTsKCQkJfQoJCX0KCX0KCXByaW50ZigiJUxkXG4iLGFbMV1bbl0pOwoJcmV0dXJuIDA7Cn0=