qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
   
r,g,b=map(int,input().split())

if (10*b+g)%4==0:
	print("YES")
else:
	print("NO")

# Fixed code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
   
r,g,b=map(int,input().split())

if (10*g+b)%4==0:
	print("YES")
else:
	print("NO")
# Buggy code:
a, b, c = map(int, input().split())
if (100*a + 10*b + c) %4 = 0:
  print("YES")
else:
  print("NO")

# Fixed code:
a, b, c = map(int, input().split())
d = 100*a + 10*b + c
if d%4 == 0:
  print("YES")
else:
  print("NO")
# Buggy code:
import sys

input = sys.stdin.readline


def main():
    print("YES" if int(input()) % 4 == 0 else "NO")


if __name__ == "__main__":
    main()


# Fixed code:
import sys

input = sys.stdin.readline


def main():
    print("YES" if int("".join(input().split())) % 4 == 0 else "NO")


if __name__ == "__main__":
    main()
# Buggy code:
if __name__ == '__main__':
    r, g, b = map(int, input().split())
    num = 100 * r + 10 * g + b
    if num % 4 == True:
        print("YES")
    else:
        print("NO")

# Fixed code:
if __name__ == '__main__':
    r, g, b = map(int, input().split())
    num = 100 * r + 10 * g + b
    if num % 4 == 0:
        print("YES")
    else:
        print("NO")
# Buggy code:
    r,g,b=map(int,raw_input().split(' '))
     
    if (r*100+g*10+b)%4==0:
      print "YES"
    else:
      print "NO"

# Fixed code:
r, g, b = map(int, input().split())
if (100*r+10*g+b) % 4 == 0:
    print("YES")
else:
    print("NO")
# Buggy code:
a,b,c = map(int,input.split())
if 10*b+c%4==0:
  return 'YES'

else:
  return 'NO'

# Fixed code:
a,b, c = map(int, input().split())
if (10*b+c)%4 ==0:
  print('YES')
     
else:
  print('NO')
# Buggy code:
r,g,b = map(int(input().split()))
test = 100*r + 10*g + b
amari = test % 4
if amari == 0:
  print("YES")
else:
  print("NO")

# Fixed code:
r, g, b = map(int, input().split())
if ((100*r + 10*g + b) % 4) == 0:
  print('YES')
else:
  print('NO')
# Buggy code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
res = 0
for i in range(n - 1):
    res += a[i+1] - a[i]
print(a)


# Fixed code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
res = 0
for i in range(n - 1):
    res += a[i+1] - a[i]
print(res)
# Buggy code:
"""
author : halo2halo
date : 30, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*A = map(int, readline().split())
A.sort()
print(A[-1]-A[0])


# Fixed code:
"""
author : halo2halo
date : 30, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*A = map(int, read().split())
A.sort()
print(A[-1]-A[0])
# Buggy code:
n = map(int, input.split())
a = list(map(int, input().split()))
print(max(a) - min(a))

# Fixed code:
n = int(input())
a = list(map(int, input().split()))
print(max(a) - min(a))
# Buggy code:
houseTime = int(input())
place = input().split() 
place = int(i) for i in place
place = sorted(place)
print(place[houseTime - 1] - place[0])


# Fixed code:
houseTime = int(input())
place = input().split() 
place = [int(i) for i in place]
place = sorted(place)
print(place[houseTime - 1] - place[0])
# Buggy code:
N=int(input())
a=[int(i) for i in input(). split ()]
mi=a[i]
ma=a[i]
while i<N:
    if a[i]>ma:
        ma=a[i]
    if a[i]<mi:
        mi=a[i]
    i+=1
print (ma-mi)

# Fixed code:
N=int(input())
a=[int(i) for i in input(). split ()]
mi=a[0]
ma=a[0]
i=0
while i<N:
    if a[i]>ma:
        ma=a[i]
    if a[i]<mi:
        mi=a[i]
    i+=1
print (ma-mi)
# Buggy code:
N = int(input())
A = sorted(map(int, input().split()))
A[0] = 0
d = 0
for i in range(1, N+1):
    d += A[i] - A[i-1]
print(d)


# Fixed code:
N = int(input())
A = sorted(map(int, input().split()))
d = 0
for i in range(1, N):
    d += A[i] - A[i-1]
print(d)
# Buggy code:
a = sorted((map(int,input().split())))
print(a[-1] - a[0])

