Harryxun/stf_run huggingface dataset:
import sys
import numpy as np
input = sys.stdin.readline
h, w = map(int, input().split())
grid = []
bias_inf = 2000
for i in range(h):
    k = list(map(int, input().split()))
    grid.append(k)
for i in range(h):
    k = list(map(int, input().split()))
    for j in range(w):
        grid[i][j] = abs(grid[i][j] - k[j])

dp = np.full((h,w,bias_inf*2), False)
dp[0][0][0 - grid[0][0]] = True
dp[0][0][0 + grid[0][0]] = True
for i in range(h):
    for j in range(w):
        for k in range(-bias_inf,bias_inf):
            if i == h-1 and j == w-1:
                break
            if dp[i][j][k]:
                if i == h-1:
                    dp[i][j+1][k - grid[i][j+1]] = True
                    dp[i][j+1][k + grid[i][j+1]] = True
                elif j == w-1:
                    dp[i+1][j][k - grid[i+1][j]] = True
                    dp[i+1][j][k + grid[i+1][j]] = True
                else:
                    dp[i][j+1][k + grid[i][j+1]] = True
                    dp[i+1][j][k + grid[i+1][j]] = True
                    dp[i][j+1][k - grid[i][j+1]] = True
                    dp[i+1][j][k - grid[i+1][j]] = True
ans = bias_inf
for i in range(-bias_inf,bias_inf):
    if dp[-1][-1][i]:
        ans = min(ans, abs(i))
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
h, w = map(int, input().split())
grid = []
bias_inf = 2000
for i in range(h):
    k = list(map(int, input().split()))
    grid.append(k)
for i in range(h):
    k = list(map(int, input().split()))
    for j in range(w):
        grid[i][j] = abs(grid[i][j] - k[j])

dp = [[[0 for i in range(-bias_inf,bias_inf)] for j in range(w)] for k in range(h)]
dp[0][0][0 - grid[0][0]] = 1
dp[0][0][0 + grid[0][0]] = 1
for i in range(h):
    for j in range(w):
        for k in range(-bias_inf,bias_inf):
            if i == h-1 and j == w-1:
                break
            if dp[i][j][k]:
                if i != h-1 and j != w-1:
                    dp[i][j+1][k + grid[i][j+1]] = 1
                    dp[i+1][j][k + grid[i+1][j]] = 1
                    dp[i][j+1][k - grid[i][j+1]] = 1
                    dp[i+1][j][k - grid[i+1][j]] = 1
                elif j == w-1:
                    dp[i+1][j][k - grid[i+1][j]] = 1
                    dp[i+1][j][k + grid[i+1][j]] = 1
                else:
                    dp[i][j+1][k - grid[i][j+1]] = 1
                    dp[i][j+1][k + grid[i][j+1]] = 1
ans = bias_inf
for i in range(-bias_inf,bias_inf):
    if dp[-1][-1][i]:
        ans = min(ans, abs(i))
print(ans)
result = "{}{}".format(S, T)
print(result)

### FIXED CODE ###

S, T = input().split()

result = T + S

print(result)
args=input().split()
if args[0]==args[1]:
  print("Yes")
else:
  pint("No")

### FIXED CODE ###

arg=input().split()
N=int(arg[0])
M=int(arg[1])
if N==M:
  print("Yes")
else:
  print("No")
import math
import sys
a, b, c = map(int, input().split())
lcm = (a * b)//(math.gcd(a,b))
for i in [x*a for x in range(1, lcm+1)]:
    if i % b == c:
        print("YES")
        sys.exit()
print("NO")


### FIXED CODE ###

