Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02756 (python)

Fixed submission:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7
    S = input()
    Slist = [S]
    Q = II()
    Slist = ['']*Q+Slist+['']*Q
    left = Q-1
    right = Q+1
    r = False
    for _ in range(Q):
        query = input().split()
        if query[0] == '1':
            r ^= True
        else:
            if query[1] == '1':
                    if r:
                        # S = ''.join([S,query[2]])
                        Slist[right] = query[2]
                        right += 1

                    else:
                        # S = ''.join([query[2],S])
                        Slist[left] = query[2]
                        left -=1
            else:
                if r:
                    Slist[left] = query[2]
                    left -=1
                else:
                    # S = ''.join([S,query[2]])
                    Slist[right] = query[2]
                    right += 1
    # print(S[::-1] if r else S)
    if r:
        Slist[Q] = Slist[Q][::-1]

    print(''.join(Slist[::-1]) if r else ''.join(Slist))
                



    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7
    S = input()
    Slist = [S]
    Q = II()
    Slist = ['']*Q+Slist+['']*Q
    left = Q-1
    right = Q+len(S)
    r = False
    for _ in range(Q):
        query = input().split()
        if query[0] == '1':
            r ^= True
        else:
            if query[1] == '1':
                    if r:
                        # S = ''.join([S,query[2]])
                        Slist[right] = query[2]
                        right += 1

                    else:
                        # S = ''.join([query[2],S])
                        Slist[left] = query[2]
                        left -=1
            else:
                if r:
                    Slist[left] = query[2]
                    left -=1
                else:
                    # S = ''.join([S,query[2]])
                    Slist[right] = query[2]
                    right += 1
    # print(S[::-1] if r else S)
    print(''.join(Slist[::-1]) if r else ''.join(Slist))
                



    

if __name__ == '__main__':
    main()
Problem p02786 (python)

Fixed submission:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    H = II()
    from math import log2,floor
    print( 2**(floor(log2(H))+1)-1)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    H = II()
    from math import log2,floor
    print( 2**(floor(log2(H))+1)-1)

if __name__ == '__main__':
    main()
Problem p02861 (python)

Fixed submission:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = int(input())
    xy = XLMIIS(N)
    

    def distance(x1,y1,x2,y2):
        return ((x1-x2)**2 + (y1-y2) ** 2) ** 0.5

    def f(n):
        ans = n
        if n <= 0:
            return 1
        for i in range(1,n):
            ans *= i
        return ans
    

    sumdis = 0
    for i in range(N):
        for j in range(i+1,N):
            sumdis += distance(xy[i][0],xy[i][1],xy[j][0],xy[j][1])
    summ = sumdis  / N * 2
    print(summ)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = int(input())
    xy = XLMIIS(N)
    

    def distance(x1,y1,x2,y2):
        return ((x1-x2)**2 + (y1-y2) ** 2) ** 0.5

    def f(n):
        ans = n
        if n <= 0:
            return 1
        for i in range(1,n):
            ans *= i
        return ans
    

    sumdis = 0
    for i in range(N):
        for j in range(i+1,N):
            sumdis += distance(*xy[i],*xy[j])
    summ = sumdis  / N * 2
    print(summ)


if __name__ == '__main__':
    main()
Problem p02903 (python)

