def get_ans ms
  m_len = ms.length
  dp = Array.new(m_len){Array.new(m_len)}
  0.upto(m_len - 1) do |i|
    0.upto(m_len - 1) do |j|
      from_i = j
      to_i = j + i
      break if to_i > m_len - 1
      dp[from_i][to_i] = if from_i == to_i
                           0
                         else
                           min_v = Float::INFINITY
                           from_i.upto(to_i - 1) do |k|
                             v = dp[from_i][k] + dp[k + 1][to_i] + ms[from_i][0] * ms[k][1] * ms[to_i][1]
                             min_v = v if v < min_v
                           end
                           min_v
                         end
    end
  end

  dp[0][m_len - 1]
end

ms = []
n = gets.chomp.to_i
while l = gets
  ms << l.chomp.split(' ').map(&:to_i)
end
puts get_ans ms
