import scala.io.StdIn.{readInt, readLine};
object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt;
        val p = new Array[Int](n + 1);
        for (i <- (0 until n)) {
            val line = readLine.split(" ").map(_.toInt);
            p(i) = line(0);
            if (i == n - 1) p(n) = line(1);
        }
        println(mcm(p));
    }

    def mcm(p: Array[Int]): Int = {
        val len = p.length;
        val arr = Array.ofDim[Int](len, len).map( e => e.map( f => -1));
        (0 until len).foreach { i => arr(i)(i) = 0}
        def go(first: Int, last: Int): Int = {
            if (arr(first)(last) != -1) {
                return arr(first)(last);
            } else {
                val minimum = (first until last).map { i =>
                    val left = go(first, i);
                    val right = go(i + 1, last);
                    // 左辺の行列の行数(最初の行列の列数) * 左辺の行列の列数 *  右辺の行列の列数
                    val curr = p(first - 1) * p(i) * p(last);
                    left + right + curr;
                }.min
                arr(first)(last) = minimum;
                minimum;
            }
        }
        go(1, len - 1);
    }
}
