m = []
N = gets.to_i
(N-1).times{|i|
  m[i] = gets.split[0].to_i
}
m.concat gets.split.map &:to_i
cost = Array.new(N){Array.new(N, 0x7fffffff)}
N.times{|i| cost[i][i] = 0}
(1...N).each{|d|
  (0...N-d).each{|first|
    last = first + d
    a = []
    (first...last).each{|s|
      a << cost[first][s] + cost[s+1][last] + m[first] * m[s+1] * m[last+1]
    }
    cost[first][last] = a.min
  }
}
puts cost[0][N-1]