n = gets.to_i

@ms = {}
@dp = {}

class Matrix
    attr_reader :row, :col

    def initialize(row, col)
        @row = row
        @col = col
    end
end

[*1..n].each do |i|
    r, c  = gets.split.map(&:to_i)
    @ms[i] = Matrix.new(r, c)
end


def set_value(x, y)
    if x == y
        @dp[[x, y]] = 0
     elsif y - x == 1
        @dp[[x, y]] = @ms[x].row * @ms[x].col * @ms[y].col
    else
        candidate = []
        [*1..(y - x)].each do |k|
            candidate << @ms[x].row * @ms[x + k].row * @ms[y].col + @dp[[x, x + (k - 1)]] + @dp[[x + k, y]]
        end
        @dp[[x, y]] = candidate.min
    end
end


1.upto(n) do |y|
    n.downto(1) do |x|
        unless x > y
            set_value(x, y)
        end
    end
end

p @dp[[1, n]]
