atcoder#ARC120D. [ARC120D] Bracket Score 2

[ARC120D] Bracket Score 2

Score : 600600 points

Problem Statement

Let us define balanced parenthesis string as a string satisfying one of the following conditions:

  • An empty string.
  • A concatenation of ss and tt in this order, for some non-empty balanced parenthesis strings ss and tt.
  • A concatenation of (, ss, ) in this order, for some balanced parenthesis string ss.

Also, let us say that the ii-th and jj-th characters of a parenthesis string ss is corresponding to each other when all of the following conditions are satisfied:

  • 1i<js1 \le i < j \le |s|.
  • si=s_i = (.
  • sj=s_j = ).
  • The string between the ii-th and jj-th characters of ss, excluding the ii-th and jj-th characters, is a balanced parenthesis string.

You are given a sequence of length 2N2N: A=(A1,A2,A3,,A2N)A = (A_1, A_2, A_3, \dots, A_{2N}). Let us define the score of a balanced parenthesis string ss of length 2N2N as the sum of AiAj|A_i - A_j| over all pairs (i,j)(i, j) such that the ii-th and jj-th characters of ss are corresponding to each other.

Among the balanced parenthesis strings of length 2N2N, find one with the maximum score.

Constraints

  • 1N2×1051 \le N \le 2 \times 10^5
  • 1Ai1091 \le A_i \le 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 A3A_3 \dots A2NA_{2N}

Output

Print a balanced parenthesis string of length 2N2N 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 44: (()) and ()(), with the following scores:

  • (()): 14+23=4|1 - 4| + |2 - 3| = 4
  • ()(): 12+34=2|1 - 2| + |3 - 4| = 2

Thus, (()) is the only valid answer.

2
2 3 2 3
()()

(()) and ()() have the following scores:

  • (()) : 23+32=2|2 - 3| + |3 - 2| = 2
  • ()() : 23+23=2|2 - 3| + |2 - 3| = 2

Thus, either is a valid answer in this case.