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;
 
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);
}

auto 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 minIndex = minIndex!((a,b)=>a[1]<b[1])(matrixList);
    long cost;
    if(minIndex+1 <= matrixList.length-2)
    {
        auto cMatrix = matrixList[minIndex+1];
        foreach(i; minIndex+1..matrixList.length-1)
        {
            auto nMatrix = matrixList[i+1];
            cost += cMatrix[0] * cMatrix[1] * nMatrix[1];
            cMatrix = [cMatrix[0], nMatrix[1]];
        }
        matrixList[minIndex+1] = cMatrix;
        matrixList = matrixList[0..minIndex+2];
    }
    auto cMatrix = matrixList[minIndex];
    foreach(i; iota(minIndex, 0, -1))
    {
        auto pMatrix = matrixList[i-1];
        cost += cMatrix[1] * pMatrix[0] * pMatrix[1];
        cMatrix = [pMatrix[0], cMatrix[1]];
    }
    matrixList[minIndex] = cMatrix;
    matrixList = matrixList[minIndex..$];
    if(matrixList.length==2)
    {
        auto nMatrix = matrixList[1];
        cost += cMatrix[0] * cMatrix[1] * nMatrix[1];
    }

    return cost;
}
