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

S = [[0 for j in range(2)] for i in range(N+1)]



DP= [[0 for j in range(100010)] for i in range(110)]

def chmax(a,b):

    if a>b:

        return a

    else:

        return b





for i in range(N):

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

    S[i][0]=w

    S[i][1]=v





for i in range(N):

    for j in range(W+1):

        if j-S[i][0]>=0:

            

            DP[i+1][j]=chmax(DP[i][j],DP[i][j-S[i][0]]+S[i][1])

        

        else:

            DP[i+1][j]=DP[i][j]

        

print((DP[N][W]))



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

w=[]

v=[]

jmax=100010

nmax=110



for i in range(N):

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

    w.append(a)

    v.append(b)

    

DP= [[0 for j in range(jmax)] for i in range(nmax)]





def chmax(a,b):

    if a>b:

        return a

    else:

        return b





for i in range(N):

    for j in range(jmax):

        if  j-w[i]>=0:

            DP[i+1][j]=chmax(DP[i][j],DP[i][j-w[i]]+v[i])

        else:

            DP[i+1][j]=DP[i][j]



            

print((DP[N][W]))
N, W = list(map(int, input().split()))
S = [[0 for j in range(2)] for i in range(N + 1)]
DP = [[0 for j in range(100010)] for i in range(110)]


def chmax(a, b):
    if a > b:
        return a
    else:
        return b


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

N, W = list(map(int, input().split()))
w = []
v = []
jmax = 100010
nmax = 110
for i in range(N):
    a, b = list(map(int, input().split()))
    w.append(a)
    v.append(b)
DP = [[0 for j in range(jmax)] for i in range(nmax)]


def chmax(a, b):
    if a > b:
        return a
    else:
        return b


for i in range(N):
    for j in range(jmax):
        if j - w[i] >= 0:
            DP[i + 1][j] = chmax(DP[i][j], DP[i][j - w[i]] + v[i])
        else:
            DP[i + 1][j] = DP[i][j]
print((DP[N][W]))

-S = [[0 for j in range(2)] for i in range(N + 1)] -DP = [[0 for j in range(100010)] for i in range(110)] +w = [] +v = [] +jmax = 100010 +nmax = 110 +for i in range(N): +    a, b = list(map(int, input().split())) +    w.append(a) +    v.append(b) +DP = [[0 for j in range(jmax)] for i in range(nmax)] -    w, v = list(map(int, input().split())) -    S[i][0] = w -    S[i][1] = v -for i in range(N): -    for j in range(W + 1): -        if j - S[i][0] >= 0: -            DP[i + 1][j] = chmax(DP[i][j], DP[i][j - S[i][0]] + S[i][1]) +    for j in range(jmax): +        if j - w[i] >= 0: +            DP[i + 1][j] = chmax(DP[i][j], DP[i][j - w[i]] + v[i])