Given two matrices with dimensions and , the cost of the usual multiplication algorithm is . For simplicity, let us consider that the cost is exactly .
Suppose that we must compute , where every is an matrix. Since the product of matrices is associative, we can choose the multiplication order. For example, to compute , we could either choose , with cost , or either choose , with cost , or three other possible orders.
Write a program to find the minimum cost of computing .
Input consists of several cases, each one with followed by the dimensions. Assume and .
For every case, print the minimum cost to compute the product of the matrices.
Input
2 1 2 3 3 10 20 30 40 10 9000 4000 3500 8000 2000 7500 6000 1000 8500 5500 7000
Output
6 18000 302250000000