#D8888. Matrix Chain Multiplication
Matrix Chain Multiplication
Matrix Chain Multiplication
The goal of the matrix-chain multiplication problem is to find the most efficient way to multiply given matrices .
Write a program which reads dimensions of , and finds the minimum number of scalar multiplications to compute the maxrix-chain multiplication .
Constraints
Input
In the first line, an integer is given. In the following lines, the dimension of matrix () is given by two integers and which respectively represents the number of rows and columns of .
Output
Print the minimum number of scalar multiplication in a line.
Example
Input
6 30 35 35 15 15 5 5 10 10 20 20 25
Output
15125
inputFormat
Input
In the first line, an integer is given. In the following lines, the dimension of matrix () is given by two integers and which respectively represents the number of rows and columns of .
outputFormat
Output
Print the minimum number of scalar multiplication in a line.
Example
Input
6 30 35 35 15 15 5 5 10 10 20 20 25
Output
15125
样例
6
30 35
35 15
15 5
5 10
10 20
20 25
15125