peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
s = list(input())
k = int(input())

z = ord("z")
a = ord("a")
for i in range(len(s)-1):
    if s[i] == "a":
        continue
    if z - ord(s[i]) + 1 <= k:
        k -= z - ord(s[i]) + 1
        s[i] = "a"

if k > 0:
    k = k%26
    x = z - ord(s[-1]) +1
    if k >= x:
        k -= z - ord(s[-1]) + 1
        s[-1] = chr(a + k)
    else:
        s[-1] = chr(ord(s[-1])+k)
    
print("".join(s))
# Judge status: Accepted
n = int(input())
lst = [int(i) for i in input().split()]

ans = [0] * n
for i in range(n-1):
  number = lst[i]
  ans[number - 1] += 1

for i in ans:
  print(i)
# Judge status: Wrong Answer
i = 0
j = 0

w = ""
for s in input():
    j += 1

    if s == "R" and (w == s or w == ""):
        i += 1
    elif s == "R" and w != s:
        i += 1
    
    if s == "S" and i > 0 and j == 2:
        i -= 1

    w = s

print(i)
# Judge status: Accepted
N = int(input())
H = [int(x) for x in input().split()]
m = 0
count = 0
for i in range(N-1):
  if H[i] >= H[i+1]:
    count += 1
  else:
    count = 0
  if count > m:
    m = count
print(m)
# Judge status: Accepted
n,a,b = map(int, input().split())