# Fixed code:
n = int(input())
a = sorted(map(int, (input().split())))
print(a[-1] - a[0])
# Buggy code:
# -*- coding: utf-8 -*-
a = list(map(int, input().split()))
print(max(a)-min(a))


# Fixed code:
# -*- coding: utf-8 -*-
_ = input()
a = list(map(int, input().split()))
print(max(a)-min(a))
# Buggy code:
n = int(input())
l = map(int,input().split())
print(max(l) - min(l))

# Fixed code:
n = int(input())
l = list(map(int,input().split()))
print(max(l) - min(l))
# Buggy code:
N = int(input())
a = list(map(int, input().split())
print(max(a) - min(a))

# Fixed code:
N = int(input())
a = list(map(int, input().split()))

d = max(a) - min(a)
print(d)
# Buggy code:
n=int(input)
a=list(map(int,input().split()))
print(max(a)-min(a))

# Fixed code:
n = int(input())
a = list(map(int, input().split()))
print(max(a)-min(a))
# Buggy code:
s = list(map(int,input().split()))
s.sort()
print(s[len(s)-1] - s[0])

# Fixed code:
n = int(input())
s = list(map(int,input().split()))
s.sort()

print(s[len(s)-1] - s[0])
# Buggy code:
N = int(input())
a = list(append(map(int,input().split)))
print(max(a) - min(a))


# Fixed code:
N = int(input())
a = list(map(int,input().split()))
print(max(a) - min(a))
# Buggy code:
# B - Traveling AtCoDeer Problem
N = int(input())
a = list(map(int, input().split()))
A = set(a)
A1 = sorted(A)
count = 0
for i in range(N-1) :
    count += A1[i+1]-A1[i]

print(count)

# Fixed code:
# B - Traveling AtCoDeer Problem
N = int(input())
a = list(map(int, input().split()))
A = set(a)
A1 = sorted(A)
count = 0
for i in range(len(A)-1) :
    count += A1[i+1]-A1[i]

print(count)
# Buggy code:
# -*- coding: <encoding name> -*-

n = int(input())
a = list[map(int(), input().split())]

A = sorted(a)
print(A[-1] - A[0])

# Fixed code:
# -*- coding: <encoding name> -*-

n = int(input())
a = list(map(int, input().split()))

A = sorted(a)
print(A[-1] - A[0])
# Buggy code:
_
A = list(map(int, input().split()))
A.sort()
print(A[-1]-A[0])

# Fixed code:
_ = input()
A = list(map(int, input().split()))
A.sort()
print(A[-1]-A[0])
# Buggy code:
lst = [int(i) for i in input().split()]

print(max(lst) - min(lst))

# Fixed code:
_ = input()
lst = [int(i) for i in input().split()]

print(max(lst) - min(lst))
# Buggy code:
N = int(input())
a = list(map(int, input().split())).sort()
print(a[-1]-a[0])

# Fixed code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
print(a[-1]-a[0])
# Buggy code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
print(a[n-1]a[0])

# Fixed code:

n = int(input())
a = list(map(int,input().split()))

a = set(a)
a = list(a)
a.sort()

#print(a)
print(a[-1] - a[0])
# Buggy code:
a = list(map(int, input().split()))
print(max(a) - min(a))

# Fixed code:
N = int(input())
a = list(map(int, input().split()))
print(max(a)-min(a))
# Buggy code:
N=int(input())
a=list(set(list(map(int,input().split()))))
ans=0
a.sort()
for i in range(1,N):
    ans+=a[i]-a[i-1]
print(ans)

# Fixed code:
N=int(input())
a=list(set(list(map(int,input().split()))))
ans=0
a.sort()
for i in range(1,len(a)):
    ans+=a[i]-a[i-1]
print(ans)
# Buggy code:
n = int(input())
lis = list(int,input().split())
print(max(lis)-min(lis))

# Fixed code:
n = int(input())
lis = list(map(int,input().split()))
print(max(lis)-min(lis))
# Buggy code:
N = int(input())
List = list(map(int,input().split()))
sorted(List)
print(List[-1]-List[0])

# Fixed code:
N = int(input())
List = list(map(int,input().split()))
LIst = sorted(List)
print(LIst[-1]-LIst[0])
# Buggy code:
N = int(input())
A = list(map(int, input()))
A.sort()
print(A[-1] - A[0])

# Fixed code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
print(A[-1] - A[0])
# Buggy code:
# -*- coding: utf-8 -*-

x = int(input())
#x = 8

y = input()
#y = ["3","1","4","1","5","9","2","6"]

for i in range(x):
    y[i] = int(y[i])

Max = max(y)
Min = min(y)

ans = Max - Min

print(ans)


# Fixed code:
# -*- coding: utf-8 -*-
 
x = int(input())
#x = 8
 
y = input().split()
#y = ["3","1","4","1","5","9","2","6"]
 
for i in range(x):
    y[i] = int(y[i])
 
Max = max(y)
Min = min(y)
 
ans = Max - Min
 
print(ans)
# Buggy code:

x=map(int,input().split())
print(x[-1]-x[0])


# Fixed code:
input()
x=sorted(map(int,input().split()))
print(x[-1]-x[0])
# Buggy code:
n = int(input())
l = list(map(int.input().split()))
l.sort()
print(abs(l[0]-l[len(l)-1]))

# Fixed code:
n = int(input())
l = list(map(int,input().split()))
l.sort()
print(abs(l[0]-l[len(l)-1]))
# Buggy code:
N=int(input())
a_n=[int(x) for i in input().split()]

print(max(a_n)-min(a_n))

# Fixed code:
N=int(input())
a_n=[int(i) for i in input().split()]

print(max(a_n)-min(a_n))
# Buggy code:
A=list(map(int,input().split()))
A=sorted(A)
print(A[-1]-A[0])


# Fixed code:
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
print(A[-1]-A[0])
# Buggy code:
# %%
n = int(input())
a = list(map(int, input().split()))
new = sorted(a)
print(a[-1] - a[0])

# Fixed code:
# %%
n = int(input())
a = list(map(int, input().split()))
new = sorted(a)
print(new[-1] - new[0])
# Buggy code:
N, S = open(0)

cnt = left = 0
for s in S:
    if s == "(":
        cnt += 1
    else:
        cnt -= 1

    if cnt < 0:
        left = max(left, -cnt)

S = "(" * left + S

right = 0
for s in S:
    if s == "(":
        right += 1
    else:
        right -= 1

S = S + ")" * right

print(S)

# Fixed code:
N, S = open(0)
S = S.strip()

cnt = left = 0
for s in S:
    if s == "(":
        cnt += 1
    else:
        cnt -= 1

        if cnt < 0:
            left = max(left, -cnt)

S = "(" * left + S

right = 0
for s in S:
    if s == "(":
        right += 1
    else:
        right -= 1

S = S + ")" * right

print(S)
# Buggy code:
N = int(input())
S = input()

ans = []
st = 0
for c in S:
    if c == '(':
        st += 1
        ans.append('(')
    else:
        if st > 0:
            st -= 1
        else:
            ans.insert(0, '(')
        ans.append(')')
    print(*ans, sep='')

ans.extend(')' * st)

print(*ans, sep='')


# Fixed code:
N = int(input())
S = input()
 
ans = []
st = 0
for c in S:
    if c == '(':
        st += 1
        ans.append('(')
    else:
        if st > 0:
            st -= 1
        else:
            ans.insert(0, '(')
        ans.append(')')
 
ans.extend(')' * st)
 
print(*ans, sep='')
# Buggy code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    S=input()
    
    st=0
    a=""
    b=""
    for i in range(N):
        s=S[i]
        if st==0 and s==")":
            a+="("
        elif s=="(":
            st+=1
        else:
            st-=1
    b+=")"*st
    print(a+S+b)

main()


# Fixed code:


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    S=input()
    
    st=0
    a=""
    b=""
    for i in range(N):
        s=S[i]
        if st==0 and s==")":
            a+="("
        elif s=="(":
            st+=1
        else:
            st-=1
    b+=")"*st
    print(a+S+b)

main()
# Buggy code:
# -*- coding: utf-8 -*-
x = int(input())
y = input()

z = y

while z.find("()") != -1:
    z = z.replace("()","")

a = z.count("(")
b = z.count(")")

ans = z

for i in range(a):
    ans = ans + ")"

for i in range(b):
    ans = "(" + ans

print(ans)


# Fixed code:
# -*- coding: utf-8 -*-
x = int(input())
y = input()

z = y

while z.find("()") != -1:
    z = z.replace("()","")

a = z.count("(")
b = z.count(")")

ans = y

for i in range(a):
    ans = ans + ")"

for i in range(b):
    ans = "(" + ans

print(ans)
# Buggy code:
n=int(input())
s=input()
l=[]
for i in s:
  if i==')':
    if len(l)>0:
      if l[-1]=='(':
        l.pop()
      else:
        l.append(i)
    else:
      l.append(i)
print(len(l)*'(' + s)

# Fixed code:
n=int(input())
s=input()
l=[]
for i in s:
  if i==')':
    if len(l)>0:
      if l[-1]=='(':
        l.pop()
      else:
        l.append(i)
    else:
      l.append(i)
  else:
    l.append(i)
print(l.count(')')*'(' + s +l.count('(')*')')
# Buggy code:
import re

S = input()

while True:
    pre = S
    S = re.sub(r'\(((L|R)*?)\)', r'L\1R', S)
    if pre == S:
        break

S = '(' * S.count(')') + S + ')' * S.count('(')
S = S.replace('L', '(')
S = S.replace('R', ')')
print(S)

# Fixed code:
import re

N = int(input())
S = input()

while True:
    pre = S
    S = re.sub(r'\(((L|R)*?)\)', r'L\1R', S)
    if pre == S:
        break

S = '(' * S.count(')') + S + ')' * S.count('(')
S = S.replace('L', '(')
S = S.replace('R', ')')
print(S)
# Buggy code:

import math
import itertools
import statistics
#import collections
n = int(input())
s = input()

amari = 0
plus = 0

for i in range(n):
    if s[i]==")":
        plus += 1
    else:
        if plus <= 0:
            amari +=1
        else:
            plus -= 1

for i in range(plus):
    print("(", end="")

print(s, end="")

for i in range(amari):
    print(")", end="")






# Fixed code:

import math
import itertools
import statistics
#import collections
n = int(input())
s = input()

amari = 0
plus = 0

for i in range(n):
    if s[i]=="(":
        plus += 1
    else:
        if plus <= 0:
            amari +=1
        else:
            plus -= 1

for i in range(amari):
    print("(", end="")

print(s, end="")

for i in range(plus):
    print(")", end="")
# Buggy code:


def main():
    num = int(input())
    data = list(input())

    left, righ = 0, 0
    for i in range(num)[::-1]:
        ele = data[i]
        if ele == ')':
            righ += 1
        elif ele == '(':
            if righ > 0:
                righ -= 1
            else:
                data[i] = '()'
    add_data = ['(' for i in range(righ)]
    data = add_data + data
    print(''.join(data))




if __name__ == '__main__':
    main()


# Fixed code:

def main():
    num = int(input())
    data = list(input())

    left, righ = 0, 0
    for i in range(num):
        ele = data[i]
        if ele == '(':
            righ += 1
        else:
            if righ > 0:
                righ -= 1
            else:
                left += 1

    ans = ['(' for i in range(left)] + data + [')' for i in range(righ)]
    print(''.join(ans))






if __name__ == '__main__':
    main()
# Buggy code:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    S = input()
    height = 0
    deepest = 0
    for c in S:
        if c == '(':
            height += 1
        else:
            height -= 1
        deepest = min(deepest, height)
    print(deepest, height)
    ans = '(' * (-deepest) + S + ')' * (height - deepest)
    print(ans)

if __name__ == "__main__":
    main()


# Fixed code:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    S = input()
    height = 0
    deepest = 0
    for c in S:
        if c == '(':
            height += 1
        else:
            height -= 1
        deepest = min(deepest, height)
    ans = '(' * (-deepest) + S + ')' * (height - deepest)
    print(ans)

if __name__ == "__main__":
    main()
# Buggy code:
N = input()
s = input()
s1 = s
s2 = ''
while s1 != s2: 
    s2 = s1
    s1 = s1.replace('()','')
print(s1)
s2 = s1.replace('(','')

print(len(s2)*'(' + s + (len(s1)-len(s2))*')')


# Fixed code:
N = input()
s = input()
s1 = s
s2 = ''
while s1 != s2: 
    s2 = s1
    s1 = s1.replace('()','')
s2 = s1.replace('(','')

print(len(s2)*'(' + s + (len(s1)-len(s2))*')')
# Buggy code:
import numpy as np
import copy

N= int(input())
S=input()
SS= copy.copy(S)
S = list(S)
#N, A, B = map(int, input().split())

flag = 1
print(len(S))
while flag == 1:
    flag = 0
    flag2 = 1
    i = 0
    while flag2:
    # for i in range(len(S)-1):
        print(i)
        if S[i]=="(" and S[i+1] ==")":
            flag = 1
            del S[i] 
            del S[i+1]
            i -= 2
        i += 1
        i = max(0,i)
        if i>len(S):
            flag2 = 0
a=0
b=0
for i in range(len(S)):
    if S[i]=="(":
        b+=1
    elif S[i]==")":
        a+=1
print(S)
# initialization of string to ""
A = ""
B = ""

# traverse in the string
for x in range(a):
    
    A += "("   
for x in range(b):    
    B += ")"   

        
#print(str(A)+SS+str(B))
print(A+SS+B)
    


# Fixed code:
import numpy as np
import copy

N= int(input())
S=input()
SS= copy.copy(S)
S = list(S)
#N, A, B = map(int, input().split())

flag = 1
#print(len(S))
while flag == 1:
    flag = 0
    flag2 = 1
    i = 0
    while flag2 and len(S)>1:
    # for i in range(len(S)-1):
        #print(S)
        if S[i]=="(" and S[i+1] ==")":
            # print(S, i)
            flag = 1
            del S[i] 
            del S[i]
            i -= 1
            # print(S, i)
        i += 1
        i = max(0,i)
        if i+1>=len(S):
            flag2 = 0
a=0
b=0
for i in range(len(S)):
    if S[i]=="(":
        b+=1
    elif S[i]==")":
        a+=1
#print(S)
# initialization of string to ""
A = ""
B = ""

# traverse in the string
for x in range(a):
    
    A += "("   
for x in range(b):    
    B += ")"   

        
#print(str(A)+SS+str(B))
print(A+SS+B)
# Buggy code:
n=int(input())
s=input()
a=0 #"("
b=0 #")"
cnt=0
for i in range(n):
    if s[i]=="(":
        if a<b:
            cnt+=b-a
            a,b=1,0
        else:
            a+=1
    else:
        b+=1
if a<b:
    cnt+=b-a
s=(cnt*"("+s)
print(s+")"*(len(s)-s.count("(")))

# Fixed code:
n=int(input())
s=input()
a=0 #"("
b=0 #")"
cnt=0
for i in range(n):
    if s[i]=="(":
        if a<b:
            cnt+=b-a
            a,b=1,0
        else:
            a+=1
    else:
        b+=1
if a<b:
    cnt+=b-a
s=(cnt*"("+s)
a=s.count("(")
b=len(s)-a
print(s+")"*(a-b))
# Buggy code:
n=int(input())
S=input()
l=0
r=0
for s in S :
    if s == ")" :
        if r :
            r -= 1
        else :
            l += 1
    else :
        r += 1
ans = "("*l + S + ")"
print(ans)


# Fixed code:
input()
S=input()
l=0
r=0
for s in S :
    if s == ")" :
        if r :
            r -= 1
        else :
            l += 1
    else :
        r += 1
ans = "("*l + S + ")"*r
print(ans)
# Buggy code:
n = int(input())
s = input()

num = 0
lmax = 0
rmax = 0
for i in range(n):
    if s[i] == ")":
        num += 1
    else:
        num -= 1
    lmax = max(lmax, num)


for i in range(n-1, 0, -1):
    if s[i] == "(":
        num += 1
    else:
        num -= 1
    rmax = max(rmax, num)

print("("*lmax + s + ")"*rmax)

# Fixed code:
n = int(input())
s = input()

num = 0
lmax = 0
rmax = 0
for i in range(n):
    if s[i] == ")":
        num += 1
    else:
        num -= 1
    lmax = max(lmax, num)

num = 0
for i in range(n-1, -1, -1):
    if s[i] == "(":
        num += 1
    else:
        num -= 1
    rmax = max(rmax, num)

print("("*lmax + s + ")"*rmax)
# Buggy code:
import collections

N = int(input())
S = str(input())

num_open = 0
num_close = 0

q = collections.deque([])

for i in range(N):
  if S[i] == "(":
    q.append("(")
  if S[i] == ")":
    if len(q) == 0:
      num_close += 1
    else:
      q.pop()

str_close = "(" * num_close
str_open =  ")" * num_open


ans = str_close + S + str_open

print(ans)


# Fixed code:
import collections

N = int(input())
S = str(input())

num_open = 0
num_close = 0

q = collections.deque([])

for i in range(N):
  if S[i] == "(":
    q.append("(")
  if S[i] == ")":
    if len(q) == 0:
      num_close += 1
    else:
      q.pop()

num_open = len(q)
str_close = "(" * num_close
str_open =  ")" * num_open


ans = str_close + S + str_open

print(ans)
# Buggy code:
from collections import deque
N = int(input())
S = list(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))


