peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
# 164 B

a, b, c, d = map(int, input().split())

while a != 0 or c != 0:
    c = c - b
    if c <= 0:
        print("Yes")
        break
    a = a - d
    if a <= 0:
        print("No")
        break
# Judge status: Wrong Answer
n = int(input())
ac = "AC"
wa = "WA"
tle = "TLE"
re = "RE"

ans = [0, 0, 0, 0]
for _ in range(n):
    a = input()
    if (a == ac):
        ans[0] += 1
    if (a == wa):
        ans[1] += 1
    if (a == tle):
        ans[2] += 1
    if (a == re):
        ans[3] += 1

print("AC x ",ans[0])
print("WA x ",ans[1])
print("TLC x ",ans[2])
print("RE x ",ans[3])
# Judge status: Accepted
H,N = map(int,input().split())
A = list(map(int, input().split()))
count = 0
for i in A:
    H = H - i
    
if H <=0:
    print("Yes")
else:
    print("No")
# Judge status: Accepted

s = input()
t = input()

if s == t[:len(t)-1]:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
W,H,x,y=map(int,input().split())

a=[]
judge=0

a.append(min(x,W-x)*H)
a.append(min(y,H-y)*W)

if a[0]==a[1]:
    judge=1

print(max(a),judge)
# Judge status: Accepted
S = input()
N = len(S)
ans = 0
for i in range(N):
  for j in range(i, N):
    if all('ACGT'.count(c)==1 for c in S[i:j+1]):
      ans = max(ans, j-i+1)
print(ans)
# Judge status: Accepted
# coding: utf-8
import itertools
import math
import bisect

N = int(input())
A = list(map(int, input().split(" ")))
A.sort()
B = list(map(int, input().split(" ")))
C = list(map(int, input().split(" ")))
C.sort()

res = 0
for bi in B:
    res += bisect.bisect_left(A, bi) * (N-bisect.bisect_right(C, bi))
print(res)
# Judge status: Accepted
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
pf={}
for i in range(2,int(n**0.5)+1):
  while n%i==0:
    pf[i]=pf.get(i,0)+1
    n//=i
if n>1:
  pf[n]=1
ans=0
for p in pf.keys():
  d=pf[p]
  tot=1
  cur=1
  ct=0
  while tot<=d:
    ct+=1
    if tot+cur+1>d:
      break
    else:
      cur+=1
      tot+=cur
  ans+=ct
print(ans)
# Judge status: Wrong Answer
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
K=int(input())
a=abs(A-B)
b=abs(A-C)
c=abs(A-D)
d=abs(A-E)
e=abs(B-C)
f=abs(B-D)
g=abs(B-E)
h=abs(C-D)
i=abs(C-E)
j=abs(D-E)
if K>a and K>b and K>c and K>d and K>e and K>f and K>g and K>h and K>i and K>j:
    print('Yay!')
else:
    print(':(')
# Judge status: Wrong Answer
n=int(input())
stone=str(input())
count=0
for i in range(n-1):
    if  stone[i]=='W' and stone[i+1]=='R':
        count=count+1
        m=1
        while m<=i and stone[i-m]=='W':
            if stone[i-m-1]=='W':
                count=count+1
                m=m+1
            else:
                m=m+1
print(count)
# Judge status: Accepted
n, m = map(int, input().split())
val = m//n
i = val
while i > 0 :
    if m % i == 0:
        print(i)
        exit()
    i -= 1
# Judge status: Accepted
L, R, d = list(map(int, input().split()))

ans_r = R // d
ans_l = L // d
ans = ans_r - ans_l

if ((L % d) == 0):
    ans += 1

print(ans)
# Judge status: Wrong Answer
a, b=map(int,input().split())
if a<=b:
  print(a)
else:
  print(b)
# Judge status: Wrong Answer
N, M = map(int, input().split())
an = []
nb = []
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        an.append(b)
    elif b == 5:
        nb.append(a)

print('IMPOSSIBLE' if len(set(an) & set(nb))==0 else 'POSSIBLE')
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in a:
    ans[i]+=1
for i in ans[1:]:
    print(i)
