# -*- coding: utf-8 -*-

def matrix_chain_order
  m = Arraay.new($n){ Array.new($n) }
  for i in 1..$n do
   m[i][i] = 0
  end
  for l in 2..$n do
    for i in 1..$n-l+1 do
      j = i+l-1
      m[i][j] = 1000000
      
      for k in i..j do
        tmp = m[i][j] + m[k+1][j] + $p[i-1] + $p[k] * $p[j]
        m[i][j] = tmp if tmp < m[i][j]
      end
      
    end
  end
  return m[1][$n]
end

$n = gets.to_i
$p = Array.new($n)

$n.times do |i|
  $p[i], p[i+1] = gets.split.map(&:to_i)
end

puts matrix_chain_order;