n = gets.to_i
ms = n.times.map { gets.split.map(&:to_i) }
dp = Array.new(n+1) {|i| Array.new n-i+1 }
dp[1].map! { 0 }
for i in 2..n
  for j in 0..n-i
    for k in 1..i-1
      c = dp[k][j] + dp[i-k][j+k] + ms[j][0] * ms[j+k-1][1] * ms[j+i-1][1]
      dp[i][j] = c unless dp[i][j]&.<=(c)
    end
  end
end
p dp.last.last