#!/usr/bin/ruby

NN = ARGF.gets.to_i

$mt = []
(NN - 1).times do
  $mt << ARGF.gets.split.shift.to_i
end
$mt += ARGF.gets.chomp.split.collect {|el| el.to_i}

$cache = Array.new(NN + 1) {Array.new(NN + 1)}

#p $mt

def calcmul(ss, ee)
  dif = ee - ss
  if dif <= 1
    return 0
  else
    cse = $cache[ss][ee]
    if cse.nil?
      if dif == 2
        #p ss, ee
        cse = $mt[ss] * $mt[ss + 1] * $mt[ss + 2]
      else
        kk = ss + 1
        #puts "#{ss}:#{kk}:#{ee}"
        cse = calcmul(ss, kk) + calcmul(kk, ee) + $mt[ss] * $mt[kk] * $mt[ee]
        for kk in (ss + 2)..(ee - 1)
          tcse = calcmul(ss, kk) + calcmul(kk, ee) + $mt[ss] * $mt[kk] * $mt[ee]
          if tcse < cse
            cse = tcse
          end
        end
      end
      $cache[ss][ee] = cse
    end
    return cse
  end
end

puts calcmul(0, NN)

