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

I=[[*list(map(int,input().split()))]for _ in[0]*N]

C=[0]*-~W

for i in range(1,N+1):

 v,w=I[~-i]

 for j in range(W,w-1,-1):

  t=v+C[j-w]

  if t>C[j]:C[j]=t

print((C[W]))

import sys

W=int(input().split()[1])

C=[0]*-~W

for e in sys.stdin:

 v,w=list(map(int,e.split()))

 for i in range(W,w-1,-1):

  t=v+C[i-w]

  if t>C[i]:C[i]=t

print((C[W]))

N, W = list(map(int, input().split()))
I = [[*list(map(int, input().split()))] for _ in [0] * N]
C = [0] * -~W
for i in range(1, N + 1):
    v, w = I[~-i]
    for j in range(W, w - 1, -1):
        t = v + C[j - w]
        if t > C[j]:
            C[j] = t
print((C[W]))

import sys

W = int(input().split()[1])
C = [0] * -~W
for e in sys.stdin:
    v, w = list(map(int, e.split()))
    for i in range(W, w - 1, -1):
        t = v + C[i - w]
        if t > C[i]:
            C[i] = t
print((C[W]))

-N, W = list(map(int, input().split())) -I = [[*list(map(int, input().split()))] for _ in [0] * N] +import sys + +W = int(input().split()[1]) -for i in range(1, N + 1): -    v, w = I[~-i] -    for j in range(W, w - 1, -1): -        t = v + C[j - w] -        if t > C[j]: -            C[j] = t +for e in sys.stdin: +    v, w = list(map(int, e.split())) +    for i in range(W, w - 1, -1): +        t = v + C[i - w] +        if t > C[i]: +            C[i] = t