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

w = [None] * N

v = [None] * N



for i in range(N):

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



dp = [[-1] * (W + 1) for i in range(N + 1)]

dp[0][0] = 0



for i in range(N):

  for j in range(len(dp[i]) - 2, -1, -1):

    if dp[i][j] == -1:

      continue

    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

    if j + w[i] >= len(dp[i]):

      continue

    dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i])



print((max(dp[N])))
N,W = list(map(int,input().split()))



dp = [[-1] * (W + 1) for i in range(N + 1)]

dp[0][0] = 0



for i in range(N):

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

  for j in range(len(dp[i]) - 2, -1, -1):

    if dp[i][j] == -1:

      continue

    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])

    if j + w >= len(dp[i]):

      continue

    dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v)



print((max(dp[N])))
N, W = list(map(int, input().split()))
w = [None] * N
v = [None] * N
for i in range(N):
    w[i], v[i] = list(map(int, input().split()))
dp = [[-1] * (W + 1) for i in range(N + 1)]
dp[0][0] = 0
for i in range(N):
    for j in range(len(dp[i]) - 2, -1, -1):
        if dp[i][j] == -1:
            continue
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
        if j + w[i] >= len(dp[i]):
            continue
        dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i])
print((max(dp[N])))

N, W = list(map(int, input().split()))
dp = [[-1] * (W + 1) for i in range(N + 1)]
dp[0][0] = 0
for i in range(N):
    w, v = list(map(int, input().split()))
    for j in range(len(dp[i]) - 2, -1, -1):
        if dp[i][j] == -1:
            continue
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
        if j + w >= len(dp[i]):
            continue
        dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v)
print((max(dp[N])))

-w = [None] * N -v = [None] * N -for i in range(N): -    w[i], v[i] = list(map(int, input().split())) +    w, v = list(map(int, input().split())) -        if j + w[i] >= len(dp[i]): +        if j + w >= len(dp[i]): -        dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]) +        dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v)