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