import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees

from itertools import permutations, combinations, product, accumulate

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from fractions import gcd

from bisect import bisect

import numpy as np



def input(): return sys.stdin.readline().strip()

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(): return list(map(int, input().split()))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7



N = INT()

S = eval(input())



T = S



while 1:

	if T.count("()") == 0:

		break

	try:

		T = T.replace("()", "")

	except:

		pass

l = 0

r = 0

for x in T:

	if x == ")":

		l += 1

	else:

		r += 1

print(("("*l + S + ")"*r))

N = int(eval(input()))

 

S = eval(input())

 

l = 0

r = 0

for s in S:

  if s == "(":

    r += 1

  else:

    if r >= 1:

      r -= 1

    else:

      l += 1

print(("("*l + S + ")"*r))
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
import numpy as np


def input():
    return sys.stdin.readline().strip()


def INT():
    return int(eval(input()))


def MAP():
    return list(map(int, input().split()))


def LIST():
    return list(map(int, input().split()))


sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N = INT()
S = eval(input())
T = S
while 1:
    if T.count("()") == 0:
        break
    try:
        T = T.replace("()", "")
    except:
        pass
l = 0
r = 0
for x in T:
    if x == ")":
        l += 1
    else:
        r += 1
print(("(" * l + S + ")" * r))

N = int(eval(input()))
S = eval(input())
l = 0
r = 0
for s in S:
    if s == "(":
        r += 1
    else:
        if r >= 1:
            r -= 1
        else:
            l += 1
print(("(" * l + S + ")" * r))

-import sys, re -from collections import deque, defaultdict, Counter -from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees -from itertools import permutations, combinations, product, accumulate -from operator import itemgetter, mul -from copy import deepcopy -from string import ascii_lowercase, ascii_uppercase, digits -from fractions import gcd -from bisect import bisect -import numpy as np - - -def input(): -    return sys.stdin.readline().strip() - - -def INT(): -    return int(eval(input())) - - -def MAP(): -    return list(map(int, input().split())) - - -def LIST(): -    return list(map(int, input().split())) - - -sys.setrecursionlimit(10**9) -INF = float("inf") -mod = 10**9 + 7 -N = INT() +N = int(eval(input())) -T = S -while 1: -    if T.count("()") == 0: -        break -    try: -        T = T.replace("()", "") -    except: -        pass -for x in T: -    if x == ")": -        l += 1 +for s in S: +    if s == "(": +        r += 1 -        r += 1 +        if r >= 1: +            r -= 1 +        else: +            l += 1