atcoder#ARC120D. [ARC120D] Bracket Score 2
[ARC120D] Bracket Score 2
Score : points
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.
2
1 2 3 4
(())
There are two balanced parenthesis strings of length : (())
and ()()
, with the following scores:
(())
:()()
:
Thus, (())
is the only valid answer.
2
2 3 2 3
()()
(())
and ()()
have the following scores:
(())
:()()
:
Thus, either is a valid answer in this case.