import std.array, std.stdio, std.conv, std.string, std.math, std.random, std.range,std.functional, std.typecons;
import std.algorithm.searching, std.algorithm.sorting, std.algorithm.iteration, std.algorithm.comparison;

alias M = Tuple!(int, "r", int, "c");
 
long count;
long[][] dp;
M[] list;

 
void main()
{
    int N = readln().strip.to!int;
    dp.length = N;
    dp.each!((ref a)=>a.length = N);
    dp.each!((ref a)=>a[] = -1);

    foreach(i; 0..N)
    {
        auto input = readln().split.to!(int[2]);
        list ~= M(input[0], input[1]);
    }
    foreach(i; 0..N)
    {
        dp[i][i] = 0;
    }
    foreach(i; 0..N-1)
    {
        dp[i][i+1] = list[i].r*list[i].c*list[i+1].c;
    }
    writeln(rec(0, N-1));
}


long rec(int r, int c)
{
    if(dp[r][c]!=-1)
    {
        return dp[r][c];
    }

    long minCost=long.max;
    foreach(s; r..c)
    {
        minCost = min(minCost, rec(r, s) + rec(s+1,c) + list[r].r*list[s].c*list[c].c);
    }
    dp[r][c] = minCost;
    return minCost;
}

