from collections import deque

N = int(eval(input()))

S = list(eval(input()))

A = deque()

B = []



left_cnt = 0

right_cnt = 0

for s in S:

    if s == "(":

        left_cnt += 1

        A.append("(")

    else:

        A.append(")")

        if right_cnt + 1 > left_cnt:

            B.append("(")

        else:

            right_cnt += 1



C = [")"] * (left_cnt - right_cnt)

B.extend(A)

B.extend(C)

print(("".join(B)))

N = int(eval(input()))

S = eval(input())



T = 0

ans = []



for s in S:

    if s == "(":

        T += 1

        ans.append("(")

    else:

        T -= 1

        ans.append(")")

        if T < 0:

            ans.insert(0, "(")

            T = 0



for i in range(T):

    ans.append(")")

print(("".join(ans)))
from collections import deque

N = int(eval(input()))
S = list(eval(input()))
A = deque()
B = []
left_cnt = 0
right_cnt = 0
for s in S:
    if s == "(":
        left_cnt += 1
        A.append("(")
    else:
        A.append(")")
        if right_cnt + 1 > left_cnt:
            B.append("(")
        else:
            right_cnt += 1
C = [")"] * (left_cnt - right_cnt)
B.extend(A)
B.extend(C)
print(("".join(B)))

N = int(eval(input()))
S = eval(input())
T = 0
ans = []
for s in S:
    if s == "(":
        T += 1
        ans.append("(")
    else:
        T -= 1
        ans.append(")")
        if T < 0:
            ans.insert(0, "(")
            T = 0
for i in range(T):
    ans.append(")")
print(("".join(ans)))

-from collections import deque - -S = list(eval(input())) -A = deque() -B = [] -left_cnt = 0 -right_cnt = 0 +S = eval(input()) +T = 0 +ans = [] -        left_cnt += 1 -        A.append("(") +        T += 1 +        ans.append("(") -        A.append(")") -        if right_cnt + 1 > left_cnt: -            B.append("(") -        else: -            right_cnt += 1 -C = [")"] * (left_cnt - right_cnt) -B.extend(A) -B.extend(C) -print(("".join(B))) +        T -= 1 +        ans.append(")") +        if T < 0: +            ans.insert(0, "(") +            T = 0 +for i in range(T): +    ans.append(")") +print(("".join(ans)))