# Fixed code:
from collections import deque
N = int(input())
S = list(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))
# Buggy code:
from sys import stdin
N = int(stdin.readline().rstrip())
S = (stdin.readline().rstrip())
stack = []
l = 0
r = 0
for i in range(N):
    if S[i] == "(":
        stack.append(1)
    elif S[i] == ")":
        if not stack:
            r += 1
        else:
            stack.pop()

l = len(stack)
print(l*"(" + S + r*")")

# Fixed code:
from sys import stdin
N = int(stdin.readline().rstrip())
S = (stdin.readline().rstrip())
stack = []
l = 0
r = 0
for i in range(N):
    if S[i] == "(":
        stack.append(1)
    elif S[i] == ")":
        if not stack:
            l += 1
        else:
            stack.pop()

r = len(stack)
print(l*"(" + S + r*")")
# Buggy code:
n = int(input())
s = input()

left = 0
leftplus = 0
for i in range(len(s)):
    if s[i] == '(':
        left += 1
    else:
        if left == 0:
            leftplus += 1
        else:
            left -= 1

right = 0
rightplus = 0
r = s[::-1]
for i in range(len(reverse)):
    if r[i] == ')':
        right += 1
    else:
        if right == 0:
            rightplus += 1
        else:
            right -= 1
print('('*leftplus + s + ')'*rightplus)

