from collections import deque

N = int(eval(input()))

S = list(eval(input()))

T = deque(S[:])

ins = []

pointer = 0

a = 0

for i in range(N):

  if S[i] == ')':

    if pointer >= 1:

      pointer -= 1

    else:

      T.appendleft('(')

  else:

    pointer += 1

  

a = 0

b = 0

for t in T:

  if t == ')':

    b += 1

  else:

    a += 1



for i in range(max(a-b, 0)):

  T.append(')')

print((''.join(T)))

N = int(eval(input()))

S = list(eval(input()))



a = 0 # (

b = 0 # )

for i in range(N):

  if S[i] == '(':

    a += 1

  else:

    if a > 0:

      a -= 1

    else:

      b += 1



ans = "".join(S)

if b > 0:

  ans = "("*b + ans

if a > 0:

  ans = ans + ")"*a

print(ans)

from collections import deque

N = int(eval(input()))
S = list(eval(input()))
T = deque(S[:])
ins = []
pointer = 0
a = 0
for i in range(N):
    if S[i] == ")":
        if pointer >= 1:
            pointer -= 1
        else:
            T.appendleft("(")
    else:
        pointer += 1
a = 0
b = 0
for t in T:
    if t == ")":
        b += 1
    else:
        a += 1
for i in range(max(a - b, 0)):
    T.append(")")
print(("".join(T)))

N = int(eval(input()))
S = list(eval(input()))
a = 0  # (
b = 0  # )
for i in range(N):
    if S[i] == "(":
        a += 1
    else:
        if a > 0:
            a -= 1
        else:
            b += 1
ans = "".join(S)
if b > 0:
    ans = "(" * b + ans
if a > 0:
    ans = ans + ")" * a
print(ans)

-from collections import deque - -T = deque(S[:]) -ins = [] -pointer = 0 -a = 0 +a = 0  # ( +b = 0  # ) -    if S[i] == ")": -        if pointer >= 1: -            pointer -= 1 +    if S[i] == "(": +        a += 1 +    else: +        if a > 0: +            a -= 1 -            T.appendleft("(") -    else: -        pointer += 1 -a = 0 -b = 0 -for t in T: -    if t == ")": -        b += 1 -    else: -        a += 1 -for i in range(max(a - b, 0)): -    T.append(")") -print(("".join(T))) +            b += 1 +ans = "".join(S) +if b > 0: +    ans = "(" * b + ans +if a > 0: +    ans = ans + ")" * a +print(ans)