Statement
There is a paper strip consisting of unit cells numbered from left to right. Boundary lies between cells and and has cost .
Initially all cells form one paper piece. Repeat the following operation:
- Choose a current paper piece containing at least two cells.
- Choose an uncut boundary inside that piece and cut the piece into two parts.
- If the piece had an odd number of cells immediately before the cut, this is a red cut. A red cut at boundary costs .
- If the piece had an even number of cells immediately before the cut, no cost is paid.
You must make exactly cuts until every cell is a separate piece.
Find the minimum total cost among cutting orders with exactly red cuts. Print -1 if no such order exists.
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 cost of a cutting order with exactly red cuts. Print -1 if no such order exists.
Constraints
- .
- .
- .
- ().
- The sum of over all test cases does not exceed .
Subtasks
Samples
In the first test case, boundaries and can be made red for a total cost of . In the second test case, at most two red cuts are possible.