peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
X, N = map(int, input().split())
S = list(map(int, input().split()))

ans = X
for i in range(200):
    if X-i not in S:
        print(X-i)
        break
    elif X+i not in S:
        print(X+i)
        break
# Judge status: Accepted
H, M, h, m, K = map(int, input().split())

print( max(0, 60*(h-H) + m - M - K) )
# Judge status: Wrong Answer
n=int(input())
for i in range(n):
    if (i+1)**2>n:
        print(i**2)
        break
# Judge status: Wrong Answer
# input
N = int(input())
A = list(map(int, input().split()))

# check
app_fl = True
for Ai in A:
    if Ai % 2 == 0 and (Ai % 3 != 0 or Ai % 5 != 0):
        app_fl = False
        break

if app_fl is True:
    print("APPROVED")
else:
    print("DENIED")
# Judge status: Accepted
N, L = list(map(int, input().split()))
T = []
for i in range (1, N+1): 
	T.append(L+i-1)
if T[0] * T[-1] <= 0:
    print(sum(T))
else:
    if min(T) < 0:
        print(sum(T) - T[-1])
    else:
        print(sum(T) - T[0])
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)

res = 0
for i in range(N):
    res += A[i//2]
print(res-A[0])
# Judge status: Accepted
N=int(input())
*A,=map(int,input().split())

mx=max(A)
mn=min(A)


if len(set(A))==1:
    print(0)
else:
    ans=float('inf')
    for i in range(mn,mx):
        ans=min(ans, sum([(k-i)**2 for k in A]))
    print(ans)
# Judge status: Wrong Answer
a, b, c, k = map(int, input().split())

total=0
total+=a

if k - a == 0:
  print(total)
elif k - a < 0:
  print(total-k)
else:
  k-=a
  if k - b <= 0:
    print(total)
  else:
    k-=b
    print(total-k)
# Judge status: Accepted
a, b, c = map(int, input().split())
print(min(a+b, b+c, c+a))
# Judge status: Wrong Answer
N = int(input())
mod = 10**9+7

A = [0]*2001
A[0] = 1

for i in range(3,2000):
    A[i] = A[i-1] + A[i-3]
print(A[N]%mod)
# Judge status: Wrong Answer
h1, m1, h2, m2, k = map(int, input().split())

# 時間を、0時0分からの経過時間に変換する。
start = (60 * h1) + m1
end = (60 * h2) + m2 - k

print(start-end)
# Judge status: Wrong Answer
a_list = map(int, input().split())

can_devide = sum([a%2 for a in a_list])==0
count = 0
while can_devide:
    count += 1
    for i, a in enumerate(a_list):
        a_list[i] = a//2
        
    can_devide = sum([a%2 for a in a_list])==0

print(count)
# Judge status: Accepted


from sys import stdin
import sys

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs



def main(inputs):
	s=inputs[0][0]
	if len(s)%2==1:
		print("No")
		sys.exit(0)
	
	ok=True
	for i in range(0, len(s), 2):
		sub=s[i:i+2]
		if sub!="hi":
			ok=False
	if ok:
		print("Yes")
	else:
		print("No")
		
	

if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)
# Judge status: Accepted
N = int(input())
a = list(map(int, input().split()))
f = sum([1 for i in a if not i % 4])
if f >= int(N / 2):
  print('Yes')
else:
  s = sum([1 for i in a if not i % 2 and i % 4])
  if f + s // 2 >= int(N / 2):
    print('Yes')
  else:
    print('No')
# Judge status: Accepted
import bisect
import sys
input = sys.stdin.readline
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
A = A[::-1]
INF = int(1e+9 + 10)
lis = [INF]* (N+1)
lis[0] = -1
for n in range(N):
    i = bisect.bisect(lis, A[n])    
    lis[i] = A[n]
print (bisect.bisect_left(lis, INF) - 1)
# Judge status: Wrong Answer
d, n = map(int, input().split())
if n != 100:
    print(n*100**d)
