#arc120d. [arc120_d]Bracket Score 2
[arc120_d]Bracket Score 2
Problem Statement
Let us define balanced parenthesis string as a string satisfying one of the following conditions:
- An empty string.
- A concatenation of and in this order, for some non-empty balanced parenthesis strings and .
- A concatenation of
(
, ,)
in this order, for some balanced parenthesis string .
Also, let us say that the -th and -th characters of a parenthesis string is corresponding to each other when all of the following conditions are satisfied:
- .
-
(
. -
)
. - The string between the -th and -th characters of , excluding the -th and -th characters, is a balanced parenthesis string.
You are given a sequence of length : .
Let us define the score of a balanced parenthesis string of length as the sum of over all pairs such that the -th and -th characters of are corresponding to each other.
Among the balanced parenthesis strings of length , find one with the maximum score.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print a balanced parenthesis string of length with the maximum score.
If there are multiple such strings, any of them will be accepted.
Sample Input 1
2
1 2 3 4
Sample Output 1
(())
There are two balanced parenthesis strings of length : (())
and ()()
, with the following scores:
(())
:()()
:
Thus, (())
is the only valid answer.
Sample Input 2
2
2 3 2 3
Sample Output 2
()()
(())
and ()()
have the following scores:
(())
:()()
:
Thus, either is a valid answer in this case.