if a%2==b%2:
    print((b-a)//2)
    exit()

print(min(a-1,n-b) +1+ (b-a-1)//2)
# Judge status: Accepted
import math
N, M = map(int, input().split())
from collections import*
c = Counter(map(int, input().split()))
for _ in range(M):
    B, C = map(int, input().split())
    c[C] = c[C] + B if C in c else B
c = sorted(c.items(), reverse=True)
s = 0
for i in c:
    s += i[0] * min(i[1],N)
    N -= min(i[1],N)
print(s)
# Judge status: Wrong Answer
import sys

print("Enter ID")
str_1 = input()
str_2 = input()

if not str_2.startswith(str_1,0):
    print("No")
    sys.exit()

if len(str_1) + 1 != len(str_2):
    print("No")
    sys.exit()

print("Yes")
# Judge status: Accepted
a,b=map(int,input().split())
ans=0
for i in range(a+1):
    for j in range(a+1):
        if 0<=(b-i-j)<=a:
                ans+=1
print(ans)
# Judge status: Wrong Answer
N = int(input())
s = {}
for _ in range(N):
  a = "".join(sorted(input()))
  if a not in s:
    s[a] = 0
  else: s[a] += 1

ans = 0
for v in s.values():
  ans += v
  if v > 1: ans += 1
print(ans)
# Judge status: Accepted
#Python Template

from sys import stdin, stdout

def main():
	a, b, c, d = [int(i) for i in stdin.readline().split()]
	ans = max(a*c, a*d, b*c, b*d)
	print(ans)

main()
# Judge status: Wrong Answer
N,P = map(int,input().split())
A = list(map(int,input().split()))
n0=0
n1=0
for i in range(N):
    if A[i]%2==0:
        n0 += 1
n1 = N-n0
if P==1 and n1==0:
    print(0)
elif P==0 and n0==0 and n1==1:
    print(0)
else:
    print(2**(n1-1)*2**n0)
# Judge status: Wrong Answer
import sys
import math
import bisect

def main():
    a, b, c = map(int, input().split())
    if 4 * a * b < (c - a - b) ** 2:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()
# Judge status: Accepted
#!/usr/bin/env python
import math

n = int(input())
m = math.log10(n)
if int(m) == m:
    print(10)
    exit()

ans = sum(map(int, list(str(n))))
print(ans)
# Judge status: Wrong Answer
a,b,c,d=map(int,input().split())
n=int(input())
if n == 1:
  print(min(a*4,b*2,c))
elif n%2 == 0:
  print(min(a*4*n,b*2*n,c*n,d*n//2))
else:
  print(min(a*4*n,b*2*n,c*n,d*n//2+min(a*4,b*2,c)))
# Judge status: Wrong Answer
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
if 2*L[0] > sum(L):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
N, x = map(int, input().split())
a_li = list(map(int, input().split()))
a_li.sort()
ans = 0
for a in a_li :
    if x >= a :
        ans += 1
        x -= a
    else :
        x = 0
        break
if x != 0 :
    ans -= 1
print(max(0, ans))
# Judge status: Wrong Answer
L = float(input())
a = round(((L / 3) * 10)) / 10
b = round(((L / 3) * 10)) / 10
c = round(((L / 3) * 10)) / 10
#a += round(L - (a + b + c))
L = round(L - (a+b+c),2)
a += L
print(float(a*b*c))
# Judge status: Accepted
from collections import defaultdict


def resolve():
    s = input()

    cnt = defaultdict(int)
    cnt[0] += 1
    tmp = 0
    for i, c in enumerate(s[::-1]):
        c = int(c)
        tmp = (tmp + c * pow(10, i, 2019)) % 2019
        cnt[tmp] += 1

    ans = sum(c * (c - 1) // 2 for c in cnt.values())
    print(ans)


resolve()
# Judge status: Wrong Answer
def f(n):
  return n%2

n=int(input())
L = list(map(int, input().split()))
x=0 if f(L[0])==1 or f(L[1])==1 or f(L[2])==1 else format(min(L), 'b')[::-1].find('1')-1;print(x)
# Judge status: Wrong Answer
import sys

def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

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

lcm = 1
for i in a:
    lcm = lcm * i // gcd (lcm,i)
for i in a:
    if (lcm/a)%2 == 0:
        print(0)
        sys.exit()
print((m+lcm//2)//lcm)
# Judge status: Wrong Answer
N = int(input())
A = int(input())
 
amari = N % 500
if amari <= A:
  print("YES")
else:
  print("NO")
# Judge status: Wrong Answer
import math

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

for i in range(len(A)):
    A[i] -= (i + 1)
# print(A)

_A = map(abs, A)
_A = list(A)

average = math.ceil(sum(_A) / len(_A))

for i in range(len(A)):
    A[i] = abs(A[i] - average)

sadness = sum(A)

print(sadness)
# Judge status: Accepted
import collections

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

values,counts = zip(*collections.Counter(A).most_common())
ans = 0

B = counts[K:]

for i in B:
    ans += i
print(ans)
# Judge status: Accepted
k,x = map(int,input().split())
li = list(range(x - (k-1),x + (k)))
print(*li)
# Judge status: Accepted
x = int(input()) - 1
s = x // 11
a = x % 11
print(s*2+2) if a > 5 else print(s*2+1)
# Judge status: Wrong Answer
n, k = map(int, input().split())
p = list(map(int, input().split()))

prev = sum(p[1:k])
ind = 0

for i in range(1, n - k + 1):
    nex = prev - p[i-1] + p[i+k-1]

    if prev < nex:
        prev = nex
        ind = i

total = 0
for i in range(ind, ind + k):
    total += (p[i] * 0.5 + 0.5)

print(total)
# Judge status: Accepted
#=input()
R=int(input())
#,=map(int,input().split())
#list(map(int,input().split()))

print(R*2*3.141592653589793238)
# Judge status: Accepted
x,y = map(int,input().split())
if (2*x - y) % 3 != 0 or (2*y-x) % 3 != 0 or 2 * min(x,y) < max(x,y):
    print(0)
    exit()

mod = 10**9 + 7
n = (x+y) // 3
a = (max(x,y)*2 - min(x,y)) // 3

fact = [1]
finv = [1]
for i in range(1, n+1):
    fact += [(fact[i-1] * i) % mod]
    finv += [pow(fact[i], mod-2, mod)]
print((fact[n]*finv[a]*finv[n-a]) % mod)
# Judge status: Wrong Answer
S = list(input())
T = list(set(S))
n = len(T)
m = len(S)
if m == 1:
  ans = 'YES'
elif n ==1:
  ans = 'NO'
elif n == 2:
  ans = 'NO'
else:
  a = S.count(T[0])
  b = S.count(T[1])
  c = S.count(T[2])
  A = [a,b,c]
  A.sort()
  if A[2]-A[1]-A[0]<=1:
    ans = 'YES'
  else:
    ans = 'NO'
print(ans)
# Judge status: Wrong Answer
N,M=map(int,input().split())
KA=[]
for i in range(N):
    KA.append(list(map(int,input().split())))
A=[]
for i in range(N):
    for j in range(1,len(KA[i])):
        A.append(KA[i][j])
a=0
for i in range(M):
    if A.count(i)==N:
        a+=1
print(a)
# Judge status: Wrong Answer
line = input()
X, Y = [int(n) for n in line.split()]

route_cost = []
for _ in range(X):
    line = input()
    key, cost = [int(n) for n in line.split()]
    route_cost.append([cost, key])
    
route_cost.sort(key=lambda x: x[0])
if route_cost[0][0] > Y:
    value = "TLE"
else:
    value = route_cost[0][1]

print(value)
# Judge status: Accepted
A,B,C = map(int,input().split())
m = [A,B,C]
m = sorted(m)
if (m[2]-m[0])%2 == (m[2]-m[1])%2:
  print(m[2]-(m[0]+m[1])//2)
else:
  print(m[2]-(m[0]+m[1])//2 + 1)
# Judge status: Wrong Answer
N,M=map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]

ans = "No"
for i in range(N-M+1):
  for j in range(N-M+1):
    t = True
    for k in range(M):
      if B[k] != A[i+k][j:j+M]:
        t = False
  if t:
    ans = "Yes"
print(ans)
# Judge status: Accepted
import itertools
import numpy as np

N, M, X = map(int, input().split())

items = np.array([list(map(int, input().split())) for _ in range(N)])

min_v = 10**18
for n in range(1, N+1):
  for c in itertools.combinations(range(N), n):
    tmp = np.sum(items[[c]], axis=0)
    c = tmp[0]
    a = tmp[1:]
    if M == np.count_nonzero(a >= X):
      min_v = min(min_v, c)
if min_v == 10**18:
  print(-1)
else:
  print(min_v)
# Judge status: Accepted
#!/usr/bin/env python3
N, M = map(int, input().split())
a = []
for i in range(M):
    b, c = map(int, input().split())
    a.append(b)
    a.append(c)

for i in range(N):
    print(a.count(i + 1))
# Judge status: Wrong Answer
C = input()
r = chr(ord(C))

print(r)
# Judge status: Accepted
c1 = list(input())
c2 = list(input())
c1.reverse()

if c1 == c2:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
# -*- coding: utf-8 -*-
import collections
N, K=map(int,input().split())
A=list(map(int,input().split()))
C=collections.Counter(A)
KEY=list(C.keys())
count=0
if len(KEY)>K:
    D=len(KEY)-K
    L=C.most_common()[::-1]
    for ii in range(D):
        count+=L[ii][1]

print(count)
# Judge status: Accepted
K,X = map(int,input().split())

if 500*K >=X:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n,m=map(int, input().split())
alist=[list(map(int, input().split())) for i in range(m)]
ans=-1
for i in range(999,-1,-1):
  if len(str(i))==n:
    x=True
    stri=str(i)
    for j in range(m):
      if stri[alist[j][0]-1]!=str(alist[j][1]):
        x=False
    if x:
      ans=i
print(ans)
# Judge status: Wrong Answer
n,k=map(int,input().split());result=0
for i in range(1,n+1):
  t=i
  count=0
  while t <= k:
    t*=2
    count+=1
  result+=1/n*(1/2)**count
print(result)
# Judge status: Accepted
from itertools import permutations
a2e = [int(input()) for i in range(5)]

perm = list(permutations(list(range(5))))

m = 643
t = 0

for i in perm:
    for j in range(5):
        t += a2e[i[j]]
        if t % 10 != 0 and j < 4:
            wait = 10 - (t % 10)
            t += wait
    if m > t:
        m = t
    t = 0
print(m)
# Judge status: Accepted
import bisect
N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))
count = 0
for i in range(N):
    b = B[i]
    cind = bisect.bisect_right(C,b)
    aind = bisect.bisect_left(A,b)
    count+=(N-cind)*aind
print(count)
# Judge status: Accepted
s = input()
stk = []
ret = 0
for i in range(len(s)):
    if len(stk) == 0:
        stk.append(s[i])
    elif stk[-1] == '0':
        if s[i] == '1':
            stk.pop(-1)
            ret += 2
        else:
            stk.append('0')
    else:
        if s[i] == '0':
            stk.pop(-1)
            ret += 2
        else:
            stk.append('1')

print(ret)
# Judge status: Wrong Answer
n = int(input())
cnt = 0
for i in range(30):
    for j in range(20):
        if n == 4 * i + 7 * j:
            print("Yes")
            break
else:
    print("No")
# Judge status: Accepted
n = int(input())
a_list = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    k = sum(a >> i & 1 for a in a_list)
    ans += (k * (n - k) % mod) * ((1 << i) % mod) % mod
print (ans % mod)
# Judge status: Accepted
N=int(input())

a=int(N*(N+1)/2)

print(a)
# Judge status: Wrong Answer
N=int(input());t=[0]+[N]*N
for i in range(2,N+1):
 x,a,b=t[i-1],6,9
 while a<=i:x=min(x,t[i-a],t[i-b]if b<=i else N);a*=6;b*=9
 t[i]=x+1
print(t[N])
# Judge status: Wrong Answer
import sys
input=lambda: sys.stdin.readline().rstrip()
n,m,x=map(int,input().split())
A=[[int(i) for i in input().split()] for _ in range(n)]
ans=float("inf")
for i in range(2**n):
  B=[0]*(m+1)
  for j in range(n):
    if i&(1<<j):
      for k in range(m+1):
        B[k]+=A[j][k]
  if min(B[1:])>=x:
    ans=min(ans,B[0])
print(ans)
# Judge status: Accepted
import copy
a = [int(input())]
t = []
i = 1


def f(n):
    if n % 2 == 0:
        return int(n / 2)
    else:
        return int(3 * n + 1)


while True:
    a.append(f(a[i - 1]))
    t = copy.copy(a)
    t = [j for j, x in enumerate(t, 1) if t.count(x) > 1]
    if 0 < len(t):
        print(t[1])
        break
    i += 1
# Judge status: Accepted
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    d = list(map(int, input().split()))
    d.sort()
    
    center_left = N//2 - 1
    center_right = N//2
    ans = d[center_right] - d[center_left]
    print(ans)
main()
# Judge status: Wrong Answer
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
s = sorted(a)
for j,k in enumerate(a):
    print(s[-2]) if j == n else print(s[-1])
# Judge status: Accepted
s = input()
a = [-1]
b = 0
for n in range(len(s)):
    if s[n] != "A" and s[n] != "C" and s[n] != "G" and s[n] != "T":
        a.append(n)
a.append(len(s))
for n in range(len(a)-1):
    b = max(b, a[n+1]-a[n]-1)
print(b)
# Judge status: Accepted
n = int(input())
b_l = list(map(int, input().split()))

a_l = [0] * n
a_l[0] = b_l[0]
a_l[-1] = b_l[-1]
for i in range(1, n-1):
    a_l[i] = min(b_l[i],b_l[i-1])
print(sum(a_l))
# Judge status: Wrong Answer
s = input()
ans = 1000000

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

print(ans)
# Judge status: Accepted
n=int(input())
print(int(n*(n-1)//2))
# Judge status: Wrong Answer
k, x = map(int, input().split())
ans = []

for i in range((k//2) + 2):
  a = x + i
  ans.append(a)
  b = x - i
  ans.append(b)

ans = sorted(set(ans))
ans = map(str, ans)
print(' '.join(ans))
# Judge status: Wrong Answer
from typing import List

def step(n: int, a: List[int])-> int:
  result = 0
  dai = 0
  for i in range(1,n):
    sub = a[i-1] + dai - a[i]
    print(sub)
    if sub > 0:
      dai = sub      
      result += sub
      continue
    dai = 0
  return result

if __name__ == "__main__":
  n = int(input())
  a = list(map(int, input().split()))
  print(step(n, a))
# Judge status: Wrong Answer
import math
[x,y] = [int(i) for i in input().split()]
div = y / x
ls = []
for i in range(100):
  ls.append(2 ** i)
if int(div) in ls:
  print(math.ceil(math.log(div,2))+1)
else:
  print(math.ceil(math.log(div,2)))
# Judge status: Accepted
import math

a,b,x = [int(i) for i in input().split(" ")]

S = a**2*b

# 満タンの場合
if S==x:
    theta = math.pi/2

# 半分以下の場合（水平に近い状態でこぼれる）
elif S/2 < x:
    theta = math.atan(a**3/(2*(S-x)))

# 半分以上の場合（垂直に近い状態でこぼれる）
else:
    theta = math.atan(2*x/(a*b**2))    
    
print(90-math.degrees(theta))
# Judge status: Accepted
N,K=map(int,input().split())
x=list(map(int,input().split()))
al=[]
for i in range(N-K+1):
  if x[i]*x[i+K-1]<0:
    al.append(max(abs(x[i]),abs(x[i+K-1]))+2*min(abs(x[i]),abs(x[i+K-1])))
  elif x[i]>=0:
    al.append(x[i+K-1])
  else:
    al.append(abs(x[i]))
print(min(al))
# Judge status: Accepted
import sys


def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return list(map(int, input().split()))


def main():
    f = input_ints()
    print(f[0] * f[1])


main()
# Judge status: Accepted
S = input()
N = len(S)
a = [0] * (N + 1)
for i in range(N):
    if S[i] == '<':
        a[i + 1] = a[i] + 1
for i in range(N - 1, -1, -1):
    if S[i] == '>' and a[i] <= a[i+1]:
        a[i] = a[i+1] + 1
print(sum(a))
# Judge status: Accepted
import collections
a = int(input())
ar = list(map(int,input().split(" ")))
br = collections.Counter(ar)
cr = []
for k,v in br.items():
    if v >= 4:
        cr.append(k)
        cr.append(k)
    elif v >= 2:
        cr.append(k)
cr = sorted(cr,reverse=True)
if len(cr) < 2:
    print(0)
else:
    print(cr[0] * cr[1])
# Judge status: Accepted
def actual(A, B, C):
    if (A, B, C) in [(5, 5, 7), (5, 7, 5), (7, 5, 5)]:
        return 'YES'

    return 'NO'

A, B, C = map(int, input().split())  
print(actual(A, B, C))
# Judge status: Accepted
n, m, q = map(int, input().split())

t = []
for _ in range(q):
   a, b, c, d = map(int, input().split())
   t.append([a-1, b-1, c, d])

#t = sorted(t, key=lambda x:x[1])

tmp = [i for i in range(1, m+1)]

from itertools import combinations_with_replacement

ans = 0
for v in combinations_with_replacement(tmp, n):
   A = list(v)
   score = 0
   for i in range(q):
      a, b, c, d = t[i]
      if A[b] - A[a] == c:
         score += d
   ans = max(ans, score)

print(ans)
# Judge status: Wrong Answer
if 'hi' in input():
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
n = int(input())
l = list(map(int,input().split()))
l.sort()
a = l[0]
for i in range(1,n):
    if l[i]%a != 0:
        a = l[i]%a
        if a == 1:
            print(1)
            exit()
print(a)
# Judge status: Accepted
import sys
sys.setrecursionlimit(10000000)
 
N = int(input())
H = list(list(map(int,input().split())) for _ in range(N))
#sub problem: max cost from 0 to ith day
memo = {}
def rec(i, choice):
  if (i, choice) in memo:
    return memo[(i, choice)]
  if i == len(H):
    return 0
  m = max(H[i][j] + rec(i+1,j) for j in range(3) if j != choice)
  memo[(i, choice)] = m
  return m
print(max(rec(0, j) for j in range(3)))
# Judge status: Accepted
int = int(input())
print((1000 - int % 1000) % 1000)
# Judge status: Accepted
n, k = map(int,input().split())
A = list(map(int,input().split()))
A = [a-1 for a in A]

path = []
passed = set([])
p = 0
while 1:
  if k ==0:
    print(p+1)
    exit()
  if p not in passed:
    path.append(p)
    passed.add(p)
    p = A[p]
    k -= 1
  else:
    break
path = path[path.index(p):]
term = len(path)
k %= term
print(path[k]+1)
# Judge status: Accepted
N=int(input())

answer=0
for i in range(1,N):
  answer+=(N-1)//i
print(answer)
# Judge status: Accepted
S = input()

cnt = 0

if S.count('R') == 0:
    cnt = 0
elif S.count('R') == 1:
    cnt = 1
elif S.count('R') == 3:
    cnt = 3
else :
    if S[1] == 'R':
        cnt = 2
    else :
        cnt = 1
        
print(cnt)
# Judge status: Accepted
a,b,c,k=map(int,input().split())
if k<=a:
  ans=k
elif k>a and k<=a+b:
  ans=a
else:
  ans=a-(k-(a+b))
print(ans)
# Judge status: Wrong Answer
import math
N = int(input())

keta = int(math.log10(N)+1)
count = 0
for i in range(1,keta+1):
    if i % 2 == 1:
        if i == 1:
            count += 9
        elif i != keta:
            count += int('8'+'9'*(i-1)) + 1
        else:
            count += N - 10 ** (keta-1) + 1
print(count)
# Judge status: Accepted
N, K = map(int, input().split())
A = list(map(int, input().split()))
visited = [False]*N
path = [0]
at = 0
loop = 0
visited[0]=True
for i in range(N):
    at = A[at]-1
    if visited[at]:
        loop = i+1-path.index(at)
        break
    else:
        visited[at]=True
        path.append(at)
if K < len(path):
    print(path[K]+1)
else:
    print(path[(K-path.index(at))%loop+path.index(at)]+1)
# Judge status: Accepted
N = int(input())
A = input()
B = input()

for i in range(N):
  if A[i:] == B[0:N-i]:
    print(N+i)
    exit(0)
    
print(N*2)
# Judge status: Accepted
n,k=map(int,input().split())
s=sorted([[int(i) for i in input().split()] for l in range(n)])
c=0
for x in s:
    c+=x[1]
    if c>=k:
        print(x[0])
        break
# Judge status: Accepted
N=int(input())
s=[input() for _ in range(N)]
M=int(input())
t=[input() for _ in range(M)]
l=list(set(s))
List=[s.count(l[i])-t.count(l[i]) for i in range(len(l))]
print(max(0,max(List)))
# Judge status: Accepted
N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)
index = N//2
for i in range(N):
    if X[i] < Y[index]:
        print(Y[index])
    else:
        print(Y[index-1])
# Judge status: Accepted
a,b = map(int,input().split())
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(a, b))
# Judge status: Accepted
import sys
MOD = 998244353


def main():
    n, *d = map(int, sys.stdin.buffer.read().split())
    e = [0]*n
    for i in d:
        e[i] += 1
    ans = e[0]
    for i in d[1:]:
        ans = ans*e[i-1] % MOD
    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Accepted
#import time
#t1 = time.time()
h,n = map(int,input().split())
ab = [[int(i) for i in input().split()] for j in range(n)]

dp = [[10**18 for i in range(h+1)] for j in range(n)]

for i in range(n):
    dp[i][0] = 0
    
for i in range(1,h+1):
    dp[0][i] = ((i+ab[0][0]-1) // ab[0][0]) * ab[0][1]

for i in range(1,n):
    for j in range(1,h+1):
        dp[i][j] = min(dp[i-1][j],dp[i][max(0,j-ab[i][0])]+ab[i][1])

print(dp[n-1][h])
# Judge status: Wrong Answer
n, m = map(int, input().split())
mizu = [1]*n
iro = [1] + [0]*(n-1)
for i in range(m):
    x, y = list(map(lambda x: x-1, map(int, input().split())))
    iro[y] += (iro[y]+iro[x])/(mizu[y]+1)
    mizu[x]-=1; mizu[y]+=1
    if mizu[x]==0:
        iro[x] = 0
print(sum(map(lambda x: int(bool(x)), iro)))
# Judge status: Accepted
X, Y = map(int, input().split())

ans = 0
ai = X
while ai <= Y:
    ai = 2 * ai
    ans += 1
print(ans)
# Judge status: Accepted
from collections import Counter
n = int(input())
l = list(Counter(input()) for i in range(n))
k =[]
m = 50
for i in l[0]:
  for t in l:
    m = min(m,t[i])
  k.append(i*m)
  m = 50
k.sort()
print("".join(k))
# Judge status: Accepted
N = int(input())
if N < 1000:
    print('ABC')
else:
    print('ABD')
# Judge status: Accepted
N, W = map(int, input().split())
w, v = [0], [0]
for i in range(N):
    w_i, v_i = map(int, input().split())
    w.append(w_i)
    v.append(v_i)
DP = [[0 for c in range(W+1)] for i in range(N+1)]
for i in range(1, N+1):
    for c in range(1, W+1):
        if c - w[i] < 0:
            DP[i][c] = DP[i-1][c]
        else:
            DP[i][c] = max(DP[i-1][c], DP[i-1][c-w[i]] + v[i])
print(DP[N][W])
# Judge status: Accepted
# A - Weather Prediction
w=['Sunny','Cloudy','Rainy']
s=input()

if s==w[0]:
    print(w[1])
elif s==w[1]:
    print(w[2])
else:
    print(w[0])
# Judge status: Wrong Answer
def solve():
  N = int(input())
  AA = list(map(int,input().split()))
 
  ans = 0
  for a in AA:
    ans += a
  ans = ans % (10**9+7)
  ans = ans**2
  for a in AA:
    ans -= a**2
  ans = ans % (10**9+7)
  while ans<0:
    ans += 10**9+7
  print(int(ans/2))
solve()
# Judge status: Wrong Answer
from collections import Counter
n = int(input())
s = input()
ans = float('inf')
e = int(s.count('E'))

for i in range(n):
    a = (s[:i]).count('W')
    b = e - (i-a)

    ans = min(ans, a + b)

print(ans)
# Judge status: Wrong Answer
N = int(input())
X = round(N / 1.08)

#再計算
if (X * 1.08) // 1 == N:
    print(X)
else:
    print(":(")
# Judge status: Wrong Answer
n=int(input())
k=int(input())
x=int(input())
y=int(input())
if n>k:
  print(x*k+y*(n-k))
else:
  print(x*k)
# Judge status: Wrong Answer
A, B, C, D = map(int, input().split())
if A-B <= 0:
    print("No")
elif D-C <= 0:
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer
S = input()
if S[0] == S[1] and S[1]== S[2]:
    print("no")
else:
    print("yes")
# Judge status: Accepted
n, x, y = map(int, input().split())

count = {k:0 for k in range(1, n)}
for i in range(1, n+1):
    for j in range(1, i):
        k = min(abs(i-j), abs(x-i) + 1 + abs(j-y),abs(y-i) + 1 + abs(x-j))
        count[k] += 1
for i in count.values():
    print(i)
# Judge status: Accepted
N = int(input())
X=list(map(int, input().split()))

sorted_X=sorted(X)
med1=sorted_X[N//2-1]
med2=sorted_X[N//2]
#print(med1, med2)
for i in range(N):
    if X[i]<=med1:
        print(med2)
    elif X[i]>=med2:
        print(med1)
# Judge status: Accepted
# https://atcoder.jp/contests/abc143/tasks/abc143_d
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
L = [int(i) for i in input().split()]
L.sort()
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        a, b = L[i], L[j]
        ans += bisect_left(L, a + b) - 1 - j
print(ans)
# Judge status: Accepted
l = input()
m = l.split(" ")
n = int(m[0])
k = int(m[1])
if n > k:
  n = n % k
if n < (k-n):
    print(n)
else:
    print(k-n)
# Judge status: Accepted
import sys
import math

n = int(input())
a = list(map(int, input().split()))
flg = 0
b = []
for i in range(n):
    if a[i] % 2 == 0:
        b.append(a[i])
for i in range(len(b)):
    if b[i] <= 2:
        flg = 1
    elif b[i] % 3 != 0 and b[i] % 5 != 0:
        flg = 1
if flg == 0:
    print("APPROVED")
else:
    print("DENIED")