else:
    print((n+1)*100**d)
# Judge status: Accepted
n, m = map(int, input().split())
a = list(map(int, input().split()))

ans = max(n - sum(a), -1)
print(ans)
# Judge status: Accepted
n=int(input())
for i in reversed(range(7)):
	if n>=2**i:
		print(2**i)
		quit()
# Judge status: Accepted
x, y = map(int, input().split())

cnt = 0
tmp = x
while tmp <= y:
    tmp *= 2
    cnt += 1
print(cnt)
# Judge status: Accepted
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cnt = 0
beforeKill = 0
for i in range(n):
    kill1 = min(A[i] - beforeKill, B[i])
    kill2 = min(A[i+1], B[i] - kill1)
    cnt += kill1 + kill2
    beforeKill = kill2
print(cnt)
# Judge status: Accepted
a = list(map(int,input().split()))
print(a.index(0)+1)
# Judge status: Accepted
import math
a, b = map(int, input().split())
mean = float((a + b) / 2)
print(math.ceil(mean))
# Judge status: Wrong Answer
s = input()
count = 0
for i in range(len(s)):
    if (i+1) % 2 != 0 and s[i] != 'R' and s[i] != 'U' and s[i] != 'D':
        count += 1
    elif (i+1) % 2 == 0 and s[i] != 'L' and s[i] != 'U' and s[i] != 'D':
        count += 1
    else:
        break
if count == 0:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
S = input()
a = S.count('a')
b = S.count('b')
c = S.count('c')
if abs(a-b) <= 1 and abs(a-c) <= 1 and abs(b-c) <= 1:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
n,k = list(map(int,input().split()))

snk_list = []
for i in range(k):
    input()
    b = list(map(int,input().split()))
    snk_list+=b

print(n-len(set(snk_list)))
# Judge status: Accepted
import sys

def solve():
    input = sys.stdin.readline
    S = int(input())
    #|ac - bd| == S, a == 10 ** 9
    a = 10 ** 9
    c = (S - 1) // a + 1
    bd = a * c - S
    if bd == 0: b, d = 0, 0
    else:
        for i in range(1, bd):
            if i ** 2 > bd: break
            if bd % i == 0:
                b, d = i, bd // i
                break
    print(0, 0, a, b, d, c)

    return 0

if __name__ == "__main__":
    solve()
# Judge status: Accepted
n=int(input())
h=list(map(int,input().split()))
ans="Yes"
for i in range(n-1):
  if h[i]<h[i+1]:
    h[i+1]-=1
  if h[i]>h[i+1]:
    ans="No"
    break
  
print(ans)
# Judge status: Wrong Answer
def read():
    h = int(input())
    w = int(input())
    n = int(input())
    return h, w, n


def calc(h, w, n):
    if h > w:
        return int(n / h) + 1
    else:
        return int(n / w) + 1


def main():
    print(calc(*read()))


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
N = int(input())
emp = list(map(int,input().split()))
emp.sort()
def rem_val(arr, value):
    while value in arr:
        try:
            arr.remove(value)
        except:
            break
for i in range(N):
    if(len(emp)!=0):
        print(emp.count(i+1))
        rem_val(emp,i+1)
    print(0)
# Judge status: Accepted
a, b, c = map(int, input().split())
cnt = 0
while cnt < c and a <= b:
    b -= a
    cnt += 1
print(cnt)
# Judge status: Accepted
W, a, b = map(int, input().split())

if abs(a - b) < W:
    print(0)
else:
    print(abs(a - b) - W)
# Judge status: Accepted
a, b, x = map(int, input().split())
ans = 'NO'
if x >= a and a + b >= x:
    ans = 'YES'
print(ans)
# Judge status: Wrong Answer
X = int(input())
ans = 0
money = 100
TAX = 1.01

while money < X:
  money = int(money * TAX)
  ans += 1
  
