INF = (1 << 31) - 1

n = gets.to_i
ms = n.times.map {gets.split.map(&:to_i)}

dp = Array.new(n + 1) {Array.new(n + 1, 0)}
dim = [ms[0][0]] + ms.map(&:last)

2.upto(n) do |l|
  1.upto(n - l + 1) do |i|
    j = i + l - 1
    dp[i][j] = INF
    i.upto(j - 1) do |k|
      tmp = dp[i][k] + dp[j][k] + dp[k + 1][j] + dim[i - 1] * dim[k] * dim[j]
      dp[i][j] = [dp[i][j], tmp].min
    end
  end
end

puts dp[1][n]
