Statement
There are cells in a row. Each cell contains one card whose color is or .
Switch lies between cells and and has operating cost .
Every switch can be operated exactly once. Operating a switch that has not been used performs the following actions in order:
- If the card colors in cells and differ immediately before the operation, pay .
- Swap the two cards.
- Switch breaks and cannot be operated again.
All switches must be operated exactly once. Find the minimum total cost over all operating orders.
Input
The input is given in the following format:
Each case is given in the following format:
is the initial color of the card in cell .
Output
For each test case, print the minimum total cost of operating every switch exactly once.
Constraints
- .
- .
- ().
- ().
- The sum of over all test cases does not exceed .
Subtasks
Samples
Input
1
8
01101001
10 1 14 18 4 6 10
Output
21
Operating the switches in the order gives total cost .