import java.io.*;
import java.math.BigInteger;
public class Main {
static BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
static int N = 55;
static BigInteger[][] dp = new BigInteger[N][N];
static BigInteger[] a = new BigInteger[N];
static final String INF = String.valueOf("10000000000000000000000000000"); //28个0
public static void main(String[] args) throws Exception{
int n = Integer.valueOf(read.readLine());
String[] ss = read.readLine().split(" ");
for(int i = 1; i <= n; i++){
a[i] = new BigInteger(ss[i - 1]);
}
for(int len = 2; len <= n; len++){
for(int i = 1; i + len - 1 <= n; i++){ //注意, 这里的r小于等于n
int j = i + len - 1;
dp[i][j] = new BigInteger(INF); //初始化为最大值
if(len == 2) dp[i][j] = new BigInteger("0");
else {
for(int k = i + 1; k < j; k++){
dp[i][j] = dp[i][j].min(dp[i][k].add(dp[k][j]).add((a[i].multiply(a[k]).multiply(a[j]))));
}
}
}
}
System.out.println(dp[1][n]);
}
}