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

w,v=[],[]

for i in range(N):

  a,b=list(map(int,input().split()))

  w.append(a)

  v.append(b)

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

for i in range(N):

  for j in range(W+1):

      if j-w[i]>=0:

          dp[i+1][j]=dp[i][j-w[i]]+v[i]

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

print((dp[N][W]))
N,W=list(map(int,input().split()))

w,v=[],[]

for i in range(N):

  ww,vv=list(map(int,input().split()))

  w.append(ww)

  v.append(vv)

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



for i in range(N):

  for j in range(W+1):

    if j-w[i]>=0:

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

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



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

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

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

-    a, b = list(map(int, input().split())) -    w.append(a) -    v.append(b) +    ww, vv = list(map(int, input().split())) +    w.append(ww) +    v.append(vv) -            dp[i + 1][j] = dp[i][j - w[i]] + v[i] +            dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i + 1][j]) -print((dp[N][W])) +print((dp[-1][-1]))