n = int(eval(input()))

s = str(eval(input()))



ans = s

ans = list(ans)



cum = 0

for i in range(n):

    if s[i] == '(':

        cum += 1

    else:

        cum -= 1

    if cum < 0:

        ans = ['('] + ans

        cum = 0

else:

    ans = ans + [')']*cum



print((''.join(ans)))

n = int(eval(input()))

s = str(eval(input()))

c = 0

from collections import deque

res = deque([])

for i in range(n):

    if s[i] =='(':

        c += 1

    else:

        c -= 1

    if c < 0:

        res.appendleft('(')

        c = 0

    res.append(s[i])

if c > 0:

    res.append(')'*c)

print((''.join(list(res))))

n = int(eval(input()))
s = str(eval(input()))
ans = s
ans = list(ans)
cum = 0
for i in range(n):
    if s[i] == "(":
        cum += 1
    else:
        cum -= 1
    if cum < 0:
        ans = ["("] + ans
        cum = 0
else:
    ans = ans + [")"] * cum
print(("".join(ans)))

n = int(eval(input()))
s = str(eval(input()))
c = 0
from collections import deque

res = deque([])
for i in range(n):
    if s[i] == "(":
        c += 1
    else:
        c -= 1
    if c < 0:
        res.appendleft("(")
        c = 0
    res.append(s[i])
if c > 0:
    res.append(")" * c)
print(("".join(list(res))))

-ans = s -ans = list(ans) -cum = 0 +c = 0 +from collections import deque + +res = deque([]) -        cum += 1 +        c += 1 -        cum -= 1 -    if cum < 0: -        ans = ["("] + ans -        cum = 0 -else: -    ans = ans + [")"] * cum -print(("".join(ans))) +        c -= 1 +    if c < 0: +        res.appendleft("(") +        c = 0 +    res.append(s[i]) +if c > 0: +    res.append(")" * c) +print(("".join(list(res))))