Matrix Multiplications

Given n matrices A1,A2,,AnA_1,A_2,…,A_n with sizes a1×b1,a2×b2,,an×bna_1×b_1, a_2×b_2,…,a_n×b_n, respectively. The matrices are ordered from left to right from 1 to n. You are allowed to place brackets to prioritize some multiplications.

What is the minimum number of operations to multiply all the matrices?

Input

The first line contains a single integer n (2n3002 ≤ n ≤ 300).

The next n lines contain the dimensions of each of the matrices ai,bia_i, b_i (1 ≤ ai,bia_i, b_i ≤ 1000).

It’s guaranteed that bi=ai+1b_i = a_{i+1} for i{1,2,...,n1}i \in \{1, 2, ..., n-1\}.

Output

The program should print the minimum number of operations required to multiply all the matrices.

Examples

Input

Output

3
2 3
3 4
4 6

72

Constraints

Time limit: 7.2 seconds

Memory limit: 512 MB

Output limit: 1 MB