Fixed submission:
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    
    H,W,A,B = LMIIS()
    l1 = '0'*A + '1'*(W-A)
    l2 = '1'*A + '0'*(W-A)
    for i in range(B):
        print(l1)
    for i in range(H-B):
        print(l2)
        

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    
    H,W,A,B = LMIIS()
    line = '1'*A + '0'*(W-A)
    
    if H == 1 and B == 0:
        print(line)
    elif W == 1 and A == 0:
        for i in range(B):
            print(1)
        for i in range(H-B):
            print(0)
    elif W*B == H*A:
        for i in range(H):

                print(line[i*((W-A)//A)%W:] + line[:i*((W-A)//A)%W])

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    
    H,W,A,B = LMIIS()
    line = '1'*A + '0'*(W-A)
    if W*B == H*A:
        for i in range(H):

                print(line[(i*(W-A)//A)%W:] + line[:(i*(W-A)//A)%W])
    elif H == 1 and B == 0:
        print(line)
    elif W == 1 and A == 0:
        for i in range(B):
            print(1)
        for i in range(H-B):
            print(0)

if __name__ == '__main__':
    main()
Problem p02969 (python)

Fixed submission:
r =int(input())
print(3*r**2)

Buggy submission (verdict: Runtime Error):
r = input()
print(r**2*3)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = lambda x: sys.stdout.write(str(x))
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = False

def main():

    N = II()
    t = [-1] * N


    E = [  [] for _ in range(N)]
 
    reached = [False] * N
    for _ in range(N-1):
        u,v,w = LMIIS()
        u -=1
        v -=1
        E[u].append((v,w))
        E[v].append((u,w))
    dbg(E)
    t[E[0][0][0]] = 0

     
    def search(u):
        for v,w in E[u]:
            if t[v] == -1:
                t[v] = t[u] if w % 2 == 0 else t[u]^1
                search(v)
                

    search(E[0][0][0])

    for i in t:
        write(i)
        write(' ')






    pass
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
write = lambda x: sys.stdout.write(str(x))
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = False

def main():

    N = II()
    t = [-1] * N


    E = [  [] for _ in range(N)]
 
    reached = [False] * N
    for _ in range(N-1):
        u,v,w = LMIIS()
        u -=1
        v -=1
        E[u].append((v,w))
        E[v].append((u,w))
    dbg(E)
    t[E[0][0][0]] = 0

     
    def search(u):
        for v,w in E[u]:
            if t[v] == -1:
                t[v] = t[u] if w % 2 == 0 else t[u]^1
                search(v)
                

    search(E[0][0][0])

    for i in t:
        write(i)
        write(' ')






    pass
if __name__ == '__main__':
    main()
Problem p03102 (python)

Fixed submission:
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7
    
    N,M,C = LMIIS()
    B = LMIIS()
    A = [LMIIS() for _ in range(N)]

    ans = 0
    for i in range(N):
        dot = C
        for a,b in zip(A[i],B):
            dot += a*b
        if dot > 0:
            ans += 1
    print(ans)

    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from math import gcd, ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    N,M,C = LMIIS()
    B = LMIIS()
    A = [LMIIS() for _ in range(N)]

    ans = 0
    for i in range(N):
        dot = C
        for a,b in zip(A[i],B):
            dot += a*b
        if dot > 0:
            ans += 1
    print(ans)

    

if __name__ == '__main__':
    main()
Problem p03268 (python)

Fixed submission:
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10
    N,K = LMIIS()
    ans = 0

    if K % 2 == 1:
        print((N//K)**3)
        return
    
    
    

    #(N//K) ありうるKの倍数の数(0以外)

    #a,b,c,全部がKの倍数 のパターン
    ans += (N//K)**3
    #a,b,c,全部がKの倍数+K//2　のパターン
    ans += ((N-K//2)//K+1)**3
    print(ans)


    


    





    
main()

Buggy submission (verdict: Runtime Error):
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10
    N,K = LMIIS()
    ans = 0

    if K % 2 == 1:
        print((N//K)**3)
        return
    
    
    

    #(N//K) ありうるKの倍数の数(0以外)

    #a,b,c,全部がKの倍数 のパターン
    ans += (N//K)**3
    #a,b,c,全部がKの倍数+K//2　のパターン
    ans += ((N-K//2)//K+1)**3
    print(ans)


    


    





    
main()
Problem p03274 (python)

Fixed submission:
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    # from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7

    N,K = LMIIS()
    X = LMIIS()


    #left:X[0] right:X[K-1]
    left = 0
    right = K-1
    syaku = X[right] - X[left]
    if abs(X[left]) > abs(X[right]):
        min_time = syaku + abs(X[right])
    else:
        min_time = syaku + abs(X[left])


    for i in range(N-K+1):
        syaku = X[right] - X[left]
        if abs(X[left]) > abs(X[right]):
            min_time = min(min_time, syaku + abs(X[right]))
        else:
            min_time = min(min_time, syaku + abs(X[left]))
        
        left += 1
        right += 1
    
    print(min_time)



    
main()

Buggy submission (verdict: Runtime Error):
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    N,K = LMIIS()
    X = LMIIS()



    D = [0]*(N-1)
    pre = X[0]
    for i in range(1,N):
        D[i-1] = X[i] - pre
        pre = X[i]

    #left:X[0] right:X[K-1]
    left = 0
    right = K-1
    syaku = X[right] - X[left]
    if abs(X[left]) > abs(X[right]):
        min_time = syaku + abs(X[right])
    else:
        min_time = syaku + abs(X[left])


    for i in range(N-K):
        if abs(X[left]) > abs(X[right]):
            min_time = min(min_time, syaku + abs(X[right]))
        else:
            min_time = min(min_time, syaku + abs(X[left]))
        syaku = syaku + (X[right+1] - X[right]) - (X[left+1] - X[left])
        left += 1
        right += 1
    
    print(min_time)



    
main()
Problem p03546 (python)

Fixed submission:
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    H,W = LMIIS()
    C = []
    for i in range(10):
        C.append(LMIIS())
    A = []
    for i in range(H):
        A.append(LMIIS())
    
    from copy import deepcopy
    for m in range(10):
        for f in range(10):
            for t in range(10):
                C[f][t] = min(C[f][t], C[f][m] + C[m][t])


    
    ans = 0
    for line in A:
        for a in line:
            if abs(a) != 1:
                ans += C[a][1]
    print(ans)


    
main()

Buggy submission (verdict: Runtime Error):
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    H,W = LMIIS()
    C = []
    for i in range(10):
        C.append(LMIIS())
    A = []
    for i in range(H):
        A.append(LMIIS())
    
    from copy import deepcopy
    minC = deepcopy(C)
    for i in range(10):
        for j in range(10):
            for k in range(10):
                if minC[i][j] + minC[j][k] < minC[i][k]:
                    minC[i][k] = minC[i][j] + minC[j][k]
    
    ans = 0
    for line in A:
        for a in line:
            if a != -1 and a!= 1:
                ans += minC[a][1]
    print(ans)


    
main()
Problem p03569 (python)

Fixed submission:
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    S = deque(input())
    N = len(S)
    ans = 0
    if len(S) == 1:
        print(0)
        return
    left = S.popleft()
    right = S.pop()
    while True:
        if left == right:
            if len(S) >= 2:
                left = S.popleft()
                right = S.pop()
                continue
            else:
                break
            
        if left != 'x' and right!='x':
            print(-1)
            return

        ans += 1
        if left == 'x':
            if len(S)>0:
                left = S.popleft()
            else:
                break
        elif right == 'x':
            if len(S)>0:
                right = S.pop()
            else:
                break

    print(ans)



            

        

main()

Buggy submission (verdict: Runtime Error):
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    S = deque(input())
    N = len(S)
    ans = 0
    if len(S) == 1:
        print(0)
        return
    left = S.popleft()
    right = S.pop()
    while True:
        if left == right:
            if len(S) >= 2:
                left = S.popleft()
                right = S.pop()
                continue
            else:
                break
            
        if left != 'x' and right!='x':
            print(-1)
            return

        ans += 1
        if left == 'x':
            if len(S)>0:
                left = S.popleft()
            else:
                break
        elif right == 'x':
            if len(S)>0:
                right = S.pop()
            else:
                break

    print(ans)



            

        

main()
Problem p03623 (python)

Fixed submission:
x,a,b = map(int, input().split())
if abs(x-a) < abs(x-b):
    print('A')
else :
    print('B')

Buggy submission (verdict: Runtime Error):
x,a,b = map(int, input().split())
if abs(x-a) < abs(x-b):
    print('A')
else :
    print('B')

Buggy submission (verdict: Runtime Error):
# coding=utf-8
# a,b = map(int, raw_input().split())

x,a,b = map(int, input().split())
if abs(x-a) < abs(x-b):
    print('A')
else :
    print('B')
Problem p03624 (python)

Fixed submission:
hoge = [0] * 26
a = ord('a')
string = input()
for i in range(len(string)):
    hoge[ord(string[i])-a] = 1

for i in range(26):
    if hoge[i] == 0:
        print(chr(i+a))
        break
    if i == 25:
        print('None')

Buggy submission (verdict: Runtime Error):
# coding=utf-8
# a,b = map(int, raw_input().split())

# x,a,b = map(int, input().split())
# if abs(x-a) < abs(x-b):
#     print('A')
# else :
#     print('B')


hoge = [0] * 26
a = ord('a')
string = input()
for i in range(len(string)):
    hoge[ord(string[i])-a] = 1

for i in range(26):
    if hoge[i] == 0:
        print(chr(i+a))
        break
    if i == 25:
        print('None')
Problem p03696 (python)

Fixed submission:
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    N=II()
    S=input()
    p = 0
    num_right_p = 0
    ans = ''
    r = 0
    for s in S:
        if s == '(':
            p += 1
        else:
            if p > 0:
                p -= 1
            else:
                r += 1

    
        ans = '(' * r + S + ')' * p
    print(ans)
            
    

    
main()

Buggy submission (verdict: Runtime Error):
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    N=II()
    S=input()
    p = 0
    num_right_p = 0
    ans = ''
    r = 0
    for s in S:
        if s == '(':
            p += 1
        else:
            if p > 0:
                p -= 1
            else:
                r += 1

    
        ans = '(' * r + S + ')' * p
    print(ans)
            
    

    
main()