print(ans)
# Judge status: Accepted
import collections
n = int(input())
a = list(map(int,input().split()))
x = collections.Counter(a)
keys = []
values = []
b = list(set(a))
for i in b:
    z = x[i]
    keys.append(i)
    values.append(z*(z-1)//2)
s = sum(values)
d = dict(zip(keys,values))
for i in a:
    ans = s
    ans -= d[i]
    ans += (x[i]-1)*(x[i]-2)//2
    print(ans)
# Judge status: Accepted
if (int(input())) == 0:
    print(1)
else:
    print(0)
# Judge status: Accepted
n = int(input())
a = 1
while True:
  if n < 2 ** a:
    break
  a += 1
print(2**(a-1))
# Judge status: Wrong Answer
import heapq
N,M = map(int,input().split())
jobs = []
for _ in range(N):
  j = list(map(int,input().split()))
  if j[0] > M: continue
  jobs.append(((-j[1],-j[0]), j[0]))
heapq.heapify(jobs)

res = 0
for d in range(M):
  while jobs:
    t,i = heapq.heappop(jobs)
    s,_ = t
    if d+i <= M:
      res += -s
      break

print(res)
# Judge status: Accepted
X = int(input())

for i in range(10 ** 9):
    if (i * (i + 1)) // 2 >= X:
        print(i)
        exit()
# Judge status: Accepted
n, k = map(int, input().split())
 
ans = 0
for i in range(1, n+1):
  res = 0
  while i < k:
    i *= 2
    res += 1
  ans += (1/n)*(1/2)**res
print(ans)
# Judge status: Accepted
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *p = map(int, read().split())
p += [0]
cnt = 0
for i, pp in enumerate(p):
    if (i + 1) == pp:
        p[i + 1] = 0
        cnt += 1
print(cnt)
# Judge status: Accepted
import numpy as np

n = int(input())
B = list(map(int, input().split()))
A = [0]*n
A[0] = B[0]
A[n-1] = B[n-2]
for i in list(range(1,n-1)):
    A[i] = min(B[i-1], B[i])
print(sum(A))
# Judge status: Wrong Answer
N = int(input())
A = [int(input()) for _ in range(N)]
A=sorted(A)

ans=0
cnt=1
tmp=A[0]

for i in range(1,N):
    if A[i]!=tmp and cnt%2==0:
        tmp=A[i]
        cnt=1
    elif A[i]!=tmp and cnt%2!=0:
        tmp=A[i]
        cnt=1
        ans+=1
    elif A[i]==tmp:
        cnt+=1

print(ans)
# Judge status: Accepted


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


ans = 0
while H > 0:
  ans += 1
  H -= A

print(ans)
# Judge status: Wrong Answer
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
csf = [list(map(int, readline().split())) for _ in range(n - 1)]
for i, (c, s, _) in enumerate(csf):
    s += c
    for j, (cc, ss, ff) in enumerate(csf[i + 1:]):
        if s <= ss:
            s = ss
        else:
            if j + i < n - 2:
                s += s % ff
        s += cc
    print(s)
print(0)
# Judge status: Accepted
a,b,c = map(int, input().split())

tmp = a-b

if c - tmp < 0:
    print(0)
else:
    print(c-tmp)
# Judge status: Accepted
N,K = map(int, input().split())
A = list(map(int, input().split()))
T = N - K
if T == 0:
  print(1)
elif T%(K-1) == 0:
  print(1+T//(K-1))
else:
  print(2+T//(K-1))
# Judge status: Accepted
a = list(input().split())
a.sort()

x = a[0]
y = a[2]+a[1]

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

ans = 1
for b in range(1, 32):
    for p in range(2, 10):
        if b**p <= x:
            ans = max(ans, b**p)

print(ans)
# Judge status: Accepted
import math;
f=math.factorial;
n,m=sorted(map(int,input().split()));
print(max(2-m+n,0)*f(n)*f(m)%(10**9+7))
# Judge status: Wrong Answer
s = input()
oi = "01"
io = "10"
oans = 0
ians = 0
for i in range(len(s)//2):
    if s[2*i]+s[2*i+1] != oi:
        if s[2*i] == "0" or s[2*i+1] == "1":
            oans += 1
        else:
            oans += 2
    if s[2*i]+s[2*i+1] != io:
        if s[2*i] == "1" or s[2*i+1] == "0":
            ians += 1
        else:
            ians += 2
print(min(oans, ians))
# Judge status: Wrong Answer
N, x = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
keep = a[0]
for i in range(1, N):
    if (keep + a[i]) > x:
        ans = ans + (keep + a[i] - x)
        keep = x - keep
    else:
        keep = a[i]
ans2 = 0
a = a[::-1]
keep = a[0]
for i in range(1, N):
    if (keep + a[i]) > x:
        ans2 = ans2 + (keep + a[i] - x)
        keep = x - keep
    else:
        keep = a[i]

print(min(ans2, ans))
# Judge status: Accepted
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)

n = int(input())
print(num2alpha(n).lower())
# Judge status: Accepted
L = list(map(int, input().split()))
K = int(input())
print(sum(L) + max(L) * (2 ** K - 1))
# Judge status: Accepted


def solve():

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

    MAX = max(Llist)

    if MAX < sum(Llist)-MAX:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    solve()
# Judge status: Accepted
s = input()

if len(s) == 6 and s[2] == s[3] and s[4] == s[5]:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
s1 = input()
s2 = input()
print("YES") if s1 == s2[::-1] else print("No")
# Judge status: Accepted
x = int(input()); y = [3,5,7]
if x in y:
    print('YES')
else:
    print('NO')
# Judge status: Wrong Answer
n=int(input())

h=list(map(int,input().split()))

for i in range(n-2):
    if h[i+1]-h[i]>=2:
        print("No")
        break
else:
    print("Yes")
# Judge status: Accepted
#ABC118B
N,M=map(int,input().split())
food=[1]*(M+1)
for _ in range(N):
    q=list(map(int,input().split()))
    q=q[1:]
    for item in range(M+1):
        if item not in q:
            food[item]=0
print(sum(food))
# Judge status: Wrong Answer
n,m=map(int,input().split())

l=list(map(int,input().split()))

l.sort(reverse=True)
res=0

for i in range(n-1):

    while l[i] >= l[i+1] and m>0:
         
         l[i]= l[i] // 2
         m-=1
         l.sort(reverse=True)


print(sum(l))
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))

if N <= 2:
    print(1)
    exit()

d = []
for i in range(N-1):
    if A[i+1] - A[i] > 0:
        d.append(1)
    elif A[i+1] - A[i] < 0:
        d.append(-1)

flag = [True]*len(d)

ans = 1
for i in range(len(d)-1):
    if flag[i]:
        if d[i] == -d[i+1]:
            ans += 1
            flag[i+1] = False
print(ans)
# Judge status: Accepted
import numpy as np
a,b,k = map(int,input().split())
c = np.gcd(a,b)
print([i for i in range(1,c+1) if c%i==0][-k])
# Judge status: Accepted
#coding: utf-8
N = int(input())
A = [0] + list(map(int, input().split()))
B = [0 for _ in range(N+1)]
ans = []
for i in range(N, 0, -1):
    v = 0
    j = i
    while j <= N:
        v += B[j]
        j += i
    if A[i] != v % 2:
        ans.append(i)
        B[i] = 1

ans.sort()
print(len(ans))
if len(ans) != 0:
    print(*ans)
# Judge status: Accepted
s=input();print('YNeos'[not(s[2]==s[3] and s[4]==s[5])::2])
# Judge status: Wrong Answer
import bisect

n,m=map(int,input().split())
A=sorted(list(map(int,input().split())))
L=[]
for i in range(m):
    b,c=map(int,input().split())
    L.append((b,c))
L.sort(key=lambda x:x[1],reverse=True)
print(A)
print(L)
for i in range(m):
    idx=bisect.bisect_left(A,L[i][1])
    P=min(idx,L[i][0])
    for j in range(P):
        A[j]=L[i][1]
    A.sort()
print(sum(A))
# Judge status: Accepted
c = [input() for i in range(2)]

c0=[]
for i in range(3):
  c0.append(c[0][i])
c1=[]
for i in range(3):
  c1.append(c[1][i])
  
if c0[0]==c1[2] and c0[1]==c1[1] and c0[2]==c1[0]:
  print('YES')
else:
  print('NO')
# Judge status: Accepted
n = int(input())
p = list(map(int, input().split()))
i = 0
ans = 0
while i != n:
    if p[i] == i + 1:
        cnt = 0
        while i + cnt != n and p[i + cnt] == i + cnt + 1:
            cnt += 1
        ans += cnt//2 + cnt%2
        i += cnt
    else:
        i += 1
print(ans)
# Judge status: Accepted
a,b=map(int,input().split())
print(len([i for i in map(str, range(a, b+1)) if i==i[::-1]]))
# Judge status: Accepted
import math
a,b=map(int,input().split())
m=10**9+7
p=math.factorial(a)
q=math.factorial(b)
if abs(a-b)==0:print(2*p*q%m)
elif abs(a-b)==1:print(p*q%m)
else:print(0)
# Judge status: Wrong Answer
from collections import Counter
N = int(input())
S = [str(sorted(input())) for _ in range(N)]
count = 0
for i in Counter(S).values():
  count = i*(i-1)//2
print(count)
# Judge status: Wrong Answer
def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	t = dict()
	for i in a:
		if t.get(i):
			t[i] += 1
		else:
			t[i] = 1
	a, b = 0, 0
	for k in t:
		if t[k] >= 4:
				a = max(a, t[k])
				b = max(b, t[k])
		elif t[k] >= 2:
			if k > a:
				b = a
				a = k
	print(a*b)
resolve()
# Judge status: Wrong Answer
n = int(input())
flag = 0
for i in range(1, 10):
    for j in range(1, 10):
        if i*j == n:
            print('Yes')
            flag = 1

if flag == 0:
    print('No')
# Judge status: Accepted
a,b = map(int,input().split())
a_all = 0

for i in range(1,(b-a)):
    a_all+=i
    
print(a_all-a)
# Judge status: Accepted
print(["ABC","ABD"][len(input())>3])
# Judge status: Accepted
import math
a=int(input())/2
print(math.floor(a)*math.ceil(a))
# Judge status: Accepted
A, B, M = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
min_p = min(As)+min(Bs)
for i in range(M):
  a, b, m = map(int, input().split())
  min_p = min(As[a-1]+Bs[b-1]-m,  min_p)
print(min_p)
# Judge status: Accepted
n = int(input())
a = [int(input()) for _ in range(5)]

m = min(a)

t = (n-1) // m

print(t+5)
# Judge status: Wrong Answer
N,M = map(int,input().split())
A = list(map(int, input().split()))
S=0
for a in A:
   S+=a
   
if N-S>0:
    print(N-S)   
else:
    print(-1)
# Judge status: Accepted
s = int(input())
m = 10**9
x = (m-s%m)%m
y = (s+x)//m
print(0,0,10**9,1,x,y)
# Judge status: Accepted
X,N = map(int,input().split())
P = list(map(int,input().split()))
if P == []:
  print(X)
  exit()
for n in range(101):
  if X - n not in P:
    ans = X - n
    break
  if X + n not in P:
    ans = X + n
    break

print(ans)
# Judge status: Accepted
from fractions import gcd
a,b=map(int,input().split())
def lcm(a,b):
    return a*b // gcd(a,b)
print(lcm(a, b))
# Judge status: Accepted
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    ans = len(s)
    cnt = 0

    for char in s:
        if char == "S":
            cnt += 1
        else:
            if cnt > 0:
                cnt -= 1
                ans -= 2

    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
a,v=map(float,input().split())
b,w=map(float,input().split())
t=float(input())
b = max(a,b)
a = min(a,b)
gap = abs(b-a)
v_gap = abs(v-w)
if v>w: 
  if v_gap*t>=gap:
    print('YES')
  else:
    print('NO')
else:
  print('NO')
# Judge status: Accepted
import sys
input = sys.stdin.readline

mod = 10**9+7
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
a = a[::-1]
dp = [0] * (N+1)
dp[0] = 1
if a and a[-1] == 1:
    a.pop()
else:
    dp[1] = 1
for i in range(2, N+1):
    if a and a[-1] == i:
        a.pop()
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % mod
print(dp[-1])
# Judge status: Wrong Answer
#107_C
N,K=map(int,input().split())
X=list(map(int,input().split()))

#全探索
Ans=10**9
for i in range(N-K+1):
    XL,XR=X[i],X[i+K-1]
    if XL*XR>0:
        Ans=min(Ans,abs(XR-XL))
    else:
        Ans=min(Ans,abs(XR)*2+abs(XL),abs(XL)*2+abs(XR))
print(Ans)
# Judge status: Wrong Answer
a,b,c,d=map(int,input().split())

def abs__(x):
    if x <0:
        x = -1 * x
    return x
  
a_b = abs__(a-b)
b_c = abs__(b-c)
if a_b <= d and b_c <= d:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
a,b=map(int,input().split());print(b if a>=13 else (0 if a<=5 else b//2))
# Judge status: Accepted
import fractions
from functools import reduce
def main():
    n,x = map(int, input().split())
    X = list(map(int,input().split()))

    array = []
    for i in range(len(X)):
        array.append(abs(X[i]-x))
    gcd1 = reduce(lambda a,b: fractions.gcd(a,b), array)
    print(gcd1)


if __name__ == '__main__':
    main()
# Judge status: Accepted
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
sumA = sum(A)
counter = Counter(A)
Q = int(input())
for i in range(Q):
    B, C = map(int, input().split())
    sumA += (counter[B]*C-counter[B]*B)
    counter[C] += counter[B]
    counter[B] = 0
    print(sumA)
# Judge status: Accepted
N = int(input())
S = input()

tmp = 10 ** 9
cntB = S.count("#")
cnt = 0
for i, s in enumerate(S):
    if s == "#":
        tmp = min(tmp, cnt + N - i - (cntB - cnt))
        cnt += 1

print(min(cntB, tmp))
# Judge status: Wrong Answer
N, K = map(int,input().split())
Monsters = list(map(int,input().split()))
Monsters = sorted(Monsters)

for i in range(min(K,N)):
    Monsters[i]=0
print(sum(Monsters))
# Judge status: Accepted
h, n = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n)]
INF = 10**18

dp = [INF] * (h + 1)
dp[h] = 0
for i in range(n):
    a, b = info[i]
    for j in range(h + 1)[::-1]:
            dp[max(j - a, 0)] = min(dp[j] + b, dp[max(j - a, 0)])
print(dp[0])
# Judge status: Wrong Answer
n = sorted(list(input()),reverse=True)
m = sorted(list(input()),reverse=True)
if n<m:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
s = input()

ans = 10000000
for i in range(len(s) - 2):
    temp = abs(753 - int(s[i: i + 3]))
    ans = min(ans, temp)

print(ans)
# Judge status: Accepted
import math

n, W = map(int, input().split())
dp = [0]*(W+1)
for i in range(n):
    weight, cost = map(int, input().split())
    for weight_already in range(W-weight, -1, -1):
        dp[weight_already+weight] = max(dp[weight_already+weight], dp[weight_already]+cost)
ans = max(dp)
print(ans)
# Judge status: Wrong Answer
A,B,C,X = [int(input()) for i in range(4)]
X_original = X
n = 0

for i in range(int(A)+1):
    X = X_original
    X = X - i*500
    for j in range(int(B)+1):
        X = X - j*100
        for k in range(int(C)+1):
            if X-k*50 == 0:
                n += 1

print(n)
# Judge status: Accepted
def main():
    MOD = 10 ** 9 + 7

    N, K = map(int, input().split())

    ans = 0
    low = sum(range(K - 1))
    high = sum(range(N - K + 2, N + 1))
    for take in range(K, N + 2):
        low += take - 1
        high += N - (take - 1)
        ans = (ans + high - low + 1) % MOD
    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
# Judge status: Accepted
#C
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

t = [a,b,c,d,e]
t.sort()

if n % t[0] == 0:
    p = n // t[0]
else:
    p = n // t[0] + 1
    
print(4+p)
# Judge status: Wrong Answer
a, b = map(int, input().split())
ans = 0
for i in range(a, b+1):
    x = i % 100
    y = i // 1000
    if x == y:
        ans += 1
print(ans)
# Judge status: Accepted
#B
n = int(input())
cnt = 0
merge = 0
for _ in range(n):
    v = int(input())
    if v==0:
        merge = 0
    else:
        q,r = divmod(v,2)
        cnt += q
        cnt += (merge * r)
        merge = (1-merge)*r + (1-r)*merge
print(cnt)
# Judge status: Accepted
import sys

n = int(sys.stdin.buffer.readline())
z, w = [0]*n, [0]*n
for a, i in zip(sys.stdin.buffer.readlines(), range(n)):
    x, y = map(int, a.split())
    z[i] = x+y
    w[i] = x-y
print(max(abs(max(z)-min(z)), abs(max(w)-min(w))))
# Judge status: Accepted
def readInt():
    return int(input())
def readList():
    return list(map(int,input().split()))
def readMap():
	return map(int,input().split())
def readStr():
    return input()
inf=float('inf')
mod = 10**9+7
import math
def solve(s):
    return s+'s' if s[-1]!='s' else s+'es'


s=readStr()
print(solve(s))
# Judge status: Wrong Answer
o=input()
e=input()
for i in range(50):
	try:
		print(o[i]+e[i],end="")
	except:
		pass
# Judge status: Wrong Answer
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    K, A, B = map(int, readline().split())
    ans = 1
    if A+2>=B:
        ans += K
    else:
        if K<A+2:
            ans += K
        else:
            ans += A-1
            ans += ((K-A+1)//2)*(B-A)
            ans += (K-A+1)%2
    print(ans)




if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
a = [int(i) for i in input().split()]

a.sort()
a.reverse()
cnt = 0
for i in range(n):
    cnt += a[2*i+1]
print(cnt)
# Judge status: Accepted
n, k = map(int, input().split())
s = input()
a = 'A'
cnt = 0
for i in s:
  if a != i:
    a = i
    cnt += 1
print(n-max(1,cnt-2*k))
# Judge status: Accepted
n=input()

n1,n2=int(n[:2]),int(n[2:])
#if (n1>12 and n2>12) or (n1==0 and n2==0):
#   print("NA")
if (n1!=0 and n1<=12) and (n2!=0 and n2<=12):
    print("AMBIGUOUS")
elif n1!=0 and n1<=12:
    print("MMYY")
elif n2!=0 and n2<=12:
    print("YYMM")
else:
    print("NA")
# Judge status: Accepted
import sys
N = int(input())
l = []

def main(n):
  global l
  i = 1
  while True:
    tmp = i*(i+1)//2
    if tmp >= n:
      l.append(i)
      if n-i == 0:
        return l
      else:
        return main(n-i)
    i += 1
    
sys.setrecursionlimit(10000)
li = main(N)
for n in li:
  print(n)