$num = gets.to_i

$matrix = []
$keisan = []
for i in 1..$num do
	row,column = gets.split.map(&:to_i)
	$matrix.push(row:row,column:column)	
end

for i in 1..$num do
	a = []
	for j in 1..$num do
	a.push(100000000)
	end
	$keisan.push(a)
end
for j in 0..$num -1 do
	$keisan[0][j] = 0
end
for j in 0..$num-2 do
	$keisan[1][j] = $matrix[j][:row]*$matrix[j][:column]*$matrix[j+1][:column]
end

for i in 2..$num-1 do
	for j in 0..$num-i-1 do
		for k in 0..i-1 do
			if $keisan[i][j] >  $keisan[k][j] + $keisan[i-k-1][j+k+1] + $matrix[j][:row] * $matrix[i+j][:column] * $matrix[j+k][:column] 
                $keisan[i][j] = $keisan[k][j] + $keisan[i-k-1][j+k+1] + $matrix[j][:row] * $matrix[i+j][:column] * $matrix[j+k][:column]
		    end
        end
	end
end

puts $keisan[$num-1][0]