import std.stdio, std.string, std.conv, std.algorithm;

void main() {
    int n = readln.chomp.to!int;
    int[] p = new int[n+1];
    foreach(i; 1 .. n+1) {
        int[] tmp = readln.chomp.split.to!(int[]);
        p[i-1] = tmp[0], p[i] = tmp[1];
    }
    int[][] m = new int[][](n+1, n+1);
    foreach (l; 2 .. n+1) {
        foreach (i; 1 .. n-l+2) {
            int j = i + l - 1;
            m[i][j] = 1 << 21;
            foreach (k; i .. j) {
                m[i][j] = min(m[i][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
            }
        }
    }
    m[1][n].writeln;
}
