#include <iostream>
#define SIZE 505
//Matrix Chain Multiplication
int dim[ SIZE ], n;
long cost[ SIZE ][ SIZE ];
void mcm(int n, int dim[ 10 ]) {
int j;
for(int i = 1; i <= n; i++) cost[i][i] = 0;
for(int k = 1; k <= n - 1; ++k)
for(int i = 1; i <= n - k; i++) {
j = i + k;
cost[i][j] = 1LL<<50;
for(int q = i; q <= j - 1; q++) {
long m = cost[i][q] + cost[q+1][j] + dim[i] * dim[q+1] * dim[j+1];
if(cost[i][j]>m) {
cost[i][j] = m;
cost[j][i] = 1;
}
}
}
std::cout<<cost[1][n];
}
int main(int argc, char const *argv[]) {
//freopen("podm.in","r",stdin);
//freopen("podm.out","w",stdout);
std::cin>>n;
for(int i = 1; i <= n + 1; i++) std::cin>>dim[i];
//test: 10 1 10 1 10
mcm( n, dim);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojZGVmaW5lIFNJWkUgNTA1CgovL01hdHJpeCBDaGFpbiBNdWx0aXBsaWNhdGlvbgoKaW50IGRpbVsgU0laRSBdLCBuOwoKbG9uZyBjb3N0WyBTSVpFIF1bIFNJWkUgXTsKCnZvaWQgbWNtKGludCBuLCBpbnQgZGltWyAxMCBdKSB7CgogICAgICBpbnQgajsKCiAgICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSBjb3N0W2ldW2ldID0gMDsKCiAgICAgIGZvcihpbnQgayA9IDE7IGsgPD0gbiAtIDE7ICsraykKCiAgICAgICAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG4gLSBrOyBpKyspIHsKCiAgICAgICAgICAgICAgIGogPSBpICsgazsKCiAgICAgICAgICAgICAgIGNvc3RbaV1bal0gPSAxTEw8PDUwOwoKICAgICAgICAgICAgICAgZm9yKGludCBxID0gaTsgcSA8PSBqIC0gMTsgcSsrKSB7CgogICAgICAgICAgICAgICAgIGxvbmcgbSA9IGNvc3RbaV1bcV0gKyBjb3N0W3ErMV1bal0gKyBkaW1baV0gKiBkaW1bcSsxXSAqIGRpbVtqKzFdOwoKICAgICAgICAgICAgICAgICBpZihjb3N0W2ldW2pdPm0pIHsKCiAgICAgICAgICAgICAgICAgICBjb3N0W2ldW2pdID0gbTsKCiAgICAgICAgICAgICAgICAgICBjb3N0W2pdW2ldID0gMTsKICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgIH0KICAgICAgfQoKICAgICAgc3RkOjpjb3V0PDxjb3N0WzFdW25dOwp9CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciBjb25zdCAqYXJndltdKSB7CgogICAgICAgIC8vZnJlb3BlbigicG9kbS5pbiIsInIiLHN0ZGluKTsKCiAgICAgICAgLy9mcmVvcGVuKCJwb2RtLm91dCIsInciLHN0ZG91dCk7CgoKICBzdGQ6OmNpbj4+bjsKCiAgZm9yKGludCBpID0gMTsgaSA8PSBuICsgMTsgaSsrKSBzdGQ6OmNpbj4+ZGltW2ldOwogIAogIC8vdGVzdDogMTAgMSAxMCAxIDEwCiAgbWNtKCBuLCBkaW0pOwoKICByZXR1cm4gMDsKfQ==