You are given a parenthesis string of length . Flipping the -th character costs . A flip changes ( to ) and ) to (.
A string is called a regular bracket sequence if it can be defined by the following rules.
Only strings that can be obtained by applying the above rules a finite number of times are regular bracket sequences.
Flip some characters of to make it a correct parenthesis string. Print the minimum possible cost and one resulting string attaining that cost.
The input is given from Standard Input in the following format:
For each test case, first print the minimum cost on one line.
On the next line, print any correct parenthesis string obtainable with that minimum cost.
In the first test case, flipping the second character changes the string to at a cost of . It is impossible to obtain a valid parenthesis string at cost , so the minimum cost is .
Each case is given in the following format:
()| 28 |
|
| 4 | 51 | No additional constraints. |