n = gets.to_i
p = []
(n-1).times do |i|
  p[i] = gets.split[0].to_i
end
p.concat gets.split.map &:to_i
m = Array.new(n){ Array.new(n, 1000000) }
n.times do |i|
  m[i][i] = 0
end
(1...n).each do |j|
  (0...n-j).each do |k|
    last = k+j
    a = []
    (k...last).each do |l|
      a << m[k][l] + m[l+1][last] + p[k] * p[l+1] * p[last+1]
    end
    m[k][last] = a.min
  end
end
puts m[0][n-1]