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

    def mcm(n: Int, p: Array[Int], matrix: Array[Array[Int]]): Int = {
        def _mcm(start: Int, end: Int): Int = {
            if (matrix(start)(end) < Int.MaxValue) {
                matrix(start)(end);
            } else {
                (start until end).foreach { i =>
                    val tmpMin = _mcm(start, i) + _mcm(i + 1, end) + (p(start) * p(i + 1) * p(end + 1));
                    if (tmpMin < matrix(start)(end)) {
                        matrix(start)(end) = tmpMin;
                    }
                }
            }
            matrix(start)(end);
        }
        _mcm(0, n - 1);
    }
}
