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

lis = [[0, 0]]

for i in  range(n):

    lis.append(list(map(int, input().split())))



dp = [[0 for i in range(w+1)] for i in range(n+1)]

#print(dp)

#print(lis)



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

    for j in range(w+1):

        if j - lis[i][0] < 0:

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

        else:

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

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

w = [0] * n

v = [0] * n

for i in range(n):

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



dp = [[0] * (W + 1) for i in range(n)]

for i in range(n):

    for j in range(W+1):

        if j - w[i] < 0:

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

        else:

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

#print(dp)

print((dp[n-1][W]))
n, w = list(map(int, input().split()))
lis = [[0, 0]]
for i in range(n):
    lis.append(list(map(int, input().split())))
dp = [[0 for i in range(w + 1)] for i in range(n + 1)]
# print(dp)
# print(lis)
for i in range(1, n + 1):
    for j in range(w + 1):
        if j - lis[i][0] < 0:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - lis[i][0]] + lis[i][1])
print((dp[n][w]))

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

-n, w = list(map(int, input().split())) -lis = [[0, 0]] +n, W = list(map(int, input().split())) +w = [0] * n +v = [0] * n -    lis.append(list(map(int, input().split()))) -dp = [[0 for i in range(w + 1)] for i in range(n + 1)] -# print(dp) -# print(lis) -for i in range(1, n + 1): -    for j in range(w + 1): -        if j - lis[i][0] < 0: +    w[i], v[i] = list(map(int, input().split())) +dp = [[0] * (W + 1) for i in range(n)] +for i in range(n): +    for j in range(W + 1): +        if j - w[i] < 0: -            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - lis[i][0]] + lis[i][1]) -print((dp[n][w])) +            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]) +# print(dp) +print((dp[n - 1][W]))