n=int(eval(input()))

s=eval(input())

s=list(s)



flag = True



ans = []



count = 0



for i in s:

    if flag:

        if i==')':

            ans.append(')')

            ans.insert(0, '(')

        else:

            flag = False

            ans.append('(')

            count += 1

    else:

        if i=='(':

            count += 1

            ans.append('(')

        else:

            ans.append(')')

            count -= 1

            if count == 0:

                flag = True

                

for j in range(count):

    ans.append(')')



print((''.join(map(str,ans))))
N = int(eval(input()))

S = list(eval(input()))



ans = []

count = 0

addFlag = True

for i in range(N):

    if addFlag:

        if S[i] == ')':

            ans.append(')')

            ans.insert(0,'(')

        else:

            ans.append('(')

            count += 1

            addFlag = False

    else:

        if S[i] == '(':

            ans.append('(')

            count += 1

        else:

            ans.append(')')

            count -= 1

            if count == 0:

                addFlag = True



for _ in range(count):

    ans.append(')')



print((''.join(ans)))
n = int(eval(input()))
s = eval(input())
s = list(s)
flag = True
ans = []
count = 0
for i in s:
    if flag:
        if i == ")":
            ans.append(")")
            ans.insert(0, "(")
        else:
            flag = False
            ans.append("(")
            count += 1
    else:
        if i == "(":
            count += 1
            ans.append("(")
        else:
            ans.append(")")
            count -= 1
            if count == 0:
                flag = True
for j in range(count):
    ans.append(")")
print(("".join(map(str, ans))))

N = int(eval(input()))
S = list(eval(input()))
ans = []
count = 0
addFlag = True
for i in range(N):
    if addFlag:
        if S[i] == ")":
            ans.append(")")
            ans.insert(0, "(")
        else:
            ans.append("(")
            count += 1
            addFlag = False
    else:
        if S[i] == "(":
            ans.append("(")
            count += 1
        else:
            ans.append(")")
            count -= 1
            if count == 0:
                addFlag = True
for _ in range(count):
    ans.append(")")
print(("".join(ans)))

-n = int(eval(input())) -s = eval(input()) -s = list(s) -flag = True +N = int(eval(input())) +S = list(eval(input())) -for i in s: -    if flag: -        if i == ")": +addFlag = True +for i in range(N): +    if addFlag: +        if S[i] == ")": -            flag = False +            addFlag = False -        if i == "(": +        if S[i] == "(": +            ans.append("(") -            ans.append("(") -                flag = True -for j in range(count): +                addFlag = True +for _ in range(count): -print(("".join(map(str, ans)))) +print(("".join(ans)))