print(0)
# Judge status: Accepted
n, a, b = map(int, input().split())

print((n // (a + b) * a + min(n % (a + b), a)))
# Judge status: Wrong Answer
h, w = map(int, input().split())
if h==1 and w==1:
  print(0)
elif h%2==1 and w%2==1:
  print((h*w+1)//2)
else:
  print(h*w//2)
# Judge status: Wrong Answer
S = input()

ans=0
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        ans=ans+1
print(len(S)-ans+1)
# Judge status: Wrong Answer
N=int(input())
k=(N-1)//11
ans=2*k
if N-k*11<=5:
  ans+=1
else:
  ans+=2
print(ans)
# Judge status: Accepted
N,A = int(input()), list(map(int, input().split()))
b,r = [0]*N,[]

for i,x in enumerate(reversed(A)):
	if not x == sum(b[N-i-1::N-i])%2:
		b[N-1-i] = 1

for i,x in enumerate(b):
	if x:
		r.append(i+1)

print(len(r))
print(' '.join(map(str, r)))
# Judge status: Wrong Answer
import math
t,d=map(int,input().split())
c=0
for i in range(t):
    x,y=map(int,input().split())
    s=math.sqrt(x*x+y*y)
    if s<=d:
        c+=1
    print(c)
# Judge status: Wrong Answer
N, M = map(int, input().split())
Q = [list(map(int, input().split())) for i in range(M)]


for n in range(1000):
    X = list(map(int, list(str(n))))
    for s, c in Q:
        s -= 1
        if len(X) != N:
            break

        if X[s] != c:
            break
    else:
        print(n)
        exit()

print(-1)
# Judge status: Accepted
N = int(input())
mod = N % 1000
if mod == 0:
    print(0)
else:
    print(1000 - N % 1000)
# Judge status: Accepted


import numpy as np

s=sorted(input())

if(s==list("abc")):print("Yes")
else:print("No")
# Judge status: Wrong Answer
n = int(input())

for i in range(n):
    t,x,y = map(int,input().split())
    if (x + y) > t or (x + y + t) % 2:
        print("No")
        exit()
    print("Yes")
# Judge status: Accepted
import sys
read = sys.stdin.buffer.read
N, *AB = map(int, read().split())
A,B=AB[::2],AB[1::2]
A.sort()
B.sort(reverse=True)
pos=(N+1)//2-1
if N%2==1:
    ans = B[pos]-A[pos]+1
else:
    ans = (B[pos]+B[pos+1])-(A[pos]+A[pos+1])+1
print(ans)
# Judge status: Wrong Answer
import sys
S = list(">")
lis = [0] * (len(S)+1)

if len(S) == 1:
    print(1)
    sys.exit()


#最初は < を処理する
for i in range(len(S)):
    if S[i] == "<":
        lis[i+1] = lis[i] + 1




for j in range(len(S)-2,-1,-1):
    if S[j] == ">":
        lis[j] = max(lis[j],lis[j+1] + 1)



print(sum(lis))
# Judge status: Accepted
N = int(input())
S = input()
base = ord('A')
ans = ''
for s in S:
  ans += chr((ord(s)+N-base)%26 + base)
print(ans)
# Judge status: Wrong Answer
n,k,q =map(int,input().split())
ans=[0]*n
for i in range(q):
    a=int(input())
    ans[a-1]+=1
for i in range(n):
    if k+q-ans[i]>0:
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(n-1):
        if p[i]==(i+1):
            p[i],p[i+1]=p[i+1],p[i]
            cnt+=1
if p[-1]==n:
    cnt+=1
 
print(cnt)
# Judge status: Accepted
A, B = map(int, input().split())
if A >= 13:
  print(B)
elif 6 <= A <= 12:
  print(B // 2)
else:
  print(0)
# Judge status: Accepted
d,n = map(int, input().split())
 
if d == 0:
    if n < 100:
        print(n)
    else:
        print(101)    
elif d == 1:
    if n < 100:
        print(n*100)
    else:
        print(10100)
elif d == 2:
    if n < 100:
        print(n*10000)
    else:
        print(n*10000+10000)
# Judge status: Accepted
S = input()
if S == 'Sunny':
    print('Cloudy')
elif S == 'Cloudy':
    print('Rainy')
else :
    print('Sunny')
# Judge status: Accepted
n,m = map(int,input().split())
'''
和が偶数:
奇数＋奇数
偶数＋偶数
'''
ans = n*(n-1)//2 + m*(m-1)//2
print(ans)
# Judge status: Wrong Answer
import math
x = int(input())
s = math.floor(math.sqrt(x))
if x == 1:
  print(1)
  exit()

def l(k,p):
  return(int(math.floor(math.log(p)/math.log(k))))

ans = 0
for i in range(2,s+1):
  ans = max(ans, i ** l(i,x))
  
print(ans)
# Judge status: Accepted
from collections import defaultdict
d = defaultdict(int)
N=int(input())
s=input()
d[s]+=1
x=s[-1]
for i in range(N-1):
  s=input()
  if s[0]==x and d[s]==0:
    x=s[-1]
    d[s]+=1
  else:
    print('No')
    exit(0)
print('Yes')
# Judge status: Wrong Answer
N,S = open(0).read().split()
ans = 0
ls = []
cnt = 1
p = S[0]
for c in S[1:]:
  if p!=c:
    p = c
    ls.append(cnt)
    cnt = 1
  else:
    cnt += 1
ls.append(cnt)
if S[0]=='.':
  ls = ls[1:]
if len(ls)%2==1:
  ls = ls[:-1]
m = sum(ls[i] for i in range(0,len(ls),2))
n = sum(ls)-m
ans = min(n,m)
print(ans)
# Judge status: Wrong Answer
N = int(input())
x = 9
order = 0
for i in range(16):
    if x > N:
        break
    x = x*10+9
    order = i+1
ans = x
for i in range(10):
    ans -= 10**order
    if  ans < N:
        break
ret = 0
while True:
    if ans == 0:
        break
    ret += ans % 10
    ans = ans//10
print(ret)
# Judge status: Accepted
N = int(input())
L = list(map(int,input().split()))

ans=0
for i in range(N-1):
    if L[i]-L[i+1]>0:
        ans += L[i]-L[i+1]
        L[i+1]=L[i]
print(ans)
# Judge status: Accepted
n = int(input())
u = [list(map(int, input().split())) for i in range(n)]
z = [u[i][0] + u[i][1] for i in range(n)]
w = [u[i][0] - u[i][1] for i in range(n)]
d = [max(z)-min(z), max(w)-min(w)]

print(max(d))
# Judge status: Accepted
a, b = map(int, input().split())

if a <= 8 and b <= 8:
  print('Yay!')
else:
  print(':(')
# Judge status: Accepted
H_1, M_1, H_2, M_2, K = map(int, input().split())
print(H_2*60+M_2-(H_1*60+M_1)-K)
# Judge status: Wrong Answer
a=list(map(int,input().split()))
a.sort()
if a[0]==a[1]==a[2]:
  print(1)
else:
  if a[0]==a[1] or a[1]==a[2] or a[2]==a[0]:
    print(2)
  else:
    print(1)
# Judge status: Wrong Answer
a=input()
b=[]
for i in range(int(a[0])):
  b.append(input())

f=sorted(b)  

for i in range(int(a[0])):
  print(f[i],end='')
# Judge status: Wrong Answer
s = input()
t = input()
if((c.islower() for c in s) and (d.islower() for d in t) and (s in t) and len(s) + 1 == len(t)):
  print("Yes")
else:
  print("No")
# Judge status: Accepted
N=int(input())
ans=0
for i in range(1,N+1):
    if len(str(i))%2==1:
        ans=ans+1
print(ans)
# Judge status: Wrong Answer
n, m = map(int, input().split())

a = []
b = []
for i in range(m):
    c, d = map(int, input().split())
    a.append(c)
    b.append(d)

indexa_num = []
indexb_num = [x for x, v in enumerate(b) if v == n]
for i in indexb_num:
    indexa_num = [y for y, w in enumerate(a) if w == i]

ans = 'IMPOSSIBLE'
for j in indexa_num:
    if 1 == a[j]:
        ans = 'POSSIBLE'

print(ans)
# Judge status: Accepted
x = int(input())

if x % 11 == 0:
    ans = x // 11 * 2
else:
    if x % 11 <= 6:
        ans = x // 11 * 2 + 1
    else:
        ans = (x // 11 + 1) * 2

print(ans)
# Judge status: Accepted
n = input()
list = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
x = 7
for item in list:
    if n == item:
        print(x)
    x -= 1
# Judge status: Accepted
N = input()
count = 0
prev = 0
for i in range(len(N)):
  if 0 <= int(N[i]) + prev < 5:
    count += int(N[i]) + prev
    prev = 0
  elif 6 <= int(N[i]) + prev <= 9:
    count += 10 - (int(N[i]) + prev)
    prev = 1
  elif int(N[i]) + prev == 10:
    prev = 1
  else:
    if (i < (len(N) - 1) and int(N[i+1]) < 5) or i == len(N) - 1:
      count += 5
      prev = 0
    else:
      count += 5
      prev = 1
count = count + prev
print(count)
# Judge status: Accepted
n,m = map(int,input().split())
lScope = []
rScope = []
ans = 0
for i in range(m):
    l,r = map(int,input().split())
    lScope.append(l)
    rScope.append(r)
# k in keyScope[i] (i= 0~m) を確かめたい
if min(rScope) >= max(lScope):
    print(min(rScope) - max(lScope) + 1)
else:
    print(0)
# Judge status: Accepted
A, B = map(int, input().split())
cnt = 1
while A*cnt-(cnt-1) < B:
  cnt +=1
print(cnt if B > 1 else 0)
# Judge status: Wrong Answer
a, b, c = map(int, input().split())
ans = "No"
for i in range(b):
    if a*i % b == c:
        ans = "Yes"
        break
print(ans)
# Judge status: Wrong Answer
N,L=map(int,input().split())
ans=(L-1)*N+(N+1)*N//2

if (L<0 and L+N<0):
    ans-=L+N-1
elif L>=N or L>0:
    ans-=L
print(ans)
# Judge status: Accepted
S = input().replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if S:
    print("NO")
else:
    print("YES")
# Judge status: Accepted
import math

A, B = map(int, input().split())

x = math.ceil((B - A) / (A - 1)) + 1
print(x)
# Judge status: Accepted
N, X, T = list(map(int, input().split()))
ans = N // X
if N % X != 0:
  ans += 1
ans = ans * T
print(ans)
# Judge status: Accepted
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))
 
x = 100000
ans = 0
 
for i in range(N):
    temp = abs(A -(T - H[i]*0.006))
    if abs(A -(T - H[i]*0.006)) < x:
        x = abs(A -(T - H[i]*0.006))
        ans = i
 
print(ans+1)
# Judge status: Wrong Answer
a,b,c=input()
if a==b and b==c:
  print("NO")
else:
  print("YES")
# Judge status: Accepted
S = list(input())
len_S = len(S)
set_S = set(S)
len_set_S = len(set_S)
if len_S == len_set_S:
    print("yes")
else:
    print("no")
# Judge status: Accepted
k, s = map(int,input().split())
ans = 0

for x in range(k+1):
  for y in range(k+1):
    if 0 <= s-x-y <= k:
        ans += 1

print(ans)
# Judge status: Accepted
n, k=map(int, input().split())
a=list(map(int, input().split()))

cnt=k
ans=1
while cnt<n:
    cnt+=k-1
    ans+=1

print(ans)
# Judge status: Accepted
def main():
    N = int(input())
    result = 1
    for n in range(2,N + 1):
        result *= n
        result %= 10 ** 9 + 7
    print(result)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


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


def resolve():
    k = int(input())
    s = input()

    if k > len(s):
        print(s)
    else:
        print(s[:k] + "...")


if __name__ == "__main__":
    resolve()
# Judge status: Accepted
S = list(input())
len_S = len(S)
a = [0]*(len_S+1)
for i, s in enumerate(S):
    if s == '<':
        a[i+1] = a[i]+1
for i, s in enumerate(S[::-1]):
    inv_i = len_S-1-i
    if s == '>':
        a[inv_i] = max(a[inv_i+1]+1, a[inv_i])
print(sum(a))
# Judge status: Wrong Answer
S = str(input())

if S[len(S)-1] == 'e':
    print(S + 's')
else:
    print(S + 'es')
# Judge status: Accepted
icase=44
if icase==44:
    n=int(input())
    k=int(input())
    x=int(input())
    y=int(input())
    if n<=k:
        print(n*x)
    else:
        print(k*x+(n-k)*y)
# Judge status: Wrong Answer
n,x,t=map(int,input().split())
print((n//x+1)*t)
# Judge status: Accepted
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    a, b, c = MI()
    if a <= c and c <= b:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()
# Judge status: Accepted
N = int(input())
memo = {}
for _ in range(N):
    Ai = int(input())
    try:
        memo[Ai] += 1
    except:
        memo[Ai] = 1

ans = 0
for i in memo:
    if memo[i] % 2 == 1:
        ans += 1

print(ans)
# Judge status: Accepted
N,K=map(int,input().split())
*A,=map(int,input().split())

print(-(-(N-1)//(K-1)))
# Judge status: Accepted
t = list(input())
ans =""
for i in t:
    if i == "?":
        ans += "D"
    else:
        ans += i
print(ans)
# Judge status: Wrong Answer
N=int(input())
L = [list(map(int, input().split())) for i in range(N)]
dp=[[0 for j in range(3)] for i in range(N)]
ans=[0]*(N+1)
for i in range(N):
  dp[i][0]=max(dp[i-1][1],dp[i-1][2])+L[i][0]
  dp[i][1]=max(dp[i-1][2],dp[i-1][0])+L[i][1]
  dp[i][2]=max(dp[i-1][0],dp[i-1][1])+L[i][2]
  ans=max(dp[i][0],dp[i][1],dp[i][2])
  #print(ans)
print(ans)
# Judge status: Wrong Answer
s=input()
s1=set(list(s[::2]))
s2=set(list(s[1::2]))
if len(s1)==1 and len(s2)==1 and "h" in s1 and "i" in s2:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
S = input()
a = [0] * (len(S) + 1)

for i in range(len(S)):
    if S[i] == '<':
        a[i + 1] = max(a[i + 1], a[i] + 1)

for i in range(len(S) - 1, 0, -1):
    if S[i] == '>':
        a[i] = max(a[i], a[i + 1] + 1)

print(sum(a))
# Judge status: Accepted
SX, SY, TX, TY = map(int, input().split())
way1 = 'U' * (TY - SY) + 'R' * (TX - SX)
way2 = 'D' * (TY - SY)+ 'L' * (TX - SX)
way3 = 'L' + 'U' * (TY - SY + 1) + 'R' * (TX - SX + 1) + 'D'
way4 = 'R' + 'D' * (TY - SY + 1) + 'L' * (TX - SX + 1) + 'U'
print(way1 + way2 + way3 + way4)
# Judge status: Accepted
n , m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ans = []
for i in range(n):
    cnt = 0
    for j in range(m):
        if ab[j][0] == i+1 or ab[j][1] == i+1:
            cnt += 1
    ans.append(cnt)
for k in range(n):
    print(ans[k])
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
d = {}
for c in a:
    if c in d.keys():
        d[c] += 1
    else:
        d.setdefault(c, 1)
ans = 0
for indx, cnt in d.items():
    if indx < cnt:
        ans += cnt - indx
    elif indx > cnt:
        ans += cnt
print(ans)
# Judge status: Wrong Answer
l = list(map(int, input()))
sum = 0
for i in range(len(l)):
    sum += l[i]

print(sum)
# Judge status: Accepted
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
    c4 = c2 = 0
    for x in a:
        if not x % 4: c4 += 1
        elif not x % 2: c2 += 1
    ans = 'Yes' if c4 >= n // 2 or c4 * 2 + c2 >= n else 'No'
    print(ans)

if __name__ ==  '__main__':
    main()
# Judge status: Wrong Answer

def solve():
    i = L//2019
    ans = 0
    while L <= 2019*i <= R:
        i += 1
#    print(i)
    if i >= 1:
        print(ans)
    else:
        ans = (L*(L+1)) % 2019
        print(ans)


if __name__ == "__main__":
    L,R = list(map(int, input().split()))
    solve()
# Judge status: Wrong Answer
s = input()
f, b = int(s[:2]), int(s[2:])
if (f == 0 or b == 0): print("NA")
elif (f > 12 and b > 12): print("NA")
elif (f > 12): print("YYMM")
elif (b > 12): print("MMYY")
else: print("AMBIGUOUS")
# Judge status: Wrong Answer
import bisect
n, m = map(int, input().split())

# 市番号
order = []
pre = [[0] for _ in range(n + 1)]

for i in range(m):
    p, y = map(int, input().split())
    order.append([p, y])
    pre[p].append(y)

# 各県ごとにソート
for i in range(n + 1):
    pre[p].sort()

# 市番号順に，各県の何番目かをにぶたんで探す
# Judge status: Accepted
def main():
    s = input()
    t = input()
    ans = 'No'
    s2 = s * 2
    for i in range(len(s2)):
        if t == s2[i:i + len(s)]:
            ans = 'Yes'
            break
    print(ans)



if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
X = int(input())
MAX = 10**5+3
num = 2
primes = [0 for _ in range(MAX+1)]

while(num**2 > MAX):
  if primes[num] == 1:
    num += 1
    continue
  i = 2
  while(num*i <= MAX):
    primes[num*i] = 1
    i += 1
while(True):
  if primes[X] == 0:
    print(X)
    exit()
  else:
    X += 1
# Judge status: Wrong Answer
loop_count = int(input())

ac_count = 0
wa_count = 0
tle_count = 0
re_count = 0

for i in range(loop_count):
    result = input()
    if result == 'AC':
        ac_count += 1
    elif result == 'WA':
        wa_count += 1
    elif result == 'TLE':
        tle_count += 1
    else:
        re_count += 1

print("AC × {0}".format(str(ac_count)))
print("WA × {0}".format(str(wa_count)))
print("TLE × {0}".format(str(tle_count)))
print("RE × {0}".format(str(re_count)), end="")
# Judge status: Accepted
n,a,s=int(input()),list(map(int,input().split())),0
for x in a:
	s ^= x
print(' '.join(list(map(str,[x^s for x in a]))))
# Judge status: Accepted
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.sort()
y.sort()

if x[-1] < y[0] and X < y[0] and x[-1] < Y:
    print('No War')
else:
    print('War')
# Judge status: Accepted
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b=INTM()
    if a>=b:
        c=a-1
        d=b
    else:
        c=b-1
        d=a
    print(max(a,b)+max(c,d))
if __name__ == '__main__':
    do()
# Judge status: Accepted
def main():
    N=int(input())
    a=[int(input()) for i in range(N)]
    tmp=1
    for i in range(N):
        if tmp==2:
            print(i)
            exit()
        tmp = a[tmp-1]
    print(-1)
main()
# Judge status: Accepted
n = int(input())
array = list(input())
ret = []

count = 0
for str in array:
    if str == "(":
        count += 1

    if str == ")":
        count -= 1
        if count < 0:
            for i in range(-count):
                ret.insert(0, "(")
            count = 0
    ret.append(str)
for i in range(count):
    ret.append(")")

print(''.join(ret))
# Judge status: Accepted
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Asum = [0]
Bsum = [0]
a = 0
b = 0
for i in range(N):
    a += A[i]
    Asum.append(a)
for i in range(M):
    b += B[i]
    Bsum.append(b)
Asum.append(0)
Bsum.append(0)
res, j = 0, M
for i in range(N+1):
    if Asum[i] > K:
        break
    while Asum[i] + Bsum[j] > K:
        j -= 1
    res = max(res,i+j)
print(res)
# Judge status: Accepted
def Fibonacci(n):
  if n==1 or n==2:
    return 1
  a,b=1,1
  for i in range (3,1+n):
    a,b=a+b,a
  return a

n,m=map(int,input().split())
bk=-1
ans=1
for i in range(m):
  a=int(input())
  if bk==-1 and a==2:
    ans*=2
  elif bk+1==a:
    print(0)
    exit()
  ans*=Fibonacci(a-bk-1)
  bk=a
if bk!=m:
  ans*=Fibonacci(n-bk)
print(ans%(10**9+7))
# Judge status: Accepted
N=input()
N=int(N)
if N<1000:
    print('ABC')
else:
    print('ABD')
# Judge status: Accepted
k=int(input())
print((k // 2) * ((k + 1) // 2))
# Judge status: Accepted
import numpy as np

N,W = list(map(int,input().split()))
dp = np.zeros(W+1,dtype = int)
for i in range(N):
    w,v = list(map(int,input().split()))
    dp[w:] = np.maximum(dp[w:],dp[:-w] + v)
print(dp[-1])
# Judge status: Wrong Answer
from heapq import nlargest
n = int(input())
a = [int(input()) for i in range(n)]
l1, l2 = nlargest(2, a)

for i in a:
  if a == l1:
    print(l2)
  else:
    print(l1)
# Judge status: Accepted
N = int(input())
A = [0] + [int(input()) for i in range(N)]

now = 1
count = 0
pushed = {1}
while now != 2:
  now = A[now]
  count += 1
  if now in pushed:
    print(-1)
    quit()
  pushed.add(now)

print(count)
# Judge status: Accepted
A, B, C = map(int,input().split())

x = B // A
if x < C:
    print(x)
else:
    print(C)
# Judge status: Accepted
#!/usr/bin/env python3
n = int(input())
*a, = map(int, input().split())
b = [0]*(n//2) + a[n//2:]
for i in reversed(range(n//2)):
    b[i] = sum(b[(i+1)*(j+1)-1] for j in range(n//(i+1)))%2 ^ a[i]
print(sum(b))
print(*[i+1 for i in range(n) if b[i]==1])
# Judge status: Wrong Answer
import copy

def blight(dist,_i):
	l=_i-dist
	r=_i+dist+1
	if l<0:l=0
	if r>n:r=n
	for _ in range(l,r):
		b[_]+=1

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

cnt=0
cntmax=450
while cnt<k:
	if cnt>cntmax:
		break

	b=[0]*n
	for i in range(n):
		blight(a[i],i)
	cnt+=1
	a=copy.deepcopy(b)
	print(b)
print(" ".join(map(str,b)))
# Judge status: Wrong Answer
N = int(input())
L1 = []
for i in range(N):
    L1.append(list(input().split()))

L2 = L1

ans=[]
for i in L1:
    seq = 1
    for j in L2:
        if i[0] > j[0]:
            seq += 1
        elif i[0] == j[0]:
            if int(i[1]) < int(j[1]):
                seq += 1
    ans.append(seq)
    

print(ans)

for i in range(N):
    print(ans.index(i+1)+1)
# Judge status: Wrong Answer
from itertools import combinations, chain

def main():
    n,m,x = map(int, input().split())
    books = [list(map(int, input().split())) for _ in range(n)]
    comb = [*chain(*(combinations(books, n+1) for n in range(len(books))))]
    print(comb)
    money = 10**9
    for c in comb:
        c = c[0]
        s = sum([c[i] for i in range(1,m+1)])
        if s < x:
            break
        money = min(money,sum(c[0] for _ in c))
    if money == 10**9:
        money = -1
    print(money)

if __name__ == '__main__':
    main()
# Judge status: Accepted
N = int(input())
print((N*800)-((N//15)*200))
# Judge status: Wrong Answer
X = int(input())
n = 1
p = 100
while True:
    p = p*(1 + 1/100)
    if p >= X:
        print(n)
        break
    n = n + 1
# Judge status: Accepted
s = input()
a = 0
b = 0
for i in range(len(s)):
    if i & 1:
        if s[i] == "0":
            a += 1
        else:
            b += 1
    else:
        if s[i] == "0":
            b += 1
        else:
            a += 1
print(min(a, b))
# Judge status: Accepted
a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, i = map(int, input().split())
if a - b == d - e == g - h and b - c == e - f == h - i:
    print('Yes')
else:
    print('No')