import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
import std.typecons;
import std.math;
import std.range;
void main()
{
    auto count = readln().strip.to!int;
    auto m = new int[(count + 1) * (count + 1)].chunks(count + 1);
    auto p = new int[count + 1];
    foreach (i; iota(count))
    {
        int x, y;
        scanf("%d %d", &x, &y);
        p[i] = x;
        p[i + 1] = y;
    }
    for (int l = 2; l <= count; l++)
    {
        for (int i = 1; i <= count - l + 1; i++)
        {
            auto j = i + l - 1;
            m[i][j] = int.max;
            for (int k = i; k <= j - 1; k++)
            {
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }
    writeln(m[1][count]);

}
