Statement
There are signal pieces in a row. Initially, every piece has displayed value .
Boundary lies between the original pieces and . Its alarm cost is .
Merging consecutive signal pieces creates a bundle. Every bundle consists of a contiguous interval of original pieces and has one displayed value between and .
Choose a boundary that has not been removed and merge the two bundles adjacent to it. Let their displayed values be and .
- If , the new bundle has displayed value .
- If , an alarm occurs at boundary . You pay , and the new bundle has displayed value .
The chosen boundary is removed and cannot be used again. Perform exactly merges until all pieces form one bundle.
Find the minimum possible total alarm cost.
Input
The input is given in the following format:
Each case is given in the following format:
Output
For each test case, print the minimum possible total alarm cost on one line.
Constraints
- .
- .
- .
- ().
- The sum of over all test cases does not exceed .
Subtasks
Samples
Removing boundaries in the order makes alarms occur only at boundaries and . The total cost is .