n = gets.chomp.to_i

# rows, cols = [], []
# n.times { |i| rows[i], cols[i] = gets.chomp.split.map(&:to_i) }

pAry = Array.new(n + 1)
mAry = Array.new(n + 1) { Array.new(n + 1) }

1.upto(n) do |i|
    pAry[i - 1], pAry[i] = gets.chomp.split.map(&:to_i)
end

1.upto(n) do |i|
    mAry[i][i] = 0
end

2.upto(n) do |l|
    1.upto(n - l + 1) do |i|
        j = i + l - 1
        mAry[i][j] = Float::INFINITY
        i.upto(j - 1) do |k|
            mAry[i][j] = [mAry[i][j], mAry[i][k] + mAry[k + 1][j] + pAry[i - 1] * pAry[k] * pAry[j]].min
        end
    end
end

puts mAry[1][n]

