import scala.io.StdIn.{readInt,readLine}

object Main {
  def main(args:Array[String]) = {
   val n = readInt
   val p = new Array[Long](n+1)
   val m = { for(i<- 0 to 100) yield { { for(j<-0 to 100) yield Long.MaxValue }.toArray } }.toArray

   (1 to n).foreach { i =>
     val q = readLine.split(" ").map(_.toLong)
     p(i-1) = q(0)
     p(i) = q(1)
   }

   (1 to n).foreach { i => m(i)(i) = 0 }
   for(i<-2 to n) {
     for(j<-1 to n-i+1) {
       val k = i+j-1
       for(l<-j to k-1) {
         val value = m(j)(l)+m(l+1)(k)+p(j-1)*p(l)*p(k)
         m(j)(k) = if(m(j)(k)>value) value else m(j)(k)
       }
     }
   }
   println(m(1)(n))
  }
}