peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
h1, m1, h2, m2, k = [int(i) for i in input().split()]

time = 60*h2+m2 - 60*h1+m1 - k
if time > 0:
  print(time)
else:
  print(0)
# Judge status: Accepted
a, b = map(int, input().split())
if (a*b)%2:
    print("Odd")
else:
    print("Even")
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
 
if n % 2 == 0:
    for i in reversed(range(1, n, 2)):
        print(a[i],end=" ")
    for i in range(0,n-1,2):
        print(a[i],end=" ")
elif n % 2 == 1:
    for i in reversed(range(0, n, 2)):
        print(a[i],end=" ")
    for i in range(1, n, 2):
        print(a[i],end=" ")
# Judge status: Accepted
n = int(input())
a = [int(i) for i in input().split()]
count1 =0
count2 = 0
for i in a:
    if i%2==0:
        count1+=1
        if i%3==0 or i%5 == 0:
            count2+=1
    else:
        pass
if count1 == count2:
    print('APPROVED')
else:
    print("DENIED")
# Judge status: Accepted
def coder(a,b):
    if a + b < 24:
        return a + b
    else:
        return ((a + b) % 24)

def main():
    a , b = map(int, input().split())
    print(coder(a , b))

if __name__ == '__main__':
    main()
# Judge status: Accepted
a, b, c = map(int, input().split())
k = int(input())

ans = 0

while a >= b:
  ans += 1
  b *= 2

while b >= c:
  ans += 1
  c *= 2

print("Yes" if ans <= k else "No")
# Judge status: Wrong Answer
s=input()
flg=False

for i in range(len(s)):
  if i%2==0 and s[i]=='R':
    flg=True
  if i%2==1 and s[i]=='L':
    flg=True
if flg:
  print('No')
else:
  print('Yes')
# Judge status: Accepted
n = int(input())
A = list(map(int, input().split( )))
cnt = 0
for i in range(n):
  if A[i] != i+1:
    cnt += 1
if cnt <= 2:
  print('YES')
else:
  print('NO')
# Judge status: Accepted
test1, test2 = input().split()

ans = test2 + test1

print(ans)
# Judge status: Accepted
X,Y=map(int,input().split())
ans=0
while X<=Y:
    X*=2
    ans+=1
print(ans)
# Judge status: Accepted

import collections
from functools import lru_cache
import bisect

INF = float("inf")
ZERO = 0
ONE = 1


def read():
    return input().strip()


def readInt():
    return int(input().strip())


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


def solve(N, arr):
    ans = 0
    MOD = 10**9 + 7
    totalSum = sum(arr) % MOD
    currSum = 0

    for num in arr:
        currSum += num
        ans = (ans + num * (totalSum - currSum)) % MOD

    return ans % MOD


N = readInt()
arr = readList()

