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

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



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



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

  for j in range(1,w+1):

    if item[i-1][0] <= j:

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

    else:

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

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

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



dp = [[0 for i in range(W + 1)] for j in range(N + 1)]



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

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

    for j in range(1, W + 1):

        if j - w >= 0:

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

        else:

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



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

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

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