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()))

C=[0]*-~W

for _ in[0]*N:

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

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

  t=v+C[i-w]

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

-import sys - -W = int(input().split()[1]) +N, W = list(map(int, input().split())) -for e in sys.stdin: -    v, w = list(map(int, e.split())) +for _ in [0] * N: +    v, w = list(map(int, input().split()))