peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
def make_divisors(n):
    divisors=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i!=n//i:
                divisors.append(n//i)
    return divisors

N = int(input())
count = 0
for i in range(1,N+1,2):
    if len(make_divisors(i)) == 8:
        count += 1

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

ans = B // A
if ans > C:
    print(C)
else :
    print(ans)
# Judge status: Wrong Answer
n = int(input())
dic = {}
w = list(input().split())
ok = True
pre = w[0][0]
for s in w:
  if(s in dic):
    ok = False
  else:
    dic[s] = 0
  if(pre[-1] !=  s[0]):
    ok = False
  pre = s
if ok : print("Yes")
else: print("No")
# Judge status: Accepted
N = int(input())

def f(k):
    s = str(k)
    n = len(s)
    ans = 0
    for i in range(n):
        ans += int(s[i])
    return ans

ans = float("INF")
for i in range(1, N):
    j = N-i
    t = f(i) + f(j)
    ans = min(ans, t)

print(ans)
# Judge status: Accepted
#A
x, y, z = [int(_) for _ in input().split()]
x, y = y, x
x, z = z, x
print(x, y, z)
# Judge status: Accepted
N,X=map(int,input().split())
L=list(map(int,input().split()))
L=sorted(L)
count=0
for i in range(N):
	if i==(N-1):
		if X!=L[i]:
			count=count
		else:
			count+=1
	elif L[i]<=X:
		X-=L[i]
		count+=1
	
print(count)
# Judge status: Wrong Answer
import math
import numpy as np
H=int(input())
if H==1:
    print(1)
else:
    n = int(np.log2(H+1))
    ans = 2**(n+1)-1
    print(ans)
# Judge status: Wrong Answer
from collections import Counter

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

c = Counter(a)

for i in c.values():
    if i > 1:
        re += 1

if re > 0:
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer
from math import ceil
n,k=map(int,input().split())
if n <= k:
  print(1)
  quit()
A=list(map(int,input().split()))
ind = A.index(1)
ans = ceil((ind+1)/k)+ceil((n-ind+1)/k)
print(ans)
# Judge status: Wrong Answer
n,m,x,y=map(int,input().split())
X= list(map(int,input().split()))
Y= list(map(int,input().split()))
maxx = max(X)
miny = min(Y)
for i in range(x+1,y+1):
    if maxx +1 <= miny:
        print("No War")
        break
print("War")
# Judge status: Wrong Answer
h = int(input())
w = int(input())
n = int(input())

lo = max(h,w)
lp = min(h,w)

cnt = 0
tmp = 0
for i in range(h*w):
    if tmp < n and tmp+lo <= n:
        tmp += lo
        cnt += 1
    elif tmp < n and tmp+lo >= n:
        tmp += lp
        cnt += 1
    else:
        break
print(cnt)
# Judge status: Wrong Answer
A, B, C = map(int, input().split())
K = int(input())
a=0
for i in range(K):
    i += 1
    if B*(2**i) > A:
        if C*(2**(K-i)) > B*(2**i):
            print('Yes')
            a=1

if a==0:
    print('No')
# Judge status: Wrong Answer
# coding: utf-8
# Your code here!

def main():
    number = int(input())
    answear = sum([result for result in range(number) if result % 3 != 0 or result % 5 != 0])
    print(answear)
if __name__ == "__main__":
    main()
# Judge status: Accepted
from fractions import gcd

MOD = 1000000000 + 7

N = int(input())
A = list(map(int, input().split()))

l = 1
ans = 0
for a in A:
    g = gcd(a, l)
    l = (l // g) * a
    ans = (ans * (a // g)) % MOD
    ans = (ans + (l // a)) % MOD
print(int(ans))
# Judge status: Accepted
N, K = map(int, input().split())
A = list(map(int, input().split()))

# 1の場所を探す
pos = A.index(1)

count = 0
num_forward = pos  # 前方の残り数
num_backward = N - pos - 1  # 後方の残り数

# 前方にX回試行したときに負の余りが生じる場合は後方に回す
rest = num_forward % -(K - 1)
num_backward += rest

while num_forward > 0:  # 先頭まで1にする
    num_forward -= K - 1
    count += 1
while num_backward > 0:  # 末尾まで1にする
    num_backward -= K - 1
    count += 1
print(count)
# Judge status: Accepted
n = int(input())
A = []
B = []

for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A = A[::-1]
B = B[::-1]

t = 0

for i, j in zip(A, B):
    if (i+t) % j == 0:
        continue
    else:
        t += j - (i+t) % j
print(t)
# Judge status: Accepted
n,x,y = map(int,input().split())
k = [0]*(n)
 
for i in range(1,n):
  for j in range(i+1,n+1):
    ind = min(j-i,abs(x-i) + abs(j-y) + 1)
    k[ind] += 1
      
for i in range(1,n):
  print(k[i])
# Judge status: Wrong Answer
import collections
N,X,Y = list(map(int,input().split()))
ans = 0
A = []
B = []
for j in range(X+1,Y):
  A.append(j-1)
  A.append(N-j)
for f in range(len(A)):
  for h in range(1,A[f]+1):
    B.append(h)
B = str(B)
c = collections.Counter(B)
for i in range(1,N-Y+X+2):
  F = N-Y+X-i+1
  D = str(i)
  C = c[D]
  print(F+C)
# Judge status: Wrong Answer
N = int(input())
K = int(input())
X = int(input())
Y = int(input())
if K < N:
    ans = N*X + (N-K)*Y
else:
    ans = N*X
print(ans)
# Judge status: Accepted
p,r=input,range
A=sum([list(map(int,p().split()))for _ in r(3)],[])
b=[int(p())for _ in r(int(p()))]
print('Yes'if[v for v in[7,56,73,84,146,273,292,448]if sum(1<<i for i in r(9)if A[i]in b)&v==v]else'No')
# Judge status: Accepted
n,k=map(int, input().split())
result = 0
while n != 0:
    result+=1
    n//=k
print(result)
# Judge status: Accepted
n = int(input())

words = [input()]

for i in range(n-1):
  s = input()
  if s in words or words[-1][-1] != s[0]:
    print("No")
    exit()
  words.append(s)
print("Yes")
# Judge status: Accepted
A, B, C, D = map(int, input().split())

x = C-A
y = D-B
first = 'U'*y+'R'*x
second = 'D'+"L"*(x-1)+'D'*(y-1)+'L'
third = 'LU'+first+'RD'
last = 'RD'+second+'LU'

print(first+second+third+last)
# Judge status: Wrong Answer
import math
a=int(input())
b=list(i+1 for i in range(a))
www=0
for j in b:
  c=[x+1 for x in range(int(math.sqrt(j)//1))]
  for y in c:
    if j%y==0:
      if not j/y==y:
        www=+j*2
      else:
        www+=j
print(www)
# Judge status: Wrong Answer
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
if N == K:
    print(1)
elif K == 2:
    print(N-1)
else:
    print(math.ceil(N/(K-1)))
# Judge status: Accepted
k,n=map(int,input().split())
a=list(map(int,input().split()))

l=[]
for i in range(n-1):
    l.append(abs(a[i]-a[i+1]))
l.append(k-a[-1]+a[0])

print(sum(l)-max(l))
# Judge status: Wrong Answer
ess = input()
sse = ess[::-1]
hugs = 0
for i in range(0, len(ess)):
  if ess[i] != sse[i]: hugs += 1
    
print(hugs)
# Judge status: Accepted
a,b = map(int,input().split())
if a%3==0 or b%3==0 or (a+b)%3==0:
  print("Possible")
else:
  print("Impossible")
# Judge status: Wrong Answer
N,A,B = map(int,input().split())
print((N//(A+B))*B)
# Judge status: Accepted
a,b,k=map(int,input().split())

if a+b<k:
    print(0,0)
elif a<k:
    print(0,b-(k-a))
elif a==k:
    print(0,b)
elif a>k:
    print(a-k,b)
# Judge status: Wrong Answer
X,Y=map(int,input().split())
mod=pow(10,9)+7
m=(2*X-Y)//3
n=(2*Y-X)//3
if (X+Y)%3!=0 or m<=0 or n<=0:
    print("0")
else:
    bunsi=1
    bunbo=1
    for i in range(0,n):
        bunsi=(bunsi*(m+1+i))%mod
        bunbo=(bunbo*(1+i))%mod
    print((bunsi*pow(bunsi,mod-2,mod))%mod)
# Judge status: Wrong Answer
import math
import sys

n = int(sys.stdin.readline().rstrip())

if n == 1:
    print(1)
elif n == 2:
    print(2)
elif n % 2 == 1:
    print(n // 2)
    print(n // 2 + 1)
else:
    print(n // 2 - 1)
    print(n // 2 + 1)
# Judge status: Wrong Answer
n = int(input())
cnt = 0
mod = 10
while n//mod !=0:
    cnt += n//mod
    mod*=5
print(cnt)
# Judge status: Accepted
import math
import sys
n,k = map(int,input().split())
ans = 0

for i in range(1,n+1):
    if i >= k:
        ans += (1/n)
    else:
        ans += (1/n) * (1/2)**(math.ceil(math.log2(k/i)))
    
print(ans)
# Judge status: Accepted
import fractions
N = int(input())
A = list(map(int, input().split()))

L = [0]
R = [0]

for i in range(N):
    L.append(fractions.gcd(L[i],A[i]))
    R.append(fractions.gcd(R[i],A[N-i-1]))
R.reverse()

ans = 0

for i in range(N):
    ans = max(ans,fractions.gcd(L[i],R[i+1]))
    
print(ans)
# Judge status: Accepted
n,m=map(int, input().split())
if n>=m/2:
    m_fin = m//2
    print(m_fin)
else:
    m_aft = m -2*n
    m_fin = m_aft//4
    print(n+m_fin)
# Judge status: Accepted
N=int(input())
ans=False
for i in range(1,10):
    if N%i==0 and N/i>0 and N/i<10:
        ans=True
print('Yes' if ans else 'No')
# Judge status: Accepted
X, A, B = list(map(int, input().split()))
if A - B >= 0:
    print('delicious')
elif B - A <= X:
    print('safe')
else:
    print('dangerous')
# Judge status: Wrong Answer
A=[1,6,36,216,1296,7776,46656,9,81,729,6561,59049]
N=int(input())
ans=0
while N!=0:
  N-=max([a for a in A if a<=N])
  ans+=1
print(ans)
# Judge status: Accepted
def main():
    L, R, d = map(int, input().split())
    ans = 0
    for i in range(L, R + 1):
        if i % d == 0:
            ans += 1
    print(ans)
if __name__ == "__main__":
    main()
# Judge status: Accepted
n=int(input())
a=-(-n//10**9)
b=10**9*a-n
print(0,0,10**9,1,b,a)
# Judge status: Accepted
N,M=map(int,input().split())
*A,=map(int,input().split())
from heapq import*
B=[]
for a in A:
    B.append(-a)
heapify(B)
for i in range(M):
    b=heappop(B)
    b=0--b//2
    heappush(B,b)
print(-sum(B))
# Judge status: Wrong Answer
D=int(input())
c = list(map(int,input().split()))
last_day = [0]*26
score = 0

def calc_sum(day,t,sum,s):
  sum += s[t-1]
  for j in range(len(c)):
    if(j!=day-1):
      sum -= c[j]*(day-last_day[j])
  return sum

for i in range(D):
  s = list(map(int,input().split()))
  t = 1
  max = -10000000
  score = 0
  for j in range(26):
    if(max < calc_sum(i+1,j,score,s)):
      max = calc_sum(i+1,j,score,s)
      t = j
  last_day[t-1]=i
  print(t)
# Judge status: Accepted
A,B,C=map(int,input().split())

#for分の繰り返し範囲
#A*B % B=0
#A*(B+1) % B=A
#→繰り返し範囲はA*Bまでで十分

for i in range(A,A*B+1,A):
  if i%B==C:
    print("YES")
    exit()
print("NO")
# Judge status: Accepted
a,b = map(int, input().split())
if a+b>23:
    print(a+b-24)
else:
    print(a+b)
# Judge status: Accepted
a,b,c=map(int,input().split())
k=int(input())
ans=a+b+c-max(a,b,c)+max(a,b,c)*2**k
print(ans)
# Judge status: Accepted
A, B, K = list(map(int,input().split()))
if A >= K:
    A -= K
elif A+B >= K: 
    B = B + A - K
    A = 0
else:
    A = 0
    B = 0
print(str(A) + " " + str(B))
# Judge status: Accepted
n = int(input())
A = [*map(int, input().split())] + [0]
yen, stock = 1000, 0
now = A[0]
for nxt in A[1:]:
    if now < nxt:
        stock += yen // now
        yen -= yen // now * now
    else:
        yen += stock * now
        stock = 0
    now = nxt
print(yen + stock * now)
# Judge status: Wrong Answer
n = int(input())
s = [input() for i in range(n)]
print('AC x' + str((s.count('AC'))))
print('WA x' + str((s.count('WA'))))
print('TLE x' + str((s.count('TLE'))))
print('RE x' + str((s.count('RE'))))
# Judge status: Accepted
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

a = int(input())

print(a + a ** 2 + a ** 3)
# Judge status: Accepted
s = input()
if s[-1]=="s":
    print(s+"es")
else:
    print(s+"s")
# Judge status: Wrong Answer
x, y = map(int,input().split())

print(x + y/2)
# Judge status: Wrong Answer
n,k = map(int,input().split())


ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
abc = "abcdefghijklmnopqrstuvwxyz"

s = input()

ans = ""

for ss in s:
  ans += abc[ABC.find(ss)]
  
print(ans)
# Judge status: Accepted
a,b,c,k = map(int, input().split())
over = 10**18
if abs(a-b)> over:
    print("unfair")
elif k %2 == 0:
    print(a-b)
else:
    print(b-a)
# Judge status: Wrong Answer
a,b,k=map(int,input().split())
 
cnt=0
 
for i in range(1,min(a,b)+1):
	ans=0
	if a%i==0 and b%i==0:
		ans+=i
		cnt+=1
	if cnt==k:
		break
print(ans)
# Judge status: Accepted
def calc(n, x):
    up = 1
    bottom = 1
    for i in range(x):
        up *= (n - i)
        up = up % mod
        bottom *= (i + 1)
        bottom = bottom % mod
    return (up * pow(bottom, mod - 2, mod)) % mod

mod = (10 ** 9) + 7

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

ans = pow(2, n, mod) - 1
for i in [a, b]:
    ans -= calc(n, i)
print(ans % mod)
# Judge status: Accepted
s = list(input())
k = int(input())

for i in range(min(k,len(s))):
    if s[i] != '1':
        print(s[i])
        exit(0)

print(1)
# Judge status: Accepted
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 21:59:58 2020

@author: shinba
"""
N,K = map(int,input().split())

ans= 0

while N>0:
    N = N//K
    ans += 1
    
print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.readline
N = int(input())
def m5(N):
    count = 0
    while True :
        k = N // 5
        if k == 0 :
            break
        else :
            N = k
            count += k // 2
    return count
if N % 2 == 1 :
    print(0)
else :
    s = str(N)
    o = int(s[-1])
    N -= o
    print(m5(N))
# Judge status: Accepted
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

distance = abs(A - B)
speed = V - W
if (distance <= speed * T):
    print("YES")
else:
    print("NO")
# Judge status: Accepted
N, M = map(int,input().split())
if(M==N):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
import sys
# sys.stdin = open('input.txt')

from math import pi

r = int(input())
ans = 2 * r * pi
print(ans)
# Judge status: Accepted
X=int(input())
i=1
while True:
    if (X*i)%360==0:
        print(i)
        exit()
    i+=1
# Judge status: Accepted
s = input()
t = input()

cnt = 0
for i in range(len(s)):
    if s[i] != t[i]:
        cnt += 1

print(cnt)
# Judge status: Accepted
# import sys
# input = sys.stdin.readline
s = input()
if s[2]==s[3] and s[4]==s[5]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N = int(input())
S = [int(input()) for _ in range(N)]
s = sum(S)
S.sort()
cnt = 0
while s % 10 == 0 and cnt < N:
    if S[cnt] % 10 != 0:
        s -= S[cnt]
    cnt += 1
if cnt == N:
    s = 0
print(s)
# Judge status: Wrong Answer
import collections
A=int(input())
l_after=[]
l=list(map(int,input().split()))
l=collections.Counter(l).most_common()
for i in range(len(l)):
   if l[i][1] > 1:
      l_after.append(l[i][0])
l_after.sort(reverse=True)
if len(l_after) < 2:
   print(0)
   exit()
print(l_after[0]*l_after[1])
# Judge status: Accepted
def is_prime(x):
    if x <= 1:
        return False
    else:
        for i in range(2,x):
            if x % i == 0:
                return False
        return True

X = int(input())
while is_prime(X) == False:
    X += 1
print(X)
# Judge status: Accepted
N ,Q = map(int,input().split())
S = input()
lst = []
for i in range(Q):
    s,e = map(int,input().split())
    lst.append([s-1,e-1])
#print(lst)

cum = [0]*N
for i in range(1,N):
    if S[i-1] == 'A' and S[i] == 'C':
        cum[i] = cum[i-1] + 1
    else:
        cum[i] = cum[i - 1]

for v in lst:
    print(cum[v[1]] - cum[v[0]])
# Judge status: Wrong Answer
s = input()

print("A{}C".format(s))
# Judge status: Wrong Answer
a,b,k = map(int, input().split())
s = set()
for i in range(a,min(a+k,b+1)):
  s.add(i)
for i in range(max(a,b-k+1),b+1):
  s.add(i)
for i in s:
  print(i)
# Judge status: Accepted
N=int(input())
print(((N-1)*N)//2)
# Judge status: Accepted
N,K= list(map(int, input().split())) 

ans = [0]*(N+1)

for i in range(K):
    d = int(input())
    A = list(map(int, input().split())) 
    for j in range(d):
        ans[A[j]] = 1

res = len(ans)-1-sum(ans)
print(res)
# Judge status: Accepted
S = list(input())
count = 0
ans = 0

for i in range(len(S)):
    if S[i] == 'R':
        count += 1
        if ans < count:
            ans = count
    else:
        count = 0

    
print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
rate = [0] * 9
for i in range(n):
    for j in range(8):
        if 400 * j <= a[i] < 400 * (j + 1):
            rate[j] += 1
            break
    else:
        rate[8] += 1

counter = 0
for i in range(8):
    if rate[i] >= 1:
        counter += 1

print(max(1, counter), counter + rate[8])
# Judge status: Wrong Answer
N = int(input())
a = list(map(int, input().split()))
a =  list(map(lambda x: x // 400, a))
#print(a)
m = len(set(a))
M = len(set(a))
if 8 in a:
    m -= 1
    M += a.count(8)
    M -= 1
M = min(M, 8)
print(m, M)
# Judge status: Wrong Answer
N = int( input() )
s = input()
numbers = s.split()

def getCost(target):
  cost = 0
  for n in numbers:
    number = int(n)
    cost += (number - target)**2
  return cost

minCost = 0
for i in range(-100, 101):
  cost = getCost(i)
  if( cost < minCost ):
    minCost = cost
print(minCost)
# Judge status: Wrong Answer
mod = (int)(1e9+7)
n = (int)(input())

print(pow(10, n, mod) - 2*pow(9, n, mod) + pow(8, n, mod))
# Judge status: Accepted
inputs = list(map(str, input()))
 
output = ''
for i in inputs:
    if i == 'B':
        output = output[:-1]
    elif i == '1':
        output += '1'
    else:
          output += '0'
print(output)
# Judge status: Accepted
n=int(input())
a=int(input())

print('Yes' if n%500<=a else 'No')
# Judge status: Accepted
import collections

S = list(input())

c = collections.Counter(S)

ans = " "
for i in range(97,123):
    s = chr(i)

    if s in c:
        continue
    else:
        ans = s
        break

print("None" if ans ==" " else ans)
# Judge status: Accepted
N,K,Q = map(int,input().split())

L = [0 for _ in range(N)]

for _ in range(Q):
  k = int(input())
  L[k-1] +=1

s = sum(L)

for i in range(N):
  if K + L[i] -s <= 0:
    print("No")
  else:
    print("Yes")
# Judge status: Accepted
#みんなのプロコン2019-C
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

k,a,b = map(int,readline().split())

if b-a <= 2:
    print(k+1)
    exit()

res = max(0,(k-(a-1))//2)

ans = a+res*(b-a)

if not even(k-(a-1)):
    ans += 1

print(ans)
# Judge status: Accepted
c_1 = list(input())
c_2 = list(input())

if (c_1[0] == c_2[2] and c_1[1] == c_2[1] and c_1[2] == c_2[0]):
    print('YES')
else:
    print('NO')
# Judge status: Wrong Answer
A,B=input().split()
A=int(A)
B=int(100*float(B)+0.1)
C=A*B
print(int(C))
# Judge status: Accepted
from math import ceil
n,d = map(int,input().split())
print(ceil(n/(2*d+1)))
# Judge status: Wrong Answer
a, b = map(int, input().split())
print(a%b)
# Judge status: Accepted
A = []
for _ in range(3):
    a1, a2, a3 = map(int, input().split())
    A += [(a1, a2, a3)]

n = int(input())
B = []
for _ in range(n):
    B += [int(input())]

for i in range(3):
    A += [(A[0][i], A[1][i], A[2][i])]
A += [(A[0][0], A[1][1], A[2][2])]
A += [(A[0][2], A[1][1], A[2][0])]

ans = 'No'
for x in A:
    _ans = [1 for _x in x if _x in B]
    if len(_ans) == 3:
        ans = 'Yes'
        break

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

t = sum([int(i) for i in list(str(N))])
# print(t)

if t == 1:
    ans = 10
else:
    ans = t
print(ans)
# Judge status: Wrong Answer
S = input()
char_S = list(S)
Q = int(input())
for i in range(Q):
    query = input().split()
    if query[0] == "1":
        char_S.reverse()
    else:
        if query[1] == "1":
            char_S.insert(0,query[2])
        else:
            char_S.insert(len(char_S),query[2])
print(char_S)
# Judge status: Accepted
import heapq as hp
def o():return map(int,input().split())
n,m=o()
c=[[0] for i in range(m)]
for i in range(n):
  a,b=o()
  if a<=m:
    c[m-a]+=[-b]
d=[]
ans=0
for i in range(m-1,-1,-1):
  for j in c[i]:
    hp.heappush(d,j)
  ans-=hp.heappop(d)
print(ans)
# Judge status: Accepted
a,b=map(int,input().split())
if max(a,b)<= 8:
  print("Yay!")
else:
  print(":(")
# Judge status: Accepted
a, b = map(int, input().split())
h = 0
for i in range(1, b - a):
  h += i
print(h - a)
# Judge status: Accepted
n = int(input())
s = str(input())
alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
teb = alp[n:26]+alp[0:n]
ans = ''
for w in s:
    ans += teb[alp.index(w)]
print(ans)
# Judge status: Accepted
import math
a, b, n = map(int, input().split())
if n <= b - 1:
    m = math.floor(a*n/b)
else:
    m = math.floor(a-a/b)
print(m)
# Judge status: Wrong Answer
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
print(nl)
x, y, a, b, c = nm()
p = nl()
q = nl()
r = nl()
p.sort()
q.sort()
print(p)
print(q)
l = p[-x:] + q[-y:]
l.sort()
r.sort()
for i in range(c):
    if l[i] < r[-1]:
        l[i] = r.pop()
    else:
        break
print(sum(l))
# Judge status: Accepted
a, b, c, x, y = map(int, input().split())

cost1 = a * x + b * y
cost2 = c * max(x, y) * 2
if x < y:
    cost3 = c * x * 2 + b * (y - x)
else:
    cost3 = c * y * 2 + a * (x - y)
print(min(cost1, cost2, cost3))
# Judge status: Accepted
N, A, B=map(int, input().split())
if (B-A)%2==0:
  print((B-A)//2)
else:
  if A==1 or B==N:
    ans=(B-A-1)//2+1
  else:
    ans=min(A-1, N-B)+(B-A-1)//2+1
  print(ans)
# Judge status: Accepted
x, k, d = map(int,input().split())

x = abs(x)
a = min(k, x//d)

k -= a
x -= a * d

if k%2==0:
    print(x)
else:
    print(d-x)
# Judge status: Accepted
a, b = map(int, input().split())
ans = 0
if a >= 13:
    print(b)
elif 5 < a <= 12:
    print(b // 2)
else:
    print(0)
# Judge status: Accepted
n = int(input())
mod=10**9+7

if n==1:
    print(0)
else:
    print(((10**n)-(9**n)-(9**n)+(8**n))%mod)
# Judge status: Accepted
a, b, c = map(int, input().split())

print("Yes" if a <= c <= b  or b <= c <= a else "No")
# Judge status: Wrong Answer
a=int(input())
if a>=3200:
  print=("pink")
else:
  print=("red")
# Judge status: Accepted
def io():
    return map(int,input().split())
def op():
    return list(map(int,input().split()))
n,k=io()
s=set()
c=0
for _ in range(k):
    d=int(input())
    s.update(op())
for i in range(1,n+1):
    if i not in s:
        c+=1
print(c)
# Judge status: Accepted
N,x = map(int,input().split())
a = list(map(int, input().split()))
a.sort()
cnt=0

for i in a:
    x-=i
    if x>=0:
        cnt+=1

if x>0:
    cnt-=1

print(cnt)
# Judge status: Accepted
s=sorted(input())
if s[0]==s[1] and s[2]==s[3] and s[1]!=s[2]:
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
from collections import deque
N, M = map(int, input().split())
ways = [[] for i in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  ways[a].append(b)
  ways[b].append(a)
print(ways)
searched = [0 for i in range(N)]
searched[0] = 1
ans = [0 for i in range(N)]
d = deque([])
d.append(0)
while d:
  tmp = d.popleft()
  for w in ways[tmp]:
    if searched[w] == 0:
      searched[w] = 1
      ans[w] = tmp
      d.append(w)
print("Yes")
for a in ans[1:]:
  print(a + 1)
# Judge status: Accepted
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    P = [int(x) for x in input().split()]


    ans = 1
    mi = P[0]
    for i in range(1, N):
        if mi >= P[i]:
            ans += 1
        mi = min(mi, P[i])


    print(ans)



    
    

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
a = input()
if a[0] != a[1] != a[2]:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
import sys
from collections import defaultdict
d = defaultdict(int)

N, M = map(int, input().split())
li = [list(map(int, input().split())) for n in range(M)]

for i in li:
  if i[1] == N:
    d[i[0]] += 1

for i in li:
  if i[0] == 1 and d[i[1]] != 0:
    print("POSSIBLE")
    sys.exit()
    
print("IMPOSSIBLE")
# Judge status: Accepted
N, A, B = map(int, input().split())
p = N // (A + B)
q = N % (A + B)
if q < A:
    print(p*A + q)
else:
    print((p+1)*A)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
a.sort()
s=a[-1]/2
b=[[i,abs(i-s)] for i in a]
b.sort(key=lambda z:z[1])
print(a[-1],b[0][0])
# Judge status: Wrong Answer
s=input()
t=input()
f=1
tmp=0
if len(s)<len(t):
  print("UNRESTORABLE")
  exit()
n=len(s)
m=len(t)
for i in range(n-m+1):
  x=s[i:i+m]
  for j in range(m+1): #
    if j==m:
      print((s[:i]+t+s[i+m:]).replace("?","a"))
      exit()
    if x[j]=="?":
      continue
    elif x[j]!=t[j]:
      break
print("UNRESTORABLE")
# Judge status: Accepted
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    S = input().strip()

    S2 = S

    while S2.count("()"):
        S2 = S2.replace("()", "")

    x = S2.count("(")
    y = S2.count(")")

    print(y * "(" + S + x * ")")




if __name__ == '__main__':
    main()