#encoding: utf-8                                                                                                                                                                 

def input
  size = []
  n = gets.chomp.to_i
  (1..n).each do |i|
    sz = gets.chomp.split(/\s/).collect{ |x| x.to_i}
    size << { :row => sz[0], :col => sz[1]}
  end
  [n, size]
end

def solve(n, size)
  dp = { }
  0.upto(n - 1).each do |i|
    i.upto(n - 1).each do |j|
      dp[[i, j]] = 0x3fffffff
    end
  end

  0.upto(n - 1) { |i| dp[[i, i]] = 0}

  1.upto(n - 1).each do |k|
    0.upto(n - k - 1).each do |i|
      i.upto(i + k - 1).each do |j|
        sz = size[i][:row] * size[j][:col] * size[i + k][:col]
        dp[[i, i + k]] = [dp[[i, i + k]], dp[[i, j]] + dp[[j + 1, i + k]] + sz].min
      end
    end
  end
  dp
end

def main
  n, size = input
#  p size                                                                                                                                                                        
  dp = solve(n, size)
  puts dp[[0, n - 1]]
end

main