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

weight=[0]*N

values=[0]*N

for i in range(N):

  weight[i],values[i]=list(map(int,input().split()))



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



for i in range(N):

  for w in range(W+1):

    if w>=weight[i]:

      dp[i+1][w]=max(dp[i][w],dp[i][w-weight[i]]+values[i])

    else:

      dp[i+1][w]=dp[i][w]

      

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

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

stones=[None]*n

for i in range(n):

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

  stones[i]=[w,v]



import numpy as np

dp=np.zeros(W+1,dtype=int)



for i in range(len(stones)):

  w=stones[i][0]

  v=stones[i][1]

  np.maximum(dp[:-w]+v,dp[w:],dp[w:])



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

n, W = list(map(int, input().split()))
stones = [None] * n
for i in range(n):
    w, v = list(map(int, input().split()))
    stones[i] = [w, v]
import numpy as np

dp = np.zeros(W + 1, dtype=int)
for i in range(len(stones)):
    w = stones[i][0]
    v = stones[i][1]
    np.maximum(dp[:-w] + v, dp[w:], dp[w:])
print((dp.max()))

-N, W = list(map(int, input().split())) -weight = [0] * N -values = [0] * N -for i in range(N): -    weight[i], values[i] = list(map(int, input().split())) -dp = [[0 for i in range(W + 1)] for j in range(N + 1)] -for i in range(N): -    for w in range(W + 1): -        if w >= weight[i]: -            dp[i + 1][w] = max(dp[i][w], dp[i][w - weight[i]] + values[i]) -        else: -            dp[i + 1][w] = dp[i][w] -print((dp[N][W])) +n, W = list(map(int, input().split())) +stones = [None] * n +for i in range(n): +    w, v = list(map(int, input().split())) +    stones[i] = [w, v] +import numpy as np + +dp = np.zeros(W + 1, dtype=int) +for i in range(len(stones)): +    w = stones[i][0] +    v = stones[i][1] +    np.maximum(dp[:-w] + v, dp[w:], dp[w:]) +print((dp.max()))