#D8888. Matrix Chain Multiplication

    ID: 7387 Type: Default 1000ms 134MiB

Matrix Chain Multiplication

Matrix Chain Multiplication

The goal of the matrix-chain multiplication problem is to find the most efficient way to multiply given nn matrices M1,M2,M3,...,MnM_1, M_2, M_3,...,M_n.

Write a program which reads dimensions of MiM_i, and finds the minimum number of scalar multiplications to compute the maxrix-chain multiplication M1M2...MnM_1M_2...M_n.

Constraints

  • 1n1001 \leq n \leq 100
  • 1r,c1001 \leq r, c \leq 100

Input

In the first line, an integer nn is given. In the following nn lines, the dimension of matrix MiM_i (i=1...ni = 1...n) is given by two integers rr and cc which respectively represents the number of rows and columns of MiM_i.

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 nn is given. In the following nn lines, the dimension of matrix MiM_i (i=1...ni = 1...n) is given by two integers rr and cc which respectively represents the number of rows and columns of MiM_i.

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