peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
import numpy as np
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
m2 = [1 for i in range(60)]
for i in range(1,60):
    m2[i] = (m2[i-1]*2)%mod

n1 = np.zeros(60,dtype=int)
for i in a:
    sai = list(map(lambda x:int(x),str(format(i,'060b'))))
    n1 += sai

'''
ans = 0
for i in range(60):
    ans = (ans+((n1[i]*(n-n1[i]))%mod*m2[59-i])%mod)%mod

print(ans)
'''
# Judge status: Wrong Answer
A = int(input())
B = int(input())

l = [1,2,3]
l.remove(A)
l.remove(B)

print(l)
# Judge status: Accepted
from collections import Counter

n = int(input())
s = input()

cnt = Counter(s)

ans = 1

for v in cnt.values():
    ans *= v + 1
    ans %= (10 ** 9 + 7)

print(ans - 1)
# Judge status: Wrong Answer
#!/usr/bin/env python3

def main():
    S = int(input())

    x1, y1 = 0, 0
    x2, y2 = 1000000000, 1

    x3 = (x2 - (S % x2)) % x2
    y3 = (S + x3) / x2

    print('{} {} {} {} {} {}'.format(x1, y1, x2, y2, x3, y3))


if __name__ == "__main__":
    main()
# Judge status: Accepted
N, H = map(int, input().split())
AB = [[int(i) for i in input().split()] for _ in range(N)]
A, B = map(list, zip(*AB))
B.sort()
X = max(A)
S = sum(B)

cnt = 0
if H > S:
    cnt += (H - S) // X
    H = H - X * cnt
if H > 0:
    for b in B[::-1]:
        H -= max(b, X)
        cnt += 1
        if H <= 0: break
while H > 0:
    H -= X
    cnt += 1
print(cnt)
# Judge status: Accepted
s = input()
l = len(s)
if l == 1:
	ans = int(s)
elif s[1:].count("9") == l-1:
	ans = int(s[0]) + 9 * (l-1)
else:
	ans = (l-1)*9 + (int(s[0])-1)

print(ans)
# Judge status: Wrong Answer
N, K = map(int, input().split())
S = input()

happiness = 0

for word in S.split("L"):
    happiness += max(0, len(word) - 1)
for word in S.split("R"):
    happiness += max(0, len(word) - 1)

res = happiness + 2 * K
print(min(res, N))
# Judge status: Accepted
n, a, b = map(int, input().split())
if b < a or (a != b and n == 1):
    print(0)
    exit()
if a == b:
    print(1)
    exit()
_min = a*(n-1)+b
_max = a+b*(n-1)
ans = _max - _min + 1
print(ans)
# Judge status: Accepted
S = input()

ans = 0
tmp = 0
for s in S:
  if s in ["A", "C", "G", "T"]:
    tmp += 1
  else:
    ans = max(ans, tmp)
    tmp = 0
ans = max(ans, tmp)

print(ans)
# Judge status: Accepted
K,X=map(int, input().split())
sum = 500 * K
if sum >= X:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
x = int(input())

if 400<=x<=599:
    print('8')
elif 600<=x<=799:
    print('7')
elif 800<=x<=999:
    print('6')
elif 1000<=x<=1199:
    print('5')
elif 1200<=x<=1399:
    print('4')
elif 1400<=x<=1599:
    print('3')
elif 1600<=x<=1799:
    print('2')
elif 1800<=x<=1999:
    print('1')
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))

A.sort()

if A[0] == max(A):
    print(A[0])
else:
    a = A[0]
    b = 0
    for i in range(N):
        if a != A[i]:
            b = A[i]
            break

    def gcd(x, y):
        if y == 0: return x
        return gcd(y, x%y)

    print(gcd(a, b))
