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

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



dp=[[0]*(W+1) for _ in range(N+1)]





for w in range(W+1):

    for n in range(N):

        if w>=wv[n][0]:

            dp[n+1][w] += max(dp[n][w-wv[n][0]]+wv[n][1], dp[n][w])

        else:

            dp[n+1][w]=dp[n][w]



print((dp[-1][-1]))

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+1)]



for i in range(W+1):

    for g in range(N):

        if i>=w[g]:

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

        else:

            dp[g+1][i]=dp[g][i]

print((dp[N][W]))

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

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 + 1)]
for i in range(W + 1):
    for g in range(N):
        if i >= w[g]:
            dp[g + 1][i] = max(dp[g][i], v[g] + dp[g][i - w[g]])
        else:
            dp[g + 1][i] = dp[g][i]
print((dp[N][W]))

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