N = int(eval(input()))

S = input().strip()

S1 = S

cur = 0

for i in range(len(S)):

    if S[i]=="(":

        cur += 1

    else:

        cur -= 1

    if cur<0:

        S1 = "("+S1

        cur += 1

S1 = S1+")"*cur

print(S1)
N = int(eval(input()))

S = input().strip()

while True:

    lv = 0

    lmin = len(S)

    for i in range(len(S)):

        if S[i]=="(":

            lv += 1

        else:

            lv -= 1

        lmin = min(lmin,lv)

    if lmin<0:

        S = "("*(-lmin)+S

    else:break

lv = 0

for i in range(len(S)):

    if S[i]=="(":

        lv += 1

    else:

        lv -= 1



if lv>0:

    S = S+")"*lv

print(S)
N = int(eval(input()))
S = input().strip()
S1 = S
cur = 0
for i in range(len(S)):
    if S[i] == "(":
        cur += 1
    else:
        cur -= 1
    if cur < 0:
        S1 = "(" + S1
        cur += 1
S1 = S1 + ")" * cur
print(S1)

N = int(eval(input()))
S = input().strip()
while True:
    lv = 0
    lmin = len(S)
    for i in range(len(S)):
        if S[i] == "(":
            lv += 1
        else:
            lv -= 1
        lmin = min(lmin, lv)
    if lmin < 0:
        S = "(" * (-lmin) + S
    else:
        break
lv = 0
for i in range(len(S)):
    if S[i] == "(":
        lv += 1
    else:
        lv -= 1
if lv > 0:
    S = S + ")" * lv
print(S)

-S1 = S -cur = 0 +while True: +    lv = 0 +    lmin = len(S) +    for i in range(len(S)): +        if S[i] == "(": +            lv += 1 +        else: +            lv -= 1 +        lmin = min(lmin, lv) +    if lmin < 0: +        S = "(" * (-lmin) + S +    else: +        break +lv = 0 -        cur += 1 +        lv += 1 -        cur -= 1 -    if cur < 0: -        S1 = "(" + S1 -        cur += 1 -S1 = S1 + ")" * cur -print(S1) +        lv -= 1 +if lv > 0: +    S = S + ")" * lv +print(S)