import std.array, std.stdio, std.conv, std.string, std.math, std.random, std.range,std.functional;
import std.algorithm.searching, std.algorithm.sorting, std.algorithm.iteration, std.algorithm.comparison;
 
long count;
 
void main()
{
    long N = readln().strip.to!long;
    int[2][] matrixList;
    foreach(i; 0..N)
    {
        int[] input = readln().split.to!(int[]);
        matrixList ~= [input[0], input[1]];
    }
    auto cost = minCostFunc(matrixList);
    writeln(cost);
}
long minCostFunc(int[2][] matrixList)
{
    if(matrixList.length == 1)
    {
        return 0;
    }
    if(matrixList.length == 2)
    {
        auto cMatrix = matrixList[0];
        auto nMatrix = matrixList[1];
        return cMatrix[1] * cMatrix[0] * nMatrix[1];
    }
    long minCost = long.max;
    foreach(i; 0..matrixList.length-1)
    {
        auto cMatrix = matrixList[i];
        auto nMatrix = matrixList[i+1];
        int[2] multiMatrix = [cMatrix[0], nMatrix[1]];
        long cost =
            cMatrix[1] * cMatrix[0] * nMatrix[1] 
            + minCostFunc(matrixList[0..i] ~ multiMatrix ~ matrixList[i+2..$]);
        if(cost < minCost)
        {
            minCost = cost;
            count++;
        }
    }
    return minCost;
}