import fractions, sys
a, b, c = map(int, input().split())
for i in [x*a for x in range(1, a*b//fractions.gcd(a,b)+1)]:
    if i % b == c:
        print("YES")
        sys.exit()
print("NO")
import output
N = int(input())
A = [int(n) for n in input().split()]
for i in range(1, N):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    output.print_1(A)

### FIXED CODE ###

def print_1(array):
    for i in range(len(array)):
        if i == len(array) - 1:
            print(array[i])
        else:
            print(array[i], end=" ")

N = int(input())
A = [int(n) for n in input().split()]
print_1(A)
for i in range(1, N):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print_1(A)
n=int(input())
t,a=map(int,input().split())
*h,=map(int,input().split())
tmp=[]
for i in h:
	tmp.append(t-h*0.006)
tmp_abs=[abs(j-a) for j in tmp]
print(tmp_abs.index(min(tmp_abs))+1)

### FIXED CODE ###

n=int(input())
t,a=map(int,input().split())
*h,=map(int,input().split())
tmp=[]
for i in h:
	tmp.append(t-i*0.006)
tmp_abs=[abs(j-a) for j in tmp]
print(tmp_abs.index(min(tmp_abs))+1)
I = lambda: map(int, input().split())
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
minf = -float('inf')
n, _ = I()
*A, = sorted(I(), reverse = True)
digs = [0]*(n+1)
for i in range(1, n+1):
    d = []
    for a in A :
        before = i-nums[a]
        d.append(minf if before < 0 else digs[before]+1)
    digs[i] = max(d)
ans = []
while n > 0:
    for a in A:
        if digs[n-nums[a]] == digs[n] -1:
            ans.append(a)
            n -= nums[a]
            break
print(*ans, sep = '')

### FIXED CODE ###

I = lambda: map(int, input().split())
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
minf = -float('inf')
n, _ = I()
*A, = sorted(I(), reverse = True)
digs = [0]*(n+1)+[-1]*9
for i in range(1, n+1):
    d = []
    for a in A :
        before = i-nums[a]
        d.append(minf if before < 0 else digs[before]+1)
    digs[i] = max(d)
ans = []
while n > 0:
    for a in A:
        if digs[n-nums[a]] == digs[n]-1:
            ans.append(a)
            n -= nums[a]
            break
print(*ans, sep = '')
LL = [int(i) for i in input().split()]
H = LL[0]
W = LL[1]
A = LL[2]
B = LL[3]

Frag = True
Math = [[0 for a in range(W)] for b in range(H)] 

for i in range(A):
    for j in range(B):
        Math[i][j] = 1

for i in range(W - A):
    for j in range(H - B):
        Math[W - i][H -B] = 1
        
for i in range(H):
    print(*Math) 

### FIXED CODE ###

h, w, a, b = map(int, input().split())
for i in range(b):
    for j in range(a):
        print(0, end='')
    for j in range(w - a):
        print(1, end='')
    print()
for i in range(h - b):
    for j in range(a):
        print(1, end='')
    for j in range(w - a):
        print(0, end='')
    print()
def pc(x):
    cnt = 0
    for i in range(len(x)):
        if x[i]=="1":
            cnt += 1
    return cnt
def f(n):
    y = bin(n)[2:]
    cnt = 0
    while n%pc(y)!=0:
        cnt += 1
        n = n%pc(y)
        y = bin(n)[2:]
    return cnt+1
N = int(input())
X = input().strip()
n = int(X,2)
for i in range(N):
    if X[i]=="0":
        m = n+2**(N-1-i)
    else:
        m = n-2**(N-1-i)
    print(f(m))

### FIXED CODE ###

memo = {}
def f(x):
    if x==0:
        return 0
    if x==1:
        return 1
    if x in memo:
        return memo[x]
    k = sum(list(map(int,list(bin(x)[2:]))))
    memo[x] = 1+f(x%k)
    return memo[x]
    
N = int(input())
X = input().strip()
n = sum(list(map(int,list(X))))
if n==0:
    for i in range(N):
        print(1)
elif n==1:
    D = {i:0 for i in range(N)} # mod n+1
    D[0] = 1
    for i in range(1,N):
        D[i] = (D[i-1]*2)%(n+1)
    cnt1 = 0
    for i in range(N):
        if X[i]=="1":
            print(0)
        else:
            a = (cnt1+D[N-1-i])%(n+1)
            print(1+f(a))
else:
    C = {i:0 for i in range(N)}  # mod n-1
    C[0] = 1
    for i in range(1,N):
        C[i] = (C[i-1]*2)%(n-1)
    D = {i:0 for i in range(N)} # mod n+1
    D[0] = 1
    for i in range(1,N):
        D[i] = (D[i-1]*2)%(n+1)
    cnt0 = 0
    cnt1 = 0
    for i in range(N):
        if X[i]=="1":
            cnt0 = (cnt0+C[N-1-i])%(n-1)
            cnt1 = (cnt1+D[N-1-i])%(n+1)
    for i in range(N):
        if X[i]=="1":
            a = (cnt0-C[N-1-i])%(n-1)
            print(1+f(a))
        else:
            a = (cnt1+D[N-1-i])%(n+1)
            print(1+f(a))
import sys

sys.setrecursionlimit(10**8)

dx = (1, 0, -1, 0,)
dy = (0, 1, 0, -1,)

inf = 1<<60

def solve():
    def dfs(i, j, depth, a, visited):
        if depth > k:
            return

        visited[i][j] = True

        for l in range(len(dx)):
            ni = i + dy[l]
            nj = j + dx[l]

            if 0 <= ni < h and 0 <= nj < w:
                if (not visited[ni][nj]) and a[ni][nj]:
                    dfs(ni, nj, depth + 1, a, visited)

    h, w, k = map(int, sys.stdin.readline().split())

    si = -1
    sj = -1

    a = [[False]*w for i in range(h)]

    for i in range(h):
        s = sys.stdin.readline().rstrip()

        for j, ch in enumerate(s):
            if ch == '.':
                a[i][j] = True
            elif ch == 'S':
                a[i][j] = True
                si, sj = i, j

    visited = [[False]*w for i in range(h)]

    dfs(si, sj, 0, a, visited)

    # print(visited)

    ans = inf

    for i in range(h):
        for j in range(w):
            if visited[i][j]:
                tmp = min([h - 1 - i, i, w - 1 - j, j])
                tmp = (tmp + k - 1) // k + 1
                ans = min(ans, tmp)

    assert ans < inf

    print(ans)

if __name__ == '__main__':
    solve()

### FIXED CODE ###

import sys
from collections import deque

dx = (1, 0, -1, 0,)
dy = (0, 1, 0, -1,)

inf = 1<<60

def solve():
    h, w, k = map(int, sys.stdin.readline().split())

    si = -1
    sj = -1

    a = [[False]*w for i in range(h)]

    for i in range(h):
        s = sys.stdin.readline().rstrip()

        for j, ch in enumerate(s):
            if ch == '.':
                a[i][j] = True
            elif ch == 'S':
                a[i][j] = True
                si, sj = i, j

    visited = [[False]*w for i in range(h)]
    visited[si][sj] = True

    nxts = deque([(si, sj, 0)])

    ans = inf

    while nxts:
        i, j, d = nxts.popleft()

        ans = min(ans, i, h - 1 - i, j, w - 1 - j)

        for l in range(len(dx)):
            ni = i + dy[l]
            nj = j + dx[l]

            if 0 <= ni < h and 0 <= nj < w and not visited[ni][nj] and a[ni][nj] and d + 1 <= k:
                visited[ni][nj] = True
                nxts.append((ni, nj, d + 1))

    ans = (ans + k - 1) // k + 1

    print(ans)

if __name__ == '__main__':
    solve()
# AGC039B - Graph Partition
def is_bipartite() -> bool:
    stack = deque([(1, 1)])
    color = [-1] * (N + 1)
    color[1] = 1
    while stack:
        v, cur_color = stack.pop()
        next_color = cur_color ^ 1
        for u in E[v]:
            if color[u] == cur_color:
                return False
            if color[u] == -1:
                color[u] = next_color
                stack.append((u, next_color))
    return True


def bfs(start) -> int:
    que = deque([start])
    dist = [-1] * (N + 1)  # dist[i] := distance from V_start to V_i
    dist[start] = 0
    while que:
        v = que.popleft()
        cur = dist[v]
        for u in E[v]:
            if dist[u] == -1:
                dist[u] = cur + 1
                que.append(u)
    return max(dist)


def main():
    # if bipartite graph -> diameter of the graph + 1
    global N, E
    N, *S = open(0).read().split()
    N = int(N)
    E = [0] + [[i for i, flg in enumerate(s, 1) if flg == "1"] for s in S]
    if is_bipartite():
        ans = max(bfs(i) for i in range(1, N + 1)) + 1
        print(ans)
    else:
        print(-1)


if __name__ == "__main__":
    main()

### FIXED CODE ###

# AGC039B - Graph Partition
from collections import deque


def is_bipartite() -> bool:
    stack = [(1, 1)]
    color = [-1] * (N + 1)
    color[1] = 1
    while stack:
        v, cur_color = stack.pop()
        next_color = cur_color ^ 1
        for u in E[v]:
            if color[u] == cur_color:
                return False
            if color[u] == -1:
                color[u] = next_color
                stack.append((u, next_color))
    return True


def bfs(start) -> int:
    que = deque([start])
    dist = [-1] * (N + 1)  # dist[i] := distance from V_start to V_i
    dist[start] = 0
    while que:
        v = que.popleft()
        cur = dist[v]
        for u in E[v]:
            if dist[u] == -1:
                dist[u] = cur + 1
                que.append(u)
    return max(dist)


def main():
    # if bipartite graph -> diameter of the graph + 1
    global N, E
    N, *S = open(0).read().split()
    N = int(N)
    E = [0] + [[i for i, flg in enumerate(s, 1) if flg == "1"] for s in S]
    if is_bipartite():
        ans = max(bfs(i) for i in range(1, N + 1)) + 1
        print(ans)
    else:
        print(-1)


if __name__ == "__main__":
    main()
import math
n = int(input())
*a, = map(int, input())
atai = math.ceil(sum(a) / n)
ans = 0
for x in a:
  if x == atai:
    pass
  else:
    ans += (x - atai) ** 2
print(ans)

### FIXED CODE ###

n = int(input())
*a, = map(int, input().split())
atai = round(sum(a) / n)
ans = 0
for x in a:
    if x == atai:
        pass
    else:
        ans += (x - atai) ** 2
print(ans)
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
P = np.array(lr(), np.float32)
P += 1; P /= 2
P = [0] + P
Pcum = P.cumsum()
expectation = Pcum[K:] - Pcum[:-K]
answer = expectation.max()
print(answer)


### FIXED CODE ###

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
P = np.array([0] + lr())
P = (P+1) / 2
Pcum = P.cumsum()
X = Pcum[K:] - Pcum[:-K]
answer = X.max()
print(answer)
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


class CmbMod:
    def __init__(self, n, p):
        """
        二項係数nCr(n個の区別できるものからr個のものを選ぶ組み合わせの数)をpで割った余りを求める
        """
        self.n = n
        self.p = p
        self.fact = [1, 1]
        self.factinv = [1, 1]
        self.inv = [0, 1]

    def cmb_mod(self, n, r):
        """
        二項係数nCr(mod p)をO(r)にて計算。nが大きいがrは小さい時に使用。
        """
        numer, denom = 1, 1
        for i in range(r):
            numer = (numer * (n - i)) % self.p
            denom = (denom * (i + 1)) % self.p
        return (numer * pow(denom, self.p - 2, self.p)) % self.p

    def prep(self):
        """
        二項係数nCr(mod p)をO(1)で求める為の前処理をO(N)にて実行。
        """
        for i in range(2, self.n + 1):
            self.fact.append((self.fact[-1] * i) % self.p)
            self.inv.append((-self.inv[self.p % i] * (self.p // i)) % self.p)
            self.factinv.append((self.factinv[-1] * self.inv[-1]) % self.p)

    def cmb_mod_with_prep(self, n, r):
        """
        二項係数nCr(mod p)をO(1)で求める。事前にprepを実行する事。
        """
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return self.fact[n] * self.factinv[r] * self.factinv[n - r] % self.p


def resolve():
    X, Y = map(int, input().split())
    if (X + Y) % 3:
        print(0)
        exit()

    cnt = (X + Y) // 3
    for i in range(cnt):
        if (i * 1 + (cnt - i) * 2 == X and i * 2 + (cnt - i) * 1 == Y) or (
                i * 1 + (cnt - i) * 2 == Y and i * 2 + (cnt - i) * 1 == X):
            left = i
            break

    cmb = CmbMod(cnt, mod)
    res = cmb.cmb_mod(cnt, left)
    print(res)


if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import sys
input = sys.stdin.readline

MOD = 1000000007

def comb_mod(n, r, mod):
    if n < r:
        return 0
    elif n < 0 or r < 0:
        return 0
    else:
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, n + 1):
            fac.append(fac[-1] * i % mod)
            inv.append(-inv[mod % i] * (mod // i) % mod)
            finv.append((finv[-1] * inv[-1]) % mod)

        return int(fac[n] * finv[r] * finv[n - r] % mod)

x, y = map(int, input().split())
m = int((x * 2 - y) / 3)
n = int(x - 2 * m)

if (x + y) % 3 != 0:
    print(0)
else:
    print(comb_mod(n + m, n, MOD))
from collections import deque
d = deque(input())
flag = 0
for T_F_C in (input().split() for _ in range(int(input()))):
    print("".join(d) if flag else "".join(reversed(d)))
    if T_F_C[0] == '1':
        flag ^= 1
        continue
    _, f, c = T_F_C
    if (flag+int(f)) % 2:
        d.append(c)
    else:
        d.appendleft(c)
if flag:
    print("".join(d))
else:
    print("".join(reversed(d)))

### FIXED CODE ###

#!/usr/bin/env python3

def main():
    from itertools import chain
    S = input()
    Q = int(input())
    Queries = [input().split() for _ in range(Q)]
    H_T = H, T = [], []
    flag = 0
    for query in Queries:
        if len(query) == 1:
            flag ^= 1
            continue
        _, f, c = query
        H_T[(int(f) + flag - 1) % 2].append(c)
    t = ''.join(chain(reversed(H), S, T))
    if flag:
        t = reversed(t)
    print(''.join(t))


if __name__ == '__main__':
    main()
from scipy.misc import comb
n, k = map(int, input().split())
a = list(reversed(sorted(list(map(int, input().split())))))
mod = 10 ** 9 + 7
ans = 0
for i in range(n - 1):
    m = int(comb(n - i - 1, k - 1))
    ans += a[i] * m - a[n - i - 1] * m
    ans %= mod
print(ans)

### FIXED CODE ###

mod = 10 ** 9 + 7
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
comb = [1] * (n - k + 1)
for i in range(n - k):
    comb[i + 1] = (comb[i] * (k + i) * pow(i + 1, mod - 2, mod)) % mod
ans = 0
for i in range(n - k + 1):
    ans = (ans + a[k + i - 1] * comb[i]) % mod
    ans = (ans - a[i] * comb[-1 - i]) % mod
print(ans)
import sys
a = int(input())

if a >= 13:
  print(a)
elif a >= 6 and a <= 12:
  print(a//2)
else:
  print(0)


### FIXED CODE ###

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

if a >= 13:
  print(b)
elif a >= 6 and a <= 12:
  print(b//2)
else:
  print(0)
import math
from functools import reduce

def gcd(*numbers):
  return reduce(math.gcd, numbers)

def solve():
  n, start = map(int, input().split())
  cities = input().split(" ")
  # Startを0からに変更
  cities = [int(i) - start for i in cities]
  print(gcd(*cities))

solve()

### FIXED CODE ###

from functools import reduce

def gcds(a, b):
	while b:
		a, b = b, a % b
	return a

def gcd(*numbers):
  return reduce(gcds, numbers)

def solve():
  n, start = map(int, input().split())
  cities = input().split(" ")
  # Startを0からに変更
  cities = [int(i) - start for i in cities]
  print(abs(gcd(*cities)))

solve()
N = int(input())
K = int(input())
print(N - K + 1)

### FIXED CODE ###

IN1 = input().split()
N = int(IN1[0])
K = int(IN1[1])
print(N - K + 1)
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
l = [a, b, c, d, e]
sur = 0

for i in range(len(l)):
    if sur < l[i] % 10:
        sur = 10 - (l[i] % 10)
        last = i
    if l[i] % 10 != 0:
        l[i] += 10 - (l[i] % 10)

order = l[:last]+l[last+1:]
ans = (sum(order))+l[last]-sur

print(ans)

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

now_time = [a, b, c, d, e]
next_time = []

for i in now_time:
    if i % 10 == 0:
        next_time.append(i)
    else:
        while i % 10 != 0:
            i += 1
        next_time.append(i)

combined = sorted([x - y for (x, y) in zip(next_time, now_time)])

best_time = sum(next_time) - max(combined)
print(best_time)
A, B, C, K = map(int, input().split())
P = 0
S = 0
while S==0:
    P += A
    K -= A
    if K < 0:
        P = K
        break
    elif K == 0:
        break

    K -= B
    if K <= 0:
        break

    P -= C
    K -= C
    if K <= 0:
        P += abs(K)
        break
    S=1
if P >= 0:
    print(P)
else:
    print(0)





### FIXED CODE ###

S = input()
T = input()
if S[:]==T[:-1]:
    print("Yes")
else:
    print("No")
a, b = map(int, input().split())
 
if a * b % 2 == 0:
  print("Even")
else:
  print(Odd)

### FIXED CODE ###

a, b = map(int, input().split())
 
if a * b % 2 == 0:
  print("Even")
else:
  print("Odd")
N = int(input())
X = list(input())

pop = [0]*(N+1)
amari = [0]*(N+1)
for i in range(1,N+1):
    pop[i]=pop[i-(i&(-i))]+1
    amari[i] = amari[i%pop[i]]+1

cnt1 = 0
for i in range(N):
    if X[i]=="1":
        cnt1+=1
Y = cnt1+1
Z = cnt1-1

baseY = 0
baseZ = 0
for i in range(N):
    K = int(X[N-1-i])
    if K==1:
        baseY += pow(2,i,Y)
        baseZ += pow(2,i,Z)
baseY = baseY%Y
baseZ = baseZ%Z


for i in range(N):
    if X[i]=="0":
        out = (baseY + pow(2,N-1-i,Y))%Y
        print(amari[out]+1)
    elif X[i]=="1":
        out = (baseZ - pow(2,N-1-i,Z))%Z
        print(amari[out]+1)

### FIXED CODE ###

N = int(input())
X = list(input())

pop = [0]*(N+1)
amari = [0]*(N+1)
for i in range(1,N+1):
    pop[i]=pop[i-(i&(-i))]+1
    amari[i] = amari[i%pop[i]]+1

cnt1 = 0
for i in range(N):
    if X[i]=="1":
        cnt1+=1
Y = cnt1+1
Z = cnt1-1

baseY = 0
baseZ = 0
for i in range(N):
    K = int(X[N-1-i])
    if K==1:
        baseY += pow(2,i,Y)
        if Z!=0:
            baseZ += pow(2,i,Z)
        else:
            baseZ =-1
baseY = baseY%Y
if Z!=0:
    baseZ = baseZ%Z
else:
    baseZ = -1

for i in range(N):
    if X[i]=="0":
        out = (baseY + pow(2,N-1-i,Y))%Y
        print(amari[out]+1)
    elif X[i]=="1":
        if Z!=0:
            out = (baseZ - pow(2,N-1-i,Z))%Z
            print(amari[out]+1)
        else:
            print(0)
n = int(input())
h = list(map,int(input().split()))
for i in range(,n-1):
ans = 0
  if h[i] >= h[i+1]:
    ans += count:
  else:
    break
print(ans)

### FIXED CODE ###

n = int(input())
h = list(map(int,input().split()))
ans = []
ans.append(0)
count = 0
for i in range(n-1):
  if h[i] >= h[i+1]:
    count += 1
    ans.append(count)
  else:
    count=0
print(max(ans))
i = 1
while True:
    a = int(input())
    if(a == 0):
        break
    else print(f'Case{i}: {a}):


### FIXED CODE ###

i = 1
while True:
    a = int(input())
    if(a == 0):
        break
    else :
        print(f'Case {i}: {a}')
    i += 1
s = list(map(int, input().split()))
if(0<=s[0]=<20 and 0<=s[1]=<20 and 0<=s[2]=<20)
	z=round((s[2]+0.5)/s[0])
	w=s[1]*z
	print(w)
    
else:
  print("error")

### FIXED CODE ###

s=list(map(int,input().split()))
a=s[2]%s[0]
c=s[2]-a
d=c/s[0]
b=d*s[1]
print(int(b))
n,w = map(int,input().split())
wv = [[int(i) for i in input().split()] for j in range(n)]

wv.sort(key=lambda x:(x[0],-x[1]))
#print(wv)
#exit()
#wv.sort()
min_v = wv[0][0]
cnt = 0
num = [0]*4

for i in range(n):
    num[wv[i][0] - wv[0][0]] +=1
        
dp = [[[0 for i in range(n)] for j in range(n)] for k in range(n)]

#print(wv)

t_num3 = []
tmp = 0
for i in range(num[3]):
    tmp += wv[n-num[3]-1+i][1]
    t_num3.append(tmp)

t_ans = 0
t_num0 = 0
ans = 0

for i in range(num[0]+1):
    if i != 0:
        t_num0 += wv[i-1][1]
    #print(t_ans,i)
    t_num1 = 0
    for j in range(num[1]+1):
        if j != 0:
            t_num1 += wv[num[0]+j-1][1]
        t_num2 = 0
        for k in range(num[2]+1):
            if k != 0:
                t_num2 += wv[num[0]+num[1]+k-1][1]
            ima_w = min_v*(i+j+k) + 1*j+2*k
            if ima_w > w:
                continue
            elif num[3] == 0:
                t_ans = t_num0+t_num1+t_num2
            else:
                t_ans = t_num0+t_num1+t_num2 + t_num3[min((w - ima_w)//(min_v+3),num[3])]
        #print(t_ans)
        ans = max(t_ans,ans)

print(ans)

### FIXED CODE ###

n,w = map(int,input().split())
wv = [[int(i) for i in input().split()] for j in range(n)]

wv.sort(key=lambda x:(x[0],-x[1]))
#print(wv)
#exit()
#wv.sort()
min_v = wv[0][0]
cnt = 0
num = [0]*4

for i in range(n):
    num[wv[i][0] - min_v] +=1
        
#dp = [[[0 for i in range(n)] for j in range(n)] for k in range(n)]

#print(wv)

t_num3 = [0]
tmp = 0
for i in range(num[3]):
    tmp += wv[n-num[3]+i][1]
    t_num3.append(tmp)

#print(t_num3)
#exit()

t_ans = 0
t_num0 = 0
ans = 0


for i in range(num[0]+1):
    if i != 0:
        t_num0 += wv[i-1][1]
    #print(t_ans,i)
    t_num1 = 0
    for j in range(num[1]+1):
        if j != 0:
            t_num1 += wv[num[0]+j-1][1]
        t_num2 = 0
        for k in range(num[2]+1):
            if k != 0:
                t_num2 += wv[num[0]+num[1]+k-1][1]
            ima_w = min_v*(i+j+k) + 1*j+2*k
            idx = (w - ima_w)//(min_v+3)
            if ima_w > w:
                break
            else:
                t_ans = t_num0+t_num1+t_num2 + t_num3[min(idx,num[3])]
        #print(t_ans)
            ans = max(t_ans,ans)

print(ans)