Given n matrices A1,A2,…,An with sizes a1×b1,a2×b2,…,an×bn, 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(2≤n≤300).
The next n lines contain the dimensions of each of the matrices ai,bi (1 ≤ ai,bi ≤ 1000).
It’s guaranteed that bi=ai+1 for i∈{1,2,...,n−1}.
Output
The program should print the minimum number of operations required to multiply all the matrices.