# Fixed code:
n = int(input())
s = input()

left = 0
leftplus = 0
for i in range(len(s)):
    if s[i] == '(':
        left += 1
    else:
        if left == 0:
            leftplus += 1
        else:
            left -= 1

right = 0
rightplus = 0
r = s[::-1]
for i in range(len(r)):
    if r[i] == ')':
        right += 1
    else:
        if right == 0:
            rightplus += 1
        else:
            right -= 1
print('('*leftplus + s + ')'*rightplus)
# Buggy code:
import sys


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


sys.setrecursionlimit(10 ** 9)


def main():
    N = int(input())
    S = list(input())
    answer = ""
    cnt = 0
    for s in S:
        if s == "(":
            cnt += 1
            answer += "("
        else:
            if cnt > 0:
                answer += ")"
                cnt -= 1
            else:
                answer += "()"
    if cnt > 0:
        answer += ")" * cnt
    print(answer)


if __name__ == "__main__":
    main()


# Fixed code:
import sys


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


sys.setrecursionlimit(10 ** 9)


def main():
    N = int(input())
    S = list(input())
    answer = ""
    right = 0
    left = 0
    for s in S:
        if s == "(":
            if right > 0:
                answer = "(" * right + answer
                answer += ")" * right
                right = 0
            left += 1
            answer += "("
        else:
            if left > 0:
                answer += ")"
                left -= 1
            else:
                right += 1
    if left > 0:
        answer += ")" * left
    if right > 0:
        answer = "(" * right + answer + ")" * right
    print(answer)


if __name__ == "__main__":
    main()
# Buggy code:
n = int(input())
s = str(input())

if s[0] == ')':
    s = '(' + s
if s[-1] == '(':
    s += ')'

r = 0
l = 0
for i in range(n):
    if r <= 0:
        if s[i] == ')':
            l += 1
        else:
            r += 1
    else:
        if s[i] == ')':
            r -= 1
        else:
            r += 1
result = '('*abs(l) + s + ')'*abs(r)

print(result)

# Fixed code:
n = int(input())
s = str(input())

r = 0
l = 0
for i in range(n):
    if r <= 0:
        if s[i] == ')':
            l += 1
        else:
            r += 1
    else:
        if s[i] == ')':
            r -= 1
        else:
            r += 1
result = '('*abs(l) + s + ')'*abs(r)

print(result)