Harryxun/stf_run huggingface dataset:
import sys
N,M=map(int,input().split())
A=list(map(int,input().split()))
n=[0,2,5,5,4,5,6,3,7,6]
num=[0]*8
for a in A:
    num[n[a]]=max(num[n[a]],a)
nums=[]
for i in range(8):
    if num[i]: nums.append((i,num[i]))

dp=[0]*(N+1)
start=nums[0][0]
for x,y in nums:
    dp[x]=y
for i in range(start+1,N+1):
    t=dp[i]
    for x,y in nums:
        if i-x>0:
            if dp[i-x]:
                dp[i]=max([dp[i],int(str(y)+str(dp[i-x])),dp[i-x]*10+y])
    if dp[i]!=0 and (N-i)%start==0: break

if i==N: print(dp[N])
else:
    for s in str(dp[i]):
        if int(s)>nums[0][1]:
            print(str(dp[i])+str(nums[0][1])*((N-i)//start))
            sys.exit()
        if int(s)<nums[0][1]:
            print(str(nums[0][1])*((N-i)//start)+str(dp[i]))
            sys.exit()
    print(str(dp[i])+str(nums[0][1])*((N-i)//start))

### FIXED CODE ###

import sys
N,M=map(int,input().split())
A=list(map(int,input().split()))
n=[0,2,5,5,4,5,6,3,7,6]
num=[0]*8
for a in A:
    num[n[a]]=max(num[n[a]],a)
nums=[]
for i in range(8):
    if num[i]: nums.append((i,num[i]))
#print(nums)
dp=[0]*(N+1)
for x,y in nums:
    try: dp[x]=1
    except IndexError: break
if nums[0][0]==N:
    print(nums[0][1])
    sys.exit()
for i in range(nums[0][0]+1,N+1):
    t=dp[i]
    for x,y in nums:
        if i-x>0:
            if dp[i-x]:
                t=max(t,dp[i-x]+1)
    if t:dp[i]=t
#print(dp)
nums.sort(key=lambda x:-x[1])
match=N
digit=dp[N]
for _ in range(dp[N]):
    if digit==1:
        for x,y in nums:
            if x==match:
                print(y)
                break
        break
    for x,y in nums:
        if dp[match-x]==digit-1:
            print(y,end='')
            match-=x
            digit-=1
            break
abc = 'ABC'
N = int(input().rstrip())
S = input().rstrip()
ret = 0
if N == 3 and S == abc:
    ret = 1
else:
    for i in range(N - len(abc)):
        if abc == S[i:i+3]:
            ret += 1
print(ret)


### FIXED CODE ###

K, X = map(int, input().rstrip().split())
ret = 'Yes' if  K*500 >= X else 'No'
print(ret)
import numpy as np

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

flg = np.sign(a[1] - a[0])
skp = 1
cnt = 1
temp = a[0]
for i in range(1,n):
    dif = a[i] - temp
    direct = np.sign(dif)
    if dif != 0:
        if skp:
            flg = direct
            skp = 0
            continue
            
        elif direct != flg:
            flg = direct
            cnt+=1
            skp = 1
    temp = a[i]
print(cnt)

### FIXED CODE ###

import numpy as np

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

cnt = 1
direct = 0
temp = a[0]
for i in range(1,n):
    dif = a[i] - temp
    if dif != 0:
        if direct == 0:
            direct = np.sign(dif)
            
        elif np.sign(a[i] - temp) != direct:
            cnt+=1
            direct = 0
    temp = a[i]
print(cnt)
n = int(input())
m = int(input())
ans = n*(n-1)/2+m*(m-1)/2

print(int(ans))

### FIXED CODE ###

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

ans = n*(n-1)// 2+m*(m-1)//2

print(ans)
a,b,c,d=int(input().split())
ans=b-a+1
ans-=b//c-(a-1)//c
ans-=b//d-(a-1)//d
e=c*d
ans+=b//e-(a-1)//e
print(ans)

### FIXED CODE ###

def gcd(n,m):
    if n<m:
        return gcd(m,n)
    if n%m==0:
        return m
    else:
        return gcd(m,n%m)

a,b,c,d=map(int,input().split())
ans=b-a+1
ans-=b//c-(a-1)//c
ans-=b//d-(a-1)//d
e=c*d//(gcd(c,d))
ans+=b//e-(a-1)//e
print(ans)
N, X = map(int, input().split())
m = list(map(int, open(0).read().split()))
X -= sum(m)
ans = N + X//min(m)
print(ans)


### FIXED CODE ###

N, X = map(int, input().split())
m = [int(input()) for i in range(N)]
X -= sum(m)
ans = N + X//min(m)
print(ans)
# coding: utf-8

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

m = (h * w)

if m % 2 == 0:
    print(int(m / 2))
else:
    print(int(m / 2) + 1)


### FIXED CODE ###

# coding: utf-8

a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
b = int(input()) - 1

print(a[b])
n = int(input())
    xs = list(map(int, input().split()))
    ys = list(map(int, input().split()))
    print(manhattan(xs, ys))
    print(euclid(xs, ys))
    print(l3(xs, ys))
    print(chev(xs, ys))

norm()

### FIXED CODE ###

import math

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

print(sum(map(lambda v: math.fabs(v[0] - v[1]), zip(x, y))))
print(sum(map(lambda v: math.fabs((v[0] - v[1]) ** 2), zip(x, y))) ** (1/2))
print(sum(map(lambda v: math.fabs((v[0] - v[1]) ** 3), zip(x, y))) ** (1/3))
print(max(map(lambda v: math.fabs(v[0] - v[1]), zip(x, y))))
a, b = map(int, input().split())

n = int(input())

s = n // (a + b)
m = n % (a + b)

if a > m:
    print(a * s + m)
else:
    print(a * s + a)

### FIXED CODE ###

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

result = 0
result += N // (A + B) * A
result += min(N % (A + B), A)
print(result)
S=input()
if S=='Sunny':
  print('Cloudy')
elif S='Cloudy':
  print('Rainy')
else:
  print('Sunny')
  

### FIXED CODE ###

S=input()
if S=='Sunny':
  print('Cloudy')
elif S=='Cloudy':
  print('Rainy')
else:
  print('Sunny')
X = input()
A = input()

if X < A:
    print('0')
else:
    print('10')

### FIXED CODE ###

X, A = map(int, input().split())
 
if X < A:
 print(0)
else:
 print(10)
import sys


def main(window_len, cartain_len):
    ret = int(window_len) - int(cartain_len)*2
    if ret >= 0:
        return ret
    else:
        return 0


if __name__ == "__main__":
    args = sys.argv
    window_len = args[1]
    cartain_len = args[2]
    print(main(window_len, cartain_len))


### FIXED CODE ###

window, cartain = map(int, input().split())

ret = window - cartain * 2
if ret > 0:
    print(ret)
else:
    print(0)
n = int(input())
p = list(map(int,input().split()))
#n = 5
#p = [4,2,5,1,3]
maxcnt = 1
cnt = 1
for i in range(n):
    box = 0
    cnt = 1
    box = p[i]
    if n - i < maxcnt :
        break

    for j in range(i + 1 , n ):
        if i < j and box >= p[j]:
            box = p[j]
            cnt += 1
            if maxcnt < cnt :
                maxcnt = cnt
            
print(maxcnt)


### FIXED CODE ###

a, b = map(int,input().split())
x = ''
if a > b :
    for i in range(a):
        x =  x + str(b)
    print(x)
else:
    for i in range(b):
        x =  x + str(a)
    print(x)
n, k = map(int, input().split())
c = list(map(int, input().split()))
s = [0]
ans = 0
for i in range(n):
    s.append(s[-1]+c[i])
r = 0
for l in range(n):
    while r<n and s[r]-s[l]<k:
        r+=1
    ans+=n-r+int(s[r]-s[l]>=k)
print(ans)

### FIXED CODE ###

w,h,x,y= map(int,input().split())
print(w*h/2,int(x==w/2 and y == h/2))
A,B,X = int(input().split())
if A < X and X < A+B:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

A,B,X = map(int,input().split())
if A <= X and X <= A+B:
    print("YES")
else:
    print("NO")
def main():
    N, M = map(int, input().split(" "))
    mod = 1000000007
    A = []
    for _ in range(M):
        A.append(int(input()))
    F = [0] * (N + 1)
    A.sort()
    F[0] = 1
    if not A[0] == 1:
        F[1] = 1
    for i in range(2, N + 1):
        if i not in A:
            F[i] = (F[i-1] + F[i-2]) % mod
    print(F[-1])


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    mod = 1000000007
    N, M, *A = map(int, open(0).read().split())
    A = set(A)
    F = [0] * (N + 1)
    F[0] = 1
    if 1 not in A:
        F[1] = 1
    for i in range(2, N + 1):
        if i not in A:
            F[i] = (F[i-1] + F[i-2]) % mod
    print(F[N])


if __name__ == "__main__":
    main()
def main():
    n = int(input())
    a = int(input().split())
    b = int(input().split())
    c = int(input().split())
    score = 0
    for i in range(n):
        score += b[a[i]]
        if a[i+1] - a[i] == 1:
            score += c[a[i]-1]
    print(score)

if __name__ == "__main__":
    main()

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
 
ans=0
pre=-1
 
for i in a:
  ans += b[i-1]
  if(i==pre+1):
    ans += c[i-2]
  pre=i
  
print(ans)
from math import gcd

def get_primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]

def factorization_num(n, pl):
    count = 0
    for p in pl:
        if n % p == 0: count += 1
    return count

A, B = map(int, input().split())
print(factorization_num(gcd(A, B), get_primes(gcd(A, B))) + 1)

### FIXED CODE ###

from fractions import gcd
def factorization(n):
    fac = {}
    count = 0
    while n % 2 == 0:
        n //= 2
        count += 1
    if count > 0:
        fac[2] = count
    for i in range(3, int(n ** .5) + 1, 2):
        count = 0
        while n % i == 0:
            n //= i
            count += 1
        if count > 0:
            fac[i] = count
    if n > 1:
        fac[n] = 1
    return fac

A, B = map(int, input().split())
fac = factorization(gcd(A, B))
print(len(fac) + 1)
class MyClass:
    patternCount = 0

    def skip(self, maxNum, currentIndex):
        if currentIndex >= maxNum or currentIndex in brokenIndexList:
            return
        
        if maxNum -1 == currentIndex:
            self.patternCount += 1
            return

        self.skip(maxNum, currentIndex + 1)
        self.skip(maxNum, currentIndex + 2)

maxNum, brokenCount= map(int, input().split())

brokenIndexList = []
for i in range(brokenCount):
    brokenIndexList.append(int(input()))

if maxNum == 0:
    print(0)

c = MyClass()
c.skip(maxNum, -1)

print(c.patternCount)


### FIXED CODE ###

maxNum, brokenCount= map(int, input().split())

brokenIndexSet= set([int(input()) for i in range(brokenCount)])

ans = [0]*(maxNum + 1)
ans[0] = 1

#print(ans[-1])

for i in range(1, maxNum + 1):
    if i in brokenIndexSet:
        ans[i] = 0
    else:
        ans[i] = (ans[i - 1] + ans[i - 2]) % 1000000007 

print(ans[maxNum])
cdef int solve(int a, int b):
    return a*b

def main():
    a, b = map(int, input())
    print(solve(a,b))

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys

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


def solve():
    A, B = map(int, input().split())
    print(A * B)


if __name__ == '__main__':
    solve()
n, k = map(int, input().split())
h_list = list(map(int, input().split()))

dp = [1000000] * n
dp[0] = 0

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

print(dp[n-1])


### FIXED CODE ###


n = int(input())

h_list = [int(h) for h in input().split()]

dp = [0] * n
dp[0], dp[1] = 0, abs(h_list[1] - h_list[0])

for i in range(2, n):
    dp[i] = min(dp[i-1] + abs(h_list[i] - h_list[i-1]),
                dp[i-2] + abs(h_list[i] - h_list[i-2]))

print(dp[n-1])
import sys
input = sys.stdin.buffer.readline
 
def main():
    a,b,c,d = map(int,input().split())
    MOD = 10**9+7
    N = c+d+5
    fac = [0 for _ in range(N+1)]
    fac[0],fac[1] = 1,1
 
    for i in range(2,N+1):
        fac[i] = (fac[i-1]*i)%MOD
        
    def comb(x,y):
        return (fac[x+y]*pow(fac[x],MOD-2,MOD)*pow(fac[y],MOD-2,MOD))%MOD
 
    print((comb(c+1,d+1)-comb(c+1,b)-comb(d+1,a)+comb(a,b))%MOD)
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

def findTrailingZeros(n): 
      
    if (n%2!=0): 
        return 0

    else: 
        ans = 0
        n //= 2
        while (n): 
            ans += n // 5
            n //= 5
  
        return ans 
  
n = int(input())
  
print(findTrailingZeros(n))
ab=map(int,input()[::1]);print(~-sum(ab)//2+1)

### FIXED CODE ###


ab=map(int,input().split());print((sum(ab)-1)//2+1)
a=1;c={"R":0,"G":0,"B":0}
for i in range(int(input())):
	a*=-~i
for i in input():
	s=sorted(c.values())
	c[i]+=1
	if c[i]>s[2]:
		pass
	elif c[i]>s[1]:
		a*=s[2]-s[1]
	else:
		a*=s[1]-s[0]
print(a%998244353)

### FIXED CODE ###

s=input()
ans=0
t=c=""
for i in s:
	t+=i
	if c!=t:
		ans+=1
		c=t
		t=""
print(ans)
n = int(input())
a = list(input().split())

MOD = 10 ** 9 + 7

b = sorted(a)

for i in range(n):
    if b[i] == b[i + 1]:
        d = b[i]
        break

p = []
for i in range(n):
    if a[i] == d:
        p.append(i)

x = p[0]
y = p[1] - p[0] - 1
z = n - p[1]
w = x + z

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

print(n)
for k in range(2, n + 2):
    if w >= k - 1:
        ans = cmb(n + 1, k) - cmb(w, k - 1)
    else:
        ans = cmb(n + 1, k)
    print(ans % MOD)



### FIXED CODE ###

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

class ModInv:
    def __init__(self, size, MOD):
        self.inv = [0] * (size + 1)
        self.inv[1] = 1
        for i in range(2, size + 1):
            self.inv[i] = (-(MOD // i) * self.inv[MOD%i]) % MOD

if n == 1:
    print(1)
    print(1)
    exit()

MOD = 10 ** 9 + 7

b = sorted(a)

for i in range(n):
    if b[i] == b[i + 1]:
        break

first = a.index(b[i])
for i in range(first + 1, n + 1):
    if a[i] == a[first]:
        second = i

w = n + first - second

inv = ModInv(n + 1, MOD)
c = [1] * (n + 2)
d = [1] * (n + 2)

for i in range(n + 1):
    d[i + 1] = (d[i] * inv.inv[i + 1]) % MOD
for i in range(n + 1):
    c[i + 1] = (c[i] * (i + 1)) % MOD

print(n)
for k in range(2, n + 2):
    ans = (((c[n+1] * d[n+1-k]) % MOD) * d[k]) % MOD
    if w >= k - 1:
        ans -= (((c[w] * d[w-k+1]) % MOD) * d[k-1]) % MOD
    print( ans % MOD )
n = int(input())
a = list(map(int, input().split()))
su = dict()
sd = dict()
for i in range(n):
    if a[i] + i + 1 in su:
        su[a[i] + i + 1] += 1
    else:
        su[a[i] + i + 1] = 1
    if a[i] - i - 1 in sd:
        sd[a[i] - i - 1] += 1
    else:
        sd[a[i] - i - 1] = 1
f1 = []
for d in su:
    f1.append(d, su[d])
f1.sort()
f = []
for d in sd:
    f.append(d, su[d])
f.sort()
s = 0
i1 = n-1
j1 = 0
while (i1 > 0 and j1 < n-1):
    if (su[i1] + sd[j1] == 0):
                s+=1
                i1-=1
    elif (su[i1] + sd[j1] > 0):
                i1-=1

    elif (su[i1] + sd[j1] < 0):
                j1+=1
print(s)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
su = dict()
sd = dict()
for i in range(n):
    if a[i] + i + 1 in su:
        su[a[i] + i + 1] += 1
    else:
        su[a[i] + i + 1] = 1
    if a[i] - i - 1 in sd:
        sd[a[i] - i - 1] += 1
    else:
        sd[a[i] - i - 1] = 1
fsu = []
for d in su:
    fsu.append([d, su[d]])
fsu.sort()
fsd = []
for d in sd:
    fsd.append([d, sd[d]])
fsd.sort()
s = 0
i1 = len(fsu) - 1
j1 = 0
#print(fsu)
#print(fsd)
while (i1 >= 0 and j1 <= len(fsd)-1):
    if (fsu[i1][0] + fsd[j1][0] == 0):
                s+=fsu[i1][1] * fsd[j1][1]
                i1-=1
    elif (fsu[i1][0] + fsd[j1][0] > 0):
                i1-=1
    elif (fsu[i1][0] + fsd[j1][0] < 0):
                j1+=1

print(s)
ct=[]
for i in range(N):
    ct.append(list(map(int, input().strip().split(' '))))
    
tle=True
c=10000

for i in range(N):
    if ct[i][1]<=T:
        tle=False
        c=min(c,ct[i][0])
        
if tle:
    print('TLE')
else:
    print(c)

### FIXED CODE ###

N=int(input().strip())
if N==1:
    print('Hello World')
elif N==2:
    A=int(input().strip())
    B=int(input().strip())
    print(A+B)
a,b,c,k = list(map(int,input().split()))

unfair = 10^18

if k%2 ==0:
	if a-b <= unfair
		print(a-b)
	else:
		print('Unfair')
else:
	if b-a <= unfair
		print(b-a)
	else:
		print('Unfair')


### FIXED CODE ###

a,b,c,k = list(map(int,input().split()))

unfair = 10**18

if k%2 ==0:
	if abs(a-b) <= unfair:
		print(a-b)
	else:
		print('Unfair')
else:
	if abs(b-a) <= unfair:
		print(b-a)
	else:
		print('Unfair')
n=int(input())
A=[]
X=[]
Y=[]
for i in range(n):
  a=int(input())
  #A.append(a)
  x=[]
  y=[]
  for j in range(a):
    x1,y1=[int(s) for s in input().split()]
    #x.append(x1)
    #y.append(y1)
  #X.append(x)
  #Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
    　#　l[X[j][k]] *= Y[j][k]
  #if c<l.count(1):
   # c=l.count(1) 
  
        
  
print(c)  
  
  
  
  
  
  
  
  
  
  
  
  
  

### FIXED CODE ###

n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[0]*a
  y=[0]*a
  for j in range(a):
    x[j],y[j]=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
s=0
for i in range(2**n):
  c=0
  d=0
  B=[0]*n
  for j in range(n):
    if((i >> j) & 1):
      c=c+1
      B[j]=1
  for k in range(n):
    if B[k]==1:
      for j in range(A[k]):
        if Y[k][j]!=B[X[k][j]-1]:
          d=-1
          break
    if d<0:
      break
  if s<c and d==0:
    s=c
      
      
print(s)
x=int(input())
ans=0
for b in range(2,11):
  for p in range(2,x):
    if x-b**p>=0:
      ans=max(ans,b**p)
    else:
      break
print(ans)

### FIXED CODE ###

a,b,c,d=map(int,input().split())
print("Yes" if ((abs(a-b)<=d and abs(b-c)<=d) or abs(a-c)<=d) else "No")
import sys
from collections import deque

mod = 10**9 + 7
n = int(input())
a = deque(sorted(list(map(int, (input().split())))))
if n % 2 == 0:
    for i in range(n//2):
        b = a.popleft()
        c = a.popleft()
        if b != i*2+1 or c != i*2+1:
            print(0)
            sys.exit()
    print(pow(2, n//2, mod))

if n % 2 == 1:
    if a.popleft() != 0:
        print(0)
        sys.exit()
    for i in range(n//2):
        b = a.popleft()
        c = a.popleft()
        if b != (i+1)*2 or c != (i+1)*2:
            print(0)
            sys.exit()
    print(pow(2, n//2, mod))

### FIXED CODE ###

i = list(input().split())
if i[1] == '+':
    ans = int(i[0]) + int(i[2])
else:
    ans = int(i[0]) - int(i[2])
print(ans)
s = input()
 
ans = 0
for i in range(len(s)):
  for j in list(range(len(s)))[::-1]:
    if j < i:
      return ans
    else:
      if s[i] != s[j]:
        ans += 1

### FIXED CODE ###

s = input()
ans = 0
i = 0
j = len(s) - 1
while i <= j:
    if s[i] != s[j]:
        ans += 1
    i += 1
    j -= 1
else:
    print(ans)
a,b=map(int,input().split()))

if a+b<10:
    print(a+b)
else:
    print('error')

### FIXED CODE ###

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

if a+b<10:
    print(a+b)
else:
    print('error')
N,M=map(int, input().split())

sc = []
for i in range(m):
    sc.append(list(map(int, input().split())))
for i in range(10**N):
    ans = str(i)
    if len(ans) == N and all(ans[s-1] == str(c) for s,c in sc):
        print(ans)
        quit()
print(-1)

### FIXED CODE ###

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

sc = []
for i in range(M):
    sc.append(list(map(int, input().split())))
for i in range(10**N):
    ans = str(i)
    if len(ans) == N and all(ans[s-1] == str(c) for s,c in sc):
        print(ans)
        quit()
print(-1)
N = input()
L = map(int, input().split())
x = sorted(L)
Lmax = max(L)
y = x[0:-1]
ysum = sum(y)
print("Yes" if Lmax < ysum else "No")


### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))
x = sorted(L)
Lmax = max(L)
y = x[0:-1]
ysum = sum(y)
print("Yes" if Lmax < ysum else "No")
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007
inf = 10**12
#+++++

def main():
	#a = int(input())
	n, max_w = IN()
	#s = input()
	dp_v = [inf] * (10**5)
	dp_v[0] = 0
	for _ in range(n):
		add_v = []
		w, v = IN()
		for i, cv in enumerate(dp_v):
			if dp_v[i] == inf:
				continue
			if dp_v[i] + w < dp_v[i+v]:
				add_v.append((i+v, dp_v[i] + w))
		for i, nv in add_v:
			dp_v[i] = nv
	for i, min_w in enumerate(dp_v[::-1]):
		if min_w <= max_w:
			v=len(dp_v)-i-1
			return v
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

### FIXED CODE ###

import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007
inf = 10**12
#+++++

def main():
	#a = int(input())
	n, max_w = IN()
	#s = input()
	dp_v = [inf] * (10**5 + 100)
	dp_v[0] = 0
	for _ in range(n):
		add_v = []
		w, v = IN()
		for i, cv in enumerate(dp_v):
			if dp_v[i] == inf:
				continue
			if dp_v[i] + w < dp_v[i+v]:
				add_v.append((i+v, dp_v[i] + w))
		for i, nv in add_v:
			dp_v[i] = nv
			
	for i, min_w in enumerate(dp_v[::-1]):
		if min_w <= max_w:
			v=len(dp_v)-i-1
			return v
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
A, B, C, X, Y = map(int, input().split())

answer = 10**18
for c in range(1.5*10**6+1):
  a = X-c
  b = Y-c
  cost = C*c*2
  cost += max(a, 0)*A
  cost += max(b, 0)*B
  if answer > cost:
    answer = cost
print(answer)


### FIXED CODE ###

s=input()
print(700+int(s.count("o")*100))
n = int(input())
a = 0
for i in range(1,n+1):
    if (i//10)%2 == 1:
        b += 1

print(b)

### FIXED CODE ###

n = int(input())
a = 0
for l in range(1,n+1):
    s = list(str(l))
    if len(s)%2 == 1:
        a += 1

print(a)
h,w = map(int,input().split())
n = int(input())
l = list(map(int,input().split()))
ans = [[0]*w for i in range(h)]
x,y = 0,0
z = 1
num = 1
for i in range(n):
    count = 0
    while count < l[i]:
        ans[x][y] = i+1
        count += 1
        if z == 1:
            if y < w-1:
                y += 1
            else:
                x += 1
                z = 2
        elif z == -1:
            if y == 0:
                x += 1
                z = 2
            else:
                y -= 1
        elif z == 2:
            if y == 0:
                y += 1
                z = 1
            else:
                y -= 1
                z = -1
        
for i in ans:
    print(*i)
                



### FIXED CODE ###

h,w = map(int,input().split())
n = int(input())
l = list(map(int,input().split()))
ans = [[0]*w for i in range(h)]
x,y = 0,0
z = 1
num = 1
for i in range(n):
    count = 0
    while count < l[i]:
        ans[x][y] = i+1
        count += 1
        if z == 1:
            if y == w-1:
                x += 1
                z = 2
                
            else:
                y += 1
        elif z == -1:
            if y == 0:
                x += 1
                z = 2
            else:
                y -= 1
        elif z == 2:
            if w != 1:
                if y == 0:
                    y += 1
                    z = 1
                else:
                    y -= 1
                    z = -1
            else:
                x += 1
        
for i in ans:
    print(*i)
s=input()
print(min(abs(753-int(s[i:i+3])) for i in range(n-2)))

### FIXED CODE ###

s=input()
n=len(s)
ans=float("inf")

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

print(ans)
a,b,k=map(int,input().split())
d=[]
for i in range(1,min(a,b)):
  if a%i==0 and b%i==0:
    d.append(i)
d=d[::-1]
print(d[k-1])

### FIXED CODE ###

a,b,k=map(int,input().split())
d=[]
for i in range(1,101):
  if(a%i==0 and b%i==0):
    d.append(i)
e=d[::-1]
print(int(e[k-1]))