class MCM
  def initialize(n)
    @a = Array.new(n+1)
    @mat = {}
  end
  def input(i, r, c)
    @a[i], @a[i+1] = r, c
  end
  def minMCM(s, e)
    key = "#{s} #{e}"
    unless @mat[key]
      min = 1.0 / 0.0
      s.upto(e-1){|m|
        val = minMCM(s, m) + minMCM(m+1, e) + @a[s] * @a[m+1] * @a[e+1]
        min = val if val < min
      }
      @mat[key] = min
    end
    return @mat[key]
  end
  def a2mat
    n = @a.size-1
    0.upto(n){|i|
      key = "#{i} #{i}"
      @mat[key] = 0
    }
  end
end

n = gets.to_i
mcm = MCM.new(n)
n.times{|i|
  r, c = gets.split.map(&:to_i)
  mcm.input(i, r, c)
}
mcm.a2mat
puts mcm.minMCM(0, n-1)