n, w = list(map(int, input().split(' ')))

items = [[]] * n

for i in range(n):

  weight, val = list(map(int, input().split(' ')))

  items[i] = [weight, val]



# print(n, w)

# print(items)



dp = []

for i in range(n+1):

  dp.append([])

  for j in range(w+1):

  	dp[i].append(0)



# print(len(dp), len(dp[0]), dp[0][0])



for i in range(n):

  weight , val = items[i]

  for sum_w in range(w+1):

    # i番目のアイテムを選択する

    if sum_w - weight >= 0:

      dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - weight] + val)

    # i番目のアイテムを選択しない

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

print((dp[n][w]))
n, w = list(map(int, input().split()))

wl = [0] * n

vl = [0] * n

for i in range(n):

  wl[i], vl[i] = list(map(int, input().split()))



dp = [[]] * (n+1)

for i in range(n+1):

  dp[i] = [0] * (w+1)



for i in range(n):

  for j in range(w+1):

    if j >= wl[i]:

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

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



print((dp[n][w]))

#for i in range(n+1):

#  print(dp[i])
n, w = list(map(int, input().split(" ")))
items = [[]] * n
for i in range(n):
    weight, val = list(map(int, input().split(" ")))
    items[i] = [weight, val]
# print(n, w)
# print(items)
dp = []
for i in range(n + 1):
    dp.append([])
    for j in range(w + 1):
        dp[i].append(0)
# print(len(dp), len(dp[0]), dp[0][0])
for i in range(n):
    weight, val = items[i]
    for sum_w in range(w + 1):
        # i番目のアイテムを選択する
        if sum_w - weight >= 0:
            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - weight] + val)
        # i番目のアイテムを選択しない
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
print((dp[n][w]))

n, w = list(map(int, input().split()))
wl = [0] * n
vl = [0] * n
for i in range(n):
    wl[i], vl[i] = list(map(int, input().split()))
dp = [[]] * (n + 1)
for i in range(n + 1):
    dp[i] = [0] * (w + 1)
for i in range(n):
    for j in range(w + 1):
        if j >= wl[i]:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - wl[i]] + vl[i])
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])
print((dp[n][w]))
# for i in range(n+1):
#  print(dp[i])

-n, w = list(map(int, input().split(" "))) -items = [[]] * n +n, w = list(map(int, input().split())) +wl = [0] * n +vl = [0] * n -    weight, val = list(map(int, input().split(" "))) -    items[i] = [weight, val] -# print(n, w) -# print(items) -dp = [] +    wl[i], vl[i] = list(map(int, input().split())) +dp = [[]] * (n + 1) -    dp.append([]) +    dp[i] = [0] * (w + 1) +for i in range(n): -        dp[i].append(0) -# print(len(dp), len(dp[0]), dp[0][0]) -for i in range(n): -    weight, val = items[i] -    for sum_w in range(w + 1): -        # i番目のアイテムを選択する -        if sum_w - weight >= 0: -            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - weight] + val) -        # i番目のアイテムを選択しない -        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w]) +        if j >= wl[i]: +            dp[i + 1][j] = max(dp[i][j], dp[i][j - wl[i]] + vl[i]) +        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]) +# for i in range(n+1): +#  print(dp[i])