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

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

C=[[0]*-~W for _ in[0]*-~N]

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

 for w in range(1,W+1):

  C[i][w]=C[i-1][w]

  if w>=I[i][1]and I[i][0]+C[i-1][w-I[i][1]]>C[i-1][w]:

   C[i][w]=I[i][0]+C[i-1][w-I[i][1]]

print((C[N][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]))

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

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