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

v = [0] * (N+1)

w = [0] * (N+1)

dp = [[0 for x in range(W+1)] for y in range(N+1)]



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

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



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

    for j in range(W+1):

        if j < w[i]:

            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[N][W]))
N,W = list(map(int, input().split()))

dp = [[0 for x in range(W+1)] for y in range(N+1)]



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

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

    for j in range(W+1):

        if j < w:

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

        else:

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



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

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

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