print(solve(N, arr))
# Judge status: Wrong Answer
N,K=map(int,input().split())
A=list(map(int,input().split()))
M=K-1
if N%M==0:
    print(N//M)
else:
    print(N//M+1)
# Judge status: Accepted
import sys
x,y=list(map(int, input().split()))

for i in range(0,101):
  for j in range(0,101):
    if i+j==x and i*4+j*2==y:
      print("Yes")
      sys.exit()
      
print("No")
# Judge status: Accepted
N = int(input())
C = [0] * (N-1)
S = [0] * (N-1)
F = [0] * (N-1)
for i in range(N-1):
    C[i], S[i], F[i] = map(int,input().split())

for i in range(N):
    t = 0
    for j in range(i,N - 1):
        if t < S[j]:
            t = S[j]
        elif t % F[j] == 0:
            pass
        else:
            t = t + F[j] - (t % F[j])
        t += C[j]
    print(t)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
b = sorted(enumerate(a), key=lambda x:x[1])
c = [b[i][0]+1 for i in range(n)]
d = [str(x) for x in c]
e = " ".join(d)
print(e)
# Judge status: Accepted
from fractions import gcd
a, b = map(int,input().split())

GCD = gcd(a,b)
ans = 1
for i in range(2, int(GCD ** 0.5) + 1):
    if GCD%i == 0:ans += 1
    while GCD%i == 0:
        GCD //= i
if GCD != 1:ans += 1
print(ans)
# Judge status: Accepted
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    n = int(input())
    p = list(map(int, input().split()))
    count = 0
    for i in range(n - 2):
        if (p[i] < p[i + 1] and p[i + 1] < p[i + 2]) or (p[i] > p[i + 1] and p[i + 1] > p[i + 2]):
            count += 1

    print(count)


if __name__ == '__main__':
    solve()
# Judge status: Wrong Answer
N, K = [int(i) for i in input().split()]

n = N
c = True
while(c):
    if n > K:
        # n - abs(n - K) => n - (n - K) => K > 0
        n = n - int(n / K) * K
    elif n < K:
        # n - abs(n - K) => n - (K - n) => 2n - K
        if 2 * n - K > 0:
            n = K - n
        else:
            c = False
    else:
        # n == K で n - abs(n - K) => n（変更後も同じ）
        c = False
print(n)
# Judge status: Wrong Answer
l,r=map(int,input().split())
if r-l>2019:
    print(0)
    exit()

ans=int(10000000)
for i in range(l,r):
    for j in range(i+1,r+1):
        if ans>i*j:
            ans=i*j

print(ans)
# Judge status: Accepted
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    A=LIST()
    ans=0
    mina=0
    for a in A:
        mina=max(mina,a)
        ans+=max(0,mina-a)
    
    print(ans)
    
if __name__ == '__main__':
    do()
# Judge status: Accepted
import math
def lcm(x,y):
    return x*y//math.gcd(x,y)
    

N = int(input())
T = int(input())
for i in range(1,N):
    S = int(input())
    T = lcm(S,T)
print(T)
# Judge status: Accepted
tax_a, tax_b = map(int, input().split())
ans = tax_b * 10

for i in range(9):
    if int(ans * 0.08) == tax_a:
        print(ans)
        break
    else:
        ans += 1
else:
    print('-1')
# Judge status: Accepted
d = []
for i in range(int(input())):
    s, p = input().split()
    d += (i + 1, s, int(p)),
d.sort(key = lambda l: (l[1], -l[2]))
for i, _, __ in d:print(i)
# Judge status: Accepted
n = int(input())
a = []
for i in range(2):
    a.append(list(map(int, input().split())))

# print(a)
ans = 0
for i in range(1, n+1):
    total = sum(a[0][:i])+sum(a[1][i-1:])
    if total > ans:
        ans = total

print(ans)
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    Aone = A - 1
    lcm = int(C / fractions.gcd(C, D) * D)

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / lcm)
    Bdec = Bc + Bd - Blcm

#    print(Bc,Bd,Blcm)

    Ac = int(Aone / C)
    Ad = int(Aone / D)
    Alcm = int(Aone / lcm)
    Adec = Ac + Ad - Alcm

#    print(Ac,Ad,Alcm)

    print(B - A + 1 - (Bdec - Adec))


main()
# Judge status: Wrong Answer
def golden_apple(n, d):

    ans = -(-n//(d*2))

    return ans

def main():
    n, d = map(int, input().split())
    print(golden_apple(n, d))

if __name__ == '__main__':
    main()
# Judge status: Accepted
n, k = map(int, input().split())
c = 0
while n != 0:
    n //= k
    c += 1
print(c)
# Judge status: Accepted
k,a,b = map(int,input().split())


if b-a <= 1 or k <= a:
    print(k+1)
else:
    print(((k-(a+1))//2)*(b-a)+b+((k-(a+1))%2))
# Judge status: Accepted
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
a = LI()
ans = 0
for i, A in enumerate(a):
    if (i+1) % 2 == 1:
        if A % 2 == 1:
            ans += 1
print(ans)
# Judge status: Wrong Answer
import sys
N = int(input())
s = input()
t = input()
ans = s+t
for i in range(N):
  if s[i:N] == t[0:N-i]:
    ans = s[0:i]+s[i:N]+t[N-i:N]

print(len(ans))
# Judge status: Wrong Answer
P,Q,R = map(int, input().split())
A = [P+Q, P+R, Q+R]
print(A)
# Judge status: Accepted
N, M = map(int,input().split())
H = list(map(int,input().split()))
A, B = [], []
for _ in range(M):
  a, b = map(int,input().split())
  A.append(a)
  B.append(b)

L = [1] * N

for i in range(M):
  ai = A[i] - 1
  bi = B[i] - 1
  if H[ai] > H[bi]:
    L[bi] = 0
  elif H[bi] > H[ai]:
    L[ai] = 0
  else:
    L[ai], L[bi] = 0, 0

print(L.count(1))
# Judge status: Accepted
N, M = [int(x) for x in input().split()]
def sol(N,M):
  if N==0 or M==0:
      return 0
  elif N==1 or M==1:
    return abs(abs(N-M)-1)
  x = (abs(3-N)+1)*(M-2)
  y = (abs(3-M)+1)*abs((N-2))
  return min(x,y)

print(sol(N,M))
# Judge status: Accepted
s = input().strip()
n = len(s)

acum = [0] * (n + 1)
acgt = ['A', 'C', 'G', 'T']

for i in range(1, n + 1):
    if s[i - 1] in acgt:
        acum[i] = acum[i - 1] + 1
    else:
        acum[0] = 0

print(max(acum))
# Judge status: Accepted
import heapq
n , m = map(int, input().split())
ab=[[] for i in range(10**5)]

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

que=[]
ans = 0
for i in range(m):
    for b in ab[i]:
        heapq.heappush(que,b)
    if que:
        ans+=heapq.heappop(que)
print(ans*(-1))
# Judge status: Accepted
N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))

from itertools import permutations
from math import factorial

X=[i+1 for i in range(N)]
X_list = list(permutations(X))

P=tuple(P)
Q=tuple(Q)

ans=[0,0]
for j in range(factorial(N)):
    if X_list[j]==P:
        ans[0] = j
        break
for k in range(factorial(N)):
    if X_list[k]==Q:
        ans[1] = k
        break
print(abs(ans[0]-ans[1]))
# Judge status: Accepted
x,y = map(int,input().split())
ans = 0
while x<=y:
  x *= 2
  ans += 1
print(ans)
# Judge status: Accepted
A = input()
B = input()

if A[0] == B[2] and A[1] == B[1] and A[2] == B[0]:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
from sys import stdin

s = int(stdin.readline().strip())
mem = []
a = s

for i in range(1000000):
  if a in mem:
    print(i+1)
    exit()
  mem.append(a)
  if a % 2 == 0: a = a // 2
  else: a = 3 * a + 1
# Judge status: Accepted
n = int(input())
A = list(map(int, input().split()))


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


# 初期値の設定
ans = A[0]
for i in range(1, n):
    ans = gcd(ans, A[i])
print(ans)
# Judge status: Accepted
s=str(input())
l=[s[0],s[1],s[2],s[3]]
l.sort()
if l[0]==l[1] and l[2]==l[3] and l[0]!=l[2]:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
a, b, c = list(map(int, input().split(' ')))

if a % 2 == 0 and a == b == c:
    print(-1)
else:
    count = 0
    while True:
        if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
            print(count)
            break
        a, b, c, = (b + c) // 2, (c + a) // 2, (a + b) // 2
        count += 1
# Judge status: Wrong Answer
N = int(input())
pts = [(list(map(int,input().split()))) for _ in range(0,N)]

from itertools import combinations
def f(x1,y1,x2,y2):
    dx = x2 - x1
    dy = y2 - y1
    return (dx**2+dy**2)**0.5
dst = 0
for i,j in combinations(range(0,N),2):
    dst += f(pts[i][0], pts[i][1], pts[j][0], pts[j][1])
print(dst / (N // 2))
# Judge status: Wrong Answer
s = int(input())
print((s//500)*1000 +  ((s%500)%5)*5 )
# Judge status: Wrong Answer
K, S = map(int, input().split())
res = 0
for x in range(K + 1):
    for y in range(K + 1):
        z = S- x + y
        if z>=0 and z<=K:
            res += 1
print(res)
# Judge status: Wrong Answer
MOD=10**9+7
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
if 1 in a and 2 in a:
  print(0)
  exit()
elif 1 in a:
  ans=[0,1]
elif 2 in a:
  ans=[1,0]
else:
  ans=[1,2]

for i in range(2,n):
  if i+1 in a:
    ans.append(0)
  else:
    s=(ans[-1]+ans[-2])%MOD
    ans.append(s)
print(ans[-1]%MOD)
# Judge status: Wrong Answer
s = input()
dif = True
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        dif = False
print("yes" if dif else "no")
# Judge status: Accepted
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n,k = na()
h = na()

A = [0]+[float("inf")]*(n-1)

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

print(A[-1])
# Judge status: Accepted
import sys

def stdin_parse_int():
    a = list(map(int,input().split()))
    return a

list = stdin_parse_int()
A = list[0]
B = list[1]
K = list[2]

if A > K:
    print(str(A-K) + " " + str(B))
elif A+B > K:
    print(str(0) + " " + str(A+B-K))
else:
    print("0 0")
# Judge status: Wrong Answer
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
import bisect
for i in range(M):
    B,C=map(int,input().split())
    p=bisect.bisect_right(A,C)
    for k in range(min(B,p-1)):
            A[k]=C
    A.sort()
    
print(sum(A))
# Judge status: Accepted
k,x=map(int,input().split())
s=""
for i in range(-k+1,k):
    s+=str(x+i)+' '
print(s)
# Judge status: Wrong Answer
x = int(input())
s = input()
li = []
c = 0
for i in range(x):
    if s[i] == "I":
        c += 1
        li.append(c)
    else:
        c -= 1
        li.append(c)
print(max(li))
# Judge status: Accepted
N = int(input())

for i in range(7):
    if 2**i <= N:
        s = i
        
print(2**s)
# Judge status: Wrong Answer
n,a,b = map(int,input().split())
ans = 0
for i in range(n):
  if a<=sum(map(int,list(str(i))))<=b:
    ans += i
print(ans)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

import math

count_1up = 0
count_2up = 0

for a, b in zip(A, B):
    if a - b >= 0:
        count_1up += a - b
    else:
        count_2up += math.ceil((b - a) / 2)

diff = sum(B) - sum(A)

# print(diff, count_1up, count_2up)
if diff < 0:
    print("No")
elif diff < count_1up or diff < count_2up:
    print("No")
else:
    print("Yes")
# 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()))
count=sum(B)
print(count)
for i in range(N-1):
    if A[i]+1==A[i+1]:
        count=count+C[A[i]-1]
print(count)
# Judge status: Wrong Answer
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: Accepted
def resolve():
  s = sorted(input())

  if s[0] == 'a' and s[1] == 'b' and s[2] == 'c':
    print('Yes')
  else:
    print('No')
  return

if __name__ == "__main__":
  resolve()
# Judge status: Accepted
S = input()
ok = 1
for i in range(len(S)):
    if i % 2 == 1 and S[i] not in ['L', 'U', 'D']:
        ok = 0
    if i % 2 == 0 and S[i] not in ['R', 'U', 'D']:
        ok = 0
print('Yes' if ok else 'No')
# Judge status: Accepted
N = int(input())

AC=0
WA=0
TLE=0
RE=0

for i in range(N):
    S = input()
    if S == "AC":
        AC+=1
    elif S == "WA":
        WA+=1
    elif S == "TLE":
        TLE +=1
    else:
        RE +=1

print("AC x "+str(AC))
print("WA x "+str(WA))
print("TLE x "+str(TLE))
print("RE x "+str(RE))
# Judge status: Accepted
from statistics import mean
import math
n = int(input())
citizen = list(map(int,input().split()))
hostF = math.floor(mean(citizen))
hostC = math.ceil(mean(citizen))
ansF = 0
ansC = 0
for i in citizen:
    ansF += (hostF-i)**2
    ansC += (hostC-i)**2
ans = ansF if ansF<ansC else ansC
print(int(ans))
# Judge status: Accepted
h,n=map(int,input().split())
x=[int(i) for i in input().split()]

y=sorted(x,reverse=True)

print(sum(y[n:]))
# Judge status: Accepted
import sys
K = int(input())
S = input()

if(len(S)<=K):
    print(S)
else:
    print(S[:K]+"...")
# Judge status: Accepted
import bisect
from collections import deque
N = int(input())
A = [int(input()) for _ in range(N)]
c = deque()
c.append(A[0])
for i in range(1, N):
    j = bisect.bisect_right(c, A[i]-1)
    if j == 0:
        c.appendleft(A[i])
    else:
        c[j-1] = A[i]
print(len(c))
# Judge status: Accepted
h,n = map(int,input().split())

ab = [list(map(int,input().split())) for i in range(n)]
ma = max(a for a,b in ab)


dp = [10**10]*(h+ma+1)
dp[0] = 0

for i in range(1,h+ma+1):
    dp[i] = min(dp[i-a]+b for a,b in ab)

print(min(dp[h:]))
# Judge status: Accepted
K = int(input())
A, B = map(int, input().split())

for c in range(A, B + 1):
    if c % K == 0:
        print("OK")
        break
else:
    print("NG")
# Judge status: Accepted
# import math
N = int(input())

# Nが奇数の場合は-2していくと全て奇数になるので答えは0
# Nが偶数の場合を検討するべし
# Nが偶数の場合、明らかに2の倍数より5の倍数の方が少ないので5の倍数がいくつかで考える
if (N % 2 == 1):
    print(0)
    exit()

bunbo = 0
sum_5 = 0
while (10 * 5 ** bunbo) <= N:
    sum_5 += N // (10 * 5**bunbo)
    bunbo += 1

print(sum_5)
# Judge status: Wrong Answer
n = int(input()) % 10
if n == 3:
	print("bon")
elif n == 0 or 1 or 6 or 8:
	print("pon")
else:
	print("hon")
# Judge status: Accepted
input_line = input().split(" ")
N=int(input_line[0])
M=int(input_line[1])
count=0

input_line = input().split(" ")
total=0
for i in range(len(input_line)):
    total=total+int(input_line[i])

border=total/(4*int(M))

for i in range(len(input_line)):
    if int(input_line[i])>=border:
        count=count+1
    

if count>=M:
    print("Yes")
else:
    print("No")

# input_line=' '.join(input_line)
# Judge status: Accepted
N,M = map(int,input().split())
ans = 0
dic = {str(i):0 for i in range(1,N)}
for _ in range(M):
    a,b = map(int,input().split())
    if a == 1:
        dic[str(b)] += 1
        if dic[str(b)] == 2:
            ans = 1
    if b == N:
        dic[str(a)] += 1
        if dic[str(a)] == 2:
            ans = 1
if ans == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')
# Judge status: Accepted
x = int(input())

for i in range(x+1):
    if (i*(i+1)) / 2 >= x:
        print(i)
        quit()
# Judge status: Accepted
from itertools import permutations

n = int(input())
a = [i+1 for i in range(n)]
a = permutations(a)
p = list(map(int, input().split()))
q = list(map(int, input().split()))

dict_order = sorted(a)
pi = dict_order.index(tuple(p))
qi = dict_order.index(tuple(q))

print(abs(pi - qi))
# Judge status: Wrong Answer
C = input()
A = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

for i in range(24):
    if A[i] == C:
        print(A[i+1])
# Judge status: Accepted
A,B,H,M=map(int,input().split())

import math  #三角関数・円周率
import numpy

H = H + M / 60
H_A = H / 12 * 360 * math.pi /180
M_A = M / 60 * 360 * math.pi / 180
H_x = math.cos(H_A) * A  #針の先端の座標計算（中心基準）
H_y = math.sin(H_A) * A
M_x = math.cos(M_A) * B
M_y = math.sin(M_A) * B

a = numpy.array([H_x, H_y])
b = numpy.array([M_x, M_y])
u = b - a
print(numpy.linalg.norm(u))
# Judge status: Wrong Answer
s = int(input())

x = s % 10 ** 9 * -1 
y = s // (10 ** 9)  
 
print(0, 0, 10 ** 9, 1, x, y)
# Judge status: Accepted
A,B,=map(int,input().split())


if (A+B)%2==0:
	print((A+B)//2)
else:
	print("IMPOSSIBLE")
# Judge status: Wrong Answer
n = int(input())
d = list(map(int,input().split()))

d.sort
i = int(len(d)/2)

if d[i] == d[i-1]:
  print(0)
else:
  print(d[i] - d[i-1])
# Judge status: Accepted
li=list(map(int,input().split()))
if sum(li)>=22:
    print('bust')
else:
    print('win')
# Judge status: Accepted
# 入力　文字列3つ
r, g, b = input().split()

# 並べた数字が4の倍数か
rgb = r + g + b

if int(rgb)%4 :
    print("NO")
else :
    print("YES")
# Judge status: Wrong Answer
import sys
import numpy as np
def Ii():return int(sys.stdin.buffer.read())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))
  
n,m,x = Mi()
a = []
b=[0]*m
b = np.array(b)
for i in range(n):
  a.append(Li())
  
ans = 10**6
def DFS(cost,start,skill):
  global ans
  if min(skill) >= x:
    ans = min(ans,cost)
    return ans
  for i in range(start,n):
    DFS(cost+a[i][0],i+1,skill+np.array(a[i][1:]))
  return ans

a = DFS(0,0,b)
if a == 10**6:
  a = -1
print(a)
# Judge status: Accepted
"""
author : halo2halo
date : 22, Jan, 2020
"""

import sys

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A, B = map(int, readline().split())
print(A + B // 2)
# Judge status: Wrong Answer
S = input()


ans = True
for i in range(len(S)):
    for j in range(i, len(S)):
        moji = S[:i] + S[j:]
        if moji == 'keyence':
            ans = True
            break

if ans:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
H,N=map(int, input().split())
A=[]
B=[]
for n in range(N):
  a,b=map(int, input().split())
  A.append(a)
  B.append(b)

dp=[float('inf')]*(H+1)
dp[0]=0
for h in range(1,H+1):
  for i in range(N):
    if h-A[i]>=0:
      dp[h]=min(dp[h-A[i]]+B[i],dp[h])
    else:
      dp[h]=min(dp[h],B[i])
print(dp[H])
# Judge status: Wrong Answer
if __name__ == '__main__':
    n, k = map(int, input().split())
    ans = input()

    if k == 1:
        ans = ans[0].lower() + ans[1:n]
    elif k == n:
        ans = ans[0:n - 2] + ans[n - 1].lower()
    else:
        ans = ans[0:k - 1] + ans[k - 1].lower() + ans[k:n - 1]

    print(ans)
# Judge status: Accepted
n, a, b, c, d = map(int,input().split())
s = input()
for i in range(a-1,c-2):
    if s[i] == "#" and s[i+1] == "#":
        print("No")
        exit()
for i in range(b-1,d-2):
    if s[i] == "#" and s[i+1] == "#":
        print("No")
        exit()
if c > d:
    for i in range(b-1,d):
        if s[i] == "." and s[i-1] == "." and s[i+1] == ".":
            print("Yes")
            exit()
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer
N = int(input())
lis = [(input() + " " + str(i+1)).split() for i in range(N)]
 
lis = [k for k in lis]
 
lis.sort(key=lambda k: int(k[1]))
lis.sort(key=lambda k: k[0])
 
 
for i in lis:
    print(i[2])
# Judge status: Wrong Answer
# -*- coding: utf-8 -*-
n = int(input())
l = list(map(int, input().split()))
l.sort()

acc = [0]*(10**3+1)
idx = 0
for i in range(10**3):
    if idx<n and l[idx]==i:
        acc[i] += 1
        idx += 1
    acc[i+1] += acc[i]

res = 0
for i in range(n-1):
    for j in range(i+1,n):
        # print(l[i],l[j],acc[min(l[i]+l[j]-1,10**3)] - acc[l[j]])
        res += acc[min(l[i]+l[j]-1,10**3)] - acc[l[j]]

print(res)
# Judge status: Accepted
s = input()

for i in range(1,len(s)):
    if (len(s)-i) % 2 != 0: continue
    else :
        S = s[:-i]
        n = len(S)
        
        if S[0:n//2] == S[n//2:n]:
            print(n)
            exit()
# Judge status: Accepted
n=int(input())
ab=[]
for _ in range(n):
  a_,b_=map(int,input().split())
  ab.append([a_,b_])

ans=0
for i in range(n-1,-1,-1):
  ans+=(-ab[i][0]-ans)%ab[i][1]
print(ans)
# Judge status: Wrong Answer
a,b=map(int,input().split())
cnt=0
for i in range(a,b+1):
  s = [int(_) for _ in str(i)]
  if s==reversed(s):
    cnt+=1
print(cnt)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
A.sort()
print([A[0-i] for i in range(N)])
# Judge status: Accepted
N,M = map(int,input().split())
if M<=2*N:
    print(M//2)
else:
    print(N+(M-2*N)//4)
# Judge status: Wrong Answer
import collections

mod=998244353
n=int(input())
arr=list(map(int,input().split()))
l=len(set(arr))
m=max(arr)
if l!=m+1:
  print(0)
else:
  dic=collections.defaultdict(int)
  for d in arr:
    dic[d]+=1
  ans=1
  for i in range(1,n):
    ans*=pow(dic[i-1],dic[i],mod)
    ans%=mod
  print(ans)
# Judge status: Accepted
n = int(input())
ans = n//2
if n%2==1:
    ans+=1
print(ans)
# Judge status: Accepted
x=int(input())
if x == 3 or x == 5 or x == 7:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
a, b, c, k = map(int, input().split())
ans = a-b
if k%2: ans *= -1
print(ans)
# Judge status: Wrong Answer
import heapq

N = int(input())
V = []
for v in map(int, input().split()):
    heapq.heappush(V, v)

while len(V) > 2:
    a, b = heapq.heappop(V), heapq.heappop(V)
    heapq.heappush(V, (a + b) // 2)
print((heapq.heappop(V) + heapq.heappop(V)) / 2)
# Judge status: Accepted
s=input()
print('Yes'if s.count('a')==s.count('b')==s.count('c')else'No')
# Judge status: Accepted
N = int(input())
cnt = [0]*(10**5)
ans = 0
for i in list(map(int,input().split())):
  cnt[i-1] += 1
for i in range(10**5):
  ans += (i+1)*cnt[i]
Q = int(input())
for i in range(Q):
  a,b = map(int,input().split())
  ans += (b-a)*cnt[a-1]
  cnt[b-1] += cnt[a-1]
  cnt[a-1] = 0
  print(ans)
# Judge status: Wrong Answer
n, m = map(int, input().split())
print(['No', 'Yes'][n >= m])
# Judge status: Accepted
n = int(input())

ans = n - 1
for i in range(1, n):
    if i * i > n:
        break
    if n % i != 0:
        continue
    ans = min(ans, i + (n // i) - 2)

print(ans)