# Judge status: Accepted
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    x=A.index(1)+1
    ans=0
    ans+=-(-(x-1)//(K-1))
    x=-(-(x-1)//(K-1))*(K-1)+1
    ans+=-(-(N-x)//(K-1))
    print(ans)

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    a = [int(i) for i in input().split()]

    if a[0] >8 or a[1]>8:
        print("Yay!")
    else:
        print(":(")
# Judge status: Wrong Answer
K = int(input())
A, B = map(int, input().split())

a = int(A/K)
b = int(B/K)

if a == b:
  print("NG")
else:
  print("Yes")
# Judge status: Accepted
x = input()

cnt = 0

while len(x) - 1 > cnt:
    if x[cnt] == 'S' and x[cnt+1] == 'T':
        x = x[:cnt] + x[cnt+2:]
        cnt = max(0, cnt - 1)
    else:
        cnt += 1

print(len(x))
# Judge status: Wrong Answer
# -*- coding: utf-8 -*-
def main():
    StringS = input();
    list = [];
    max = len(StringS);
    for i in range(max):
        print('x');

main()
# Judge status: Accepted
s=input()
t=input()
s="".join(sorted(list(s)))
t="".join(sorted(list(t)))[::-1]
if s<t:print("Yes")
else:print("No")
# Judge status: Accepted
def q2():
    N = int(input())
    W = [int(i) for i in input().split()]
    min_abs = 100*100
    for i in range(N-1):
        new_abs = abs(sum(W[0:i+1]) - sum(W[i+1:]))
        min_abs = min(min_abs, new_abs)
    print(min_abs)

    
if __name__ == '__main__':
    q2()
# Judge status: Accepted
# ABC094A

a, b, x = map(int, input().split())
if x < a:
    print('NO')
elif b >= x-a:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
n = int(input())
a = [int(i) for i in input().split()]
ans = 1
if 0 in a:
   print(0)
   quit()
for i in a:
   ans *= i
   if ans > 10**18:
      ans = -1
      break
print(ans)
# Judge status: Wrong Answer
a, b, k = map(int, input().split())
if a-k < 0:
  b -= (k-a)
  a = 0
  print(a,b)
else:
  print(a-k,b)
# Judge status: Accepted
import sys
import collections
import itertools
import math

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    MOD = 10 ** 9 + 7

    c = collections.Counter(S)

    ans = 1
    for i in range(0, 27):
        ans *= c[chr(i + ord('a'))] + 1

    ans -= 1

    print(ans % MOD)


if __name__ == '__main__':
    main()
# Judge status: Accepted
s = input()
a,b=0,0
for si in s:
  if si=="1":
    b+=1
  else:
    a+=1
print(2*min(a,b))
# Judge status: Accepted
S = input()
key = "keyence"
ans = "NO"
for i in range(8):
    left = key[0:i]
    right = key[i:8]
    if S[0:i] == left and S[len(S)-7+i:len(S)] == right:
        ans = "YES"
print(ans)
# Judge status: Accepted
a, b = map(int, input().split())

n = b - a - 1
an = (n*(n+1))//2
print(an-a)
# Judge status: Accepted
x, y = map(int, input().split())
print(x + y//2)
# Judge status: Accepted
# 各数値の取得
a,b,c = map(int,input().split())

# 計算結果に基づいてメッセージを出力
if b - a == c - b:
    print("YES")
else:
    print("NO")
# Judge status: Wrong Answer
s = input()
k = int(input())
ans = "1"
for si in s:
    if si!="1":
        ans = si
        break
print(ans)
# Judge status: Accepted
n = int(input())
s = list(input())

maxi = 0

for i in range(n-1):
    left = set(s[:i+1])
    right = set(s[i+1:])
    g = len(left & right)
    if maxi<g:
        maxi = g

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

if A + 2 < B:
    K2 = K - A + 1
    print( K2 // 2 * ( B - A ) + K2 % 2 + A)
else:
    print( 1 + K )
# Judge status: Accepted
import math

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

print(math.ceil((b - a)/(a - 1)) + 1)
# Judge status: Accepted
N, M = list(map(int,input().split()))
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
C = [[]*M for _ in range(N)]

def match(i,j):
    for k in range(M):
        if A[i+k][j:j+M] != B[k]:return False
    return True

def a():
    for i in range(N-M+1):
        for j in range(N-M+1):
            if match(i,j):return "Yes"
    return "No"

print(a())
# Judge status: Accepted
n=int(input())

t=int(2*n**0.5)
ans = {i for i in range(1,t+1)}

sum=t*(t+1)//2


for i in range(t,0,-1):
    if sum-i >n:
        ans.remove(i)
        sum -= i
    elif sum-i == n:
        ans.remove(i)
        break

for i in ans:
    print(i)
# Judge status: Accepted
N = int(input())
S = input()
now = 0
right = 0
left = 0
add_left = 0
while now < N:
    if S[now] == '(':
        left += 1
    else:
        if left:
            left -= 1
        else:
            add_left += 1
    now += 1
for _ in range(add_left):
    print('(', end='')
print(S, end='')
for _ in range(left):
    print(')', end='')
# Judge status: Accepted
h, w, n = [list(map(int, s.split()))[0] for s in open(0)]
print(min(int((n-1)//h+1), int((n-1)//w+1)))
# Judge status: Accepted
n,k=map(int,input().split())
ki=[]
ai=[]
for i in range(1,k+1):
  ki.append(int(input()))
  ai.append(list(map(int,input().split())))

s=list(range(1,n+1))

for i in range(1,k+1):
  for j in range(len(ai[i-1])):
    if ai[i-1][j-1] in s:
      s.remove(ai[i-1][j-1])
    
print(len(s))
# Judge status: Accepted
import sys
a, b = map(int, input().split())
c = 0
s = 1

if b == 1:
    print(0)
    sys.exit()

while True:
    for e in range(s):
        c += 1
        s = s - 1 + a
        if s >= b:
            print(c)
            break
    else:
        continue
    break
# Judge status: Accepted
N = int( input())

A_1 = list(map(int, input().split() ))
A_2 = list(map(int, input().split() ))
result = 0

for i in range(N):
    result = max( result,sum( A_1[:i+1])+sum(A_2[i:]))
    
print(result)
# Judge status: Wrong Answer
N = int(input())
for i in range(1,50001):
  tmp = int(i * 1.08)
  if(tmp == N):
    print(str(tmp))
    exit()
print(":(")
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))

a = sorted(A)

result = list()

for i in range(N):
   result.append(A.index(a[i]) + 1)
  
print(result)
# Judge status: Accepted
from functools import reduce
from fractions import gcd
def lcm(x,y):
  return x*y//gcd(x,y)
def lcmm(l):
  return reduce(lcm,l)
n=int(input())
t=[int(input()) for _  in range(n)]
print(lcmm(t))
# Judge status: Wrong Answer
from heapq import heapify, heappop, heappush


N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
if N == 1:
    print(N >> M)
    exit()
heapify(A)
for i in range(M):
    a = -heappop(A)
    while a >= -A[0]:
        a >>= 1
    heappush(A, -a)
print(-sum(A))
# Judge status: Wrong Answer
x= input()
if x==0:
  print(1)
else:
  print(0)
# Judge status: Accepted
N,M = list(map(int,input().split()))
X = sorted(list(map(int,input().split())))
A = []
if N >= M:
    print(0)
    exit()
for i in range(M-1):
    A.append(X[i+1]-X[i])
print(X[-1]-X[0]-sum(sorted(A,key=lambda x: -x)[:N-1]))
# Judge status: Accepted
n=int(input())
l = list(map(int,input().strip().split()))[:n] 
rs= 1
l.sort()
if l[0]==0 :
    rs=0
else:
    for i in range(n):
        if(10**18 // rs < l[i]):
            rs = -1
            break
        rs=l[i]*rs
print(rs)
# Judge status: Accepted
x, y = list(map(int, input().split()))

gA = [1,3,5,7,8,10,12]
gB = [4,6,9,11]
gC = [2]

def ok(x, y, group):
    return (x in group) and (y in group)

if ok(x, y, gA):
    print("Yes")
elif ok(x, y, gB):
    print("Yes")
elif ok(x, y, gC):
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
H,W=map(int,input().split())
if H%2==0 or W%2==0:
    print(H*W//2)
elif H==1 or W==1:
    print(1)
else:
    a=int(H*W/2)
    print(a+1)
# Judge status: Wrong Answer
a=list(input())
b=0
for i in range(3):
	if a[i]==0:
		b=b+0
	else :
		b=b+1
print(b)
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

al=a.sort()
bl=b.sort()
cl=c.sort()

j=0
k=0
ans=0
for i in range(n):
    while a[i]>=b[j]:
        if j==n-1:
            break
        j+=1
    while b[j]>=c[k]:
        if k==n-1:
            break
        k+=1
    ans+=(n-j)*(n-k)
print(ans)
# Judge status: Accepted
def main():
    n=int(input())
    x=list(map(int, input().split()))
    d=[]
    rui=0
    kei=sum(x)
    for i in range(n-1):
        rui += x[i]
        d.append( abs(rui - (kei - rui)) )
    print(min(d))
    
if __name__ == "__main__":
    main()
# Judge status: Accepted
from collections import Counter

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

d = Counter()
for _ in range(n):
    a, b = map(int, input().split())
    d[a] += b

x = sorted(d.items(), key=lambda x: x[0])
cnt = 0
for a, b in x:
    cnt += b
    if cnt >= k:
        print(a)
        exit()
# Judge status: Accepted
a,b,c,d = map(int,input().split())
if max(a,c) > min(b,d):
    print(0)
else:
    print(min(b,d) - max(a,c))
# Judge status: Wrong Answer
n,m=map(int,input().split())
a=[0]*m
b=[list(map(int,input().split())) for _ in range(n) ]
      
for i in range(n):
  c=b[i][0]
  for j in range(1,c):
    a[b[i][j]-1]+=1


print(a.count(n))
# Judge status: Accepted
k=int(input())
a,b=list(map(int,input().split()))
for i in range(a,b+1,1):
  if i % k == 0:
    print("OK")
    exit()
print("NG")
# Judge status: Accepted
s = set(input())
l = list("abcdefghijklmnopqrstuvwxyz")
for i in s:
    l.remove(i)
if l == []:
    print("None")
else:
    print(l[0])
# Judge status: Accepted
n=int(input())

ans = ''
while n:
    tmp = (n-1)%26
    ans += chr(ord('a')+tmp)
    n-=1
    n//=26
print(ans[::-1])
# Judge status: Accepted
import numpy

W, H, N = map(int, input().split())
info = []
for _ in range(N):
    x, y, a = map(int, input().split())
    info.append([x,y,a])

plane = numpy.ones((H, W))

for x, y, a in info:
    if a == 1:
        plane[:, :x] = 0
    elif a == 2:
        plane[:, x:] = 0
    elif a == 3:
        plane[:y, :] = 0
    else:
        plane[y:, :] = 0
    
        
print(int(numpy.sum(plane)))
# Judge status: Accepted
n, k = map(int, input().split())
a = list(map(int, input().split()))


def ok(l):
    cnt = 0
    for L in a:
        cnt += L // l
        if L % l != 0:
            cnt += 1
        cnt -= 1
    return cnt <= k

#bottom:ng, top:ok
bottom, top = 0, max(a)

while top - bottom > 1:
    mid = (top + bottom) // 2
    if ok(mid):top = mid
    else: bottom = mid

print(top)
# Judge status: Accepted
N=int(input())
abc_list=[]
for i in range(N) :
  k=input().split()
  abc_list.append([int(i) for i in k])
n_list=  [[0 for i in range(3)] for j in range(N)]

n_list[0]=abc_list[0]
for i in range(1,N) :
  n_list[i][0]=max(n_list[i-1][1],n_list[i-1][2])+abc_list[i][0]
  
  n_list[i][1]=max(n_list[i-1][0],n_list[i-1][2])+abc_list[i][1]
  
  n_list[i][2]=max(n_list[i-1][0],n_list[i-1][1])+abc_list[i][2]
  

print(max(n_list[-1]))
# Judge status: Accepted
A,B,C = map(int,input().split())
K = int(input())
cnt = 0
for _ in range(K):
	if A>=B:
		B *= 2
		cnt += 1
	else:
		break

for _ in range(K-cnt):
	if B>=C:
		C *= 2
	else:
		break
#print(cnt)

if (A<B) and (B<C):
	print('Yes')
else:
	print('No')
# Judge status: Accepted
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(N):
  if i != N-1 and a[i] <= x:
    ans += 1
    x -= a[i]
  if i == N-1 and a[i] == x:
    ans += 1
print(ans)
# Judge status: Accepted
from collections import defaultdict
counts = defaultdict(lambda: 0)

n = int(input())
s = input()
ans = 0

for i, c in enumerate(s):
    counts[c] += 1
    j = 1
    while i - j >= 0 and i + j <= n - 1:
        if s[i - j] != s[i] and s[i] != s[i + j] and s[i - j] != s[i + j]:
            ans -= 1
        j += 1
print(ans + counts['R'] * counts['G'] * counts['B'])
# Judge status: Accepted
N, M = map(int, input().split())
assigns = list(map(int, input().split()))
left = N - sum(assigns)
if left >= 0:
	print(left)
else:
	print(-1)
# Judge status: Accepted
n = int(input())
a = map(int,input().split())
a = sorted(a)

result = 0
spots = [a.pop()]

for i in range(n-1):
	x = a.pop()
	result += spots[i]
	spots.append(x)
	spots.append(x)
	
print(result)
# Judge status: Accepted
a=int(input())
ans = 0
tmp = 2 
while tmp*tmp <=a:
    ct = 0 
    while not a % tmp:
        ct+=1
        a/=tmp
    for i in range(1,ct+1):
        if (1+i)*i/2<=ct:
            ans+=1
        else:
            break
    tmp+=1
if a != 1:
    ans+=1
print(ans)
# Judge status: Accepted
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1

    if 0 in A:
        print(0)
        return
    A1 = A[::2]
    A2 = A[1::2]

    if N%2 ==1:
        ans *= A1[-1]
    for i,j in zip(A1,A2):
        ans *= i*j
        if ans >10**18:
            return print(-1)

    return print(ans)


if __name__ == '__main__':
    solve()
# Judge status: Accepted
from collections import Counter
a = list(map(int,input().split()))
a = Counter(a).items()
print(len(a))
# Judge status: Wrong Answer
n=int(input())
k=1
for i in range(1,n):
    k=(k*i)%((10**9)+7)
print(k)
# Judge status: Accepted
a,b,c,d = map(int, input().split())
result =  [a*c,a*d,b*c,b*d]
print(max(result))
# Judge status: Accepted
n,d = map(int, input().split())
count = 0
for i in range(n):
  p,q = map(int, input().split())
  if p**2 + q**2 <= d**2:
    count += 1
print(count)
# Judge status: Wrong Answer
x, y, a, b, c = map(int,input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

cx = x-1
cy = y-1

while r:
    cz = r.pop()
    if p[cx] <= q[cy] and cz > p[cx]:
        p[cx] = cz
        cx -= 1
    elif p[cx] > q[cy] and cz > q[cy]:
        q[cy] = cz
        cy -= 1

print(sum(p[:x]) + sum(q[:y]))
# Judge status: Wrong Answer
s,t = input().split()
a,b = (int(x) for x in input().split())
u = input()

if u==s:
    print(a-1)
elif u==t:
    print(b-1)
# Judge status: Wrong Answer
a,b = map(int,input().split())
print(min(2*a-1, 2*b-1, a+b))
# Judge status: Wrong Answer
n=int(input())
c=[]
for i in range(n):
  a,b=map(int,input().split())
  if a==b:
    c.append(1)
  else:
    c.append(0)
cnt=0
for j in range(2,n):
  if c[j-2]==c[j-1] and c[j-1]==c[j]:
      print("Yes")
      break
  if j==n:
      print("No")
# Judge status: Accepted
s = list(input())
if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
    print('Bad')
else:
    print('Good')
# Judge status: Accepted
X = int(input())
limit = int(X ** 0.5)
ans = -1
prob_ans = []

if X == 1:
    ans = 1
for i in range(2, limit+1):
    p = 2
    while True:
        tmp = i ** p
        if tmp > X:
            break
        ans = max(ans, tmp)
        p += 1

print(ans)
# Judge status: Wrong Answer
def o(a):
    for i in range(len(a)):
        a[i]=[a[i],i+1]
    return a             

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

a=o(a)

q=[0]*n

for i in range(len(a)):
    q[a[i][0]-1]=a[i][1]

print(q)
# Judge status: Accepted
N = int(input())
ans = N//11
ans1 = N % 11
if(ans1 >= 7):
  ans2 = ans * 2 + 2
elif(ans1 <= 6) and (ans1 >= 1):
  ans2 = ans * 2 + 1
else:
  ans2 = ans * 2
print(ans2)
# Judge status: Accepted
A,B = map(int,input().split())
if(A<=5):
    print(0)
elif(A<=12):
    print(int(B/2))
else:
    print(B)
# Judge status: Wrong Answer
from sys import stdin
N,Y=list(map(int,stdin.readline().strip().split()))
count=0
flag=False
if abs(N)-abs(Y)==0:
    print(1)
    exit()
if N>Y:
    count+=1
    N*=-1
    flag=True
if Y-N<0:
    count+=1
    Y*=-1
if Y>N:
    print(count+Y-N)
else:
    print(count+N-Y)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
  b.append(0)
for i in range(n):
  b[a[i]-1] = i+1
for i in range(n):
  print(b[i],end=" ")
# Judge status: Accepted
s = input()

left = 0
right = 0
for i in range(len(s)):
    if s[i] == 'A':
        left = i
        break
for i in range(len(s) - 1, -1, -1):
    if s[i] == 'Z':
        right = i
        break
print(right - left + 1)
# Judge status: Accepted
import collections

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

MOD = 10 ** 9 + 7
c = collections.Counter(S)
ans = 1
for k, v in c.items():
    ans *= v + 1
    ans %= MOD

ans -= 1
print(ans)
# Judge status: Wrong Answer
K = int(input())
cnt=len(str(K))

if K % 2 == 0:
    print(-1)
else:
    while True:
        n = int(cnt*str(1))
        if n % int(K) != 0:
            cnt+=1
        else:
            print(len(str(n)))
            break
# Judge status: Wrong Answer
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]
a = 0
for i in range(0,N):
    if s.count(i) > 0:
        for j in range(0,M):
            if a < (s.count(s[i]) - t.count(t[j])):
                a = s.count(s[i]) - t.count(t[j])
print(a)
# Judge status: Accepted
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys

# import numpy as np

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

K = int(readline())
print(K // 2 * (K - K // 2))
# Judge status: Accepted
import heapq
N, M = map(int, input().split())
S = list()
A = [list() for _ in range(M+1)]
for _ in range(N):
    a, b = map(int, input().split())
    if M < a:
        continue
    heapq.heappush(A[a], -b)

ans = 0
for i in range(1, M+1):
    for num in A[i]:
        heapq.heappush(S, num)
    if S == []:
        continue
    ans -= heapq.heappop(S)
print(ans)
# Judge status: Accepted
h,a=map(int,input().split())
print((h-1)//a+1)
# Judge status: Accepted
N = int(input())
S = input()
a = S.count("E")
c = a 
 
for s in S:
  if s=="E":
    c-=1
  else:
    c+=1
  a=min(a,c)
 
print(a)
# Judge status: Wrong Answer
import collections

N = int(input())
cs = list(input())


count_R = cs.count("R")
count_W = cs.count("W")

W_check = cs[: count_W]
R_check = cs[count_R:]

print(min(W_check.count("W"), R_check.count("R")))
# Judge status: Accepted
N, C, K = map(int, input().split())
t = []
for i in range(N):
    t.append(int(input()))
t.sort()

ans = 0
pt = t[0]
cnt = 1

for i, ct in enumerate(t[1:]):
    if ct - pt > K:
        ans += 1
        cnt = 1
        pt = ct
    elif ct - pt <= K and cnt <= C:
        if cnt == C:
            ans += 1
            cnt = 0
            pt = ct
        cnt += 1
        
if cnt > 0:
    ans += 1
    
print(ans)
# Judge status: Accepted
n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]
l=[]
h.sort()
for i in range(n+1-k):
  x=h[i+k-1]-h[i]
  l.append(x)
print(min(l))
# Judge status: Accepted
n, r = map(int, input().split())

if n >= 10:
    ans = r
else:
    ans = r + 100*(10-n)

print(ans)
# Judge status: Accepted
a=[]
for q in range(4):
  g=int(input())
  a.append(g)
#a,b,c,x=map(int,input().split())
ans=0
for i in range(a[0]+1):
   for j in range(a[1]+1):
      for k in range(a[2]+1):
      	if a[3]==500*i+100*j+50*k:
        	ans+=1
print(ans)
# Judge status: Accepted
ans = 0
arr = [int(input()) for _ in range(5)]
ans = float('inf')
maxsum = 0
for i in range(5):
    maxsum += -(-arr[i] // 10) * 10
for i in range(5):
    if maxsum - -(-arr[i] // 10) * 10 + arr[i] < ans:
        ans = maxsum - -(-arr[i] // 10) * 10 + arr[i]
print(ans)
# Judge status: Accepted
a,b,c = map(int,input().split())
print('No' if a+b<c else 'Yes')
# Judge status: Accepted
s = input().split() 
print(s[2],s[0],s[1])
# Judge status: Wrong Answer
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
print(sum(a[0::2])  - sum(a[1::2]))
# Judge status: Accepted
N=input()
ans=0
for i in range(len(N)):
    ans+=int(N[i])
    ans%=9

if ans==0:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
def main():
    n = int(input())
    a = n - 1
    b = 1
    menor = soma_digitos(a) + soma_digitos(b)
    temp = 0
    for i in range(n-2):
        a -= 1
        b += 1
        temp = soma_digitos(a) + soma_digitos(b)
        if menor > temp:
            menor = temp
            print('A=', a,'B=', b)
    print(menor)

def soma_digitos(n):
    soma = 0
    while n >= 1:
        soma += n%10
        n = n//10
    return soma
main()
# Judge status: Accepted
N = int(input())



# 数値→アルファベット
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)


print(num2alpha(N).lower())
# Judge status: Wrong Answer
List=list(input())
N=len(List)
if N%4==3 and 0 not in [int(List[i]==List[(N-3)//2-i]) for i in range((N-1)//2)]\
and List[0:(N-3)//2]==List[(N+1)//2:N-1]:
    print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
time = 0
ares = 0
bres = 0
bsatu = int()
time2 = 0
res = []
for i in range(0,n): #Aで最高何冊読めるか
    if sum(a[n-i:]) < k and k <= sum(a[n-i-1:]):
        ares = i
for i in range(0,ares+1): #0からaresまで
    asatu = ares - i
    bsatu = 0
    time2 = sum(a[n-asatu:])
    bsatu += i
    if time >= k:
        break
    res += [asatu + bsatu]
print(max(res))