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

item = [list(map(int, input().split())) for _ in range(N)]



dp = [[0]*100100 for _ in range(110)]



for i in range(N):

    for sum_w in range(W+1):

        weight, value = item[i]

        if sum_w - weight >= 0:

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



        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()))

dp = [[0]*100100 for _ in range(110)]



for i in range(N):

    weight, value = list(map(int, input().split()))

    for sum_w in range(W+1):

        if sum_w - weight >= 0:

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



        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()))
item = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * 100100 for _ in range(110)]
for i in range(N):
    for sum_w in range(W + 1):
        weight, value = item[i]
        if sum_w - weight >= 0:
            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - weight] + value)
        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()))
dp = [[0] * 100100 for _ in range(110)]
for i in range(N):
    weight, value = list(map(int, input().split()))
    for sum_w in range(W + 1):
        if sum_w - weight >= 0:
            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - weight] + value)
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
print((dp[N][W]))

-item = [list(map(int, input().split())) for _ in range(N)] +    weight, value = list(map(int, input().split())) -        weight, value = item[i]