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()))



def chmax(a, b):

    if a >= b:

        return a

    else:

        return b



dp = [[0]*(10**5 + 10) for _ in range(110)]



#i個の品物を入れて重さがjになっているときの価値の総和の最大値

#dp[i+1][j] = dp[i][j - w[i] + v[i]] 入れるとき

#dp[i+1][j] = dp[i][j] 入れないとき



#dp[0][j] = 0 初期値設定でOK

for i in range(N+1):

    for j in range(W+1):

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

        if (i < N):

            if (j >= w[i]):

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



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

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



def chmax(a,b):

    if a >= b:

        return a

    else:

        return b

# dp[i+1][w]: i番目までの品物を選びその重さがwを超えないときの最大価値

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



for i in range(N):

    for w in range(W+1):

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

        

        if w - wv[i][0] >= 0:

            dp[i+1][w] = chmax(dp[i][w - wv[i][0]] + wv[i][1], dp[i][w])



print((dp[N][W]))
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()))


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


dp = [[0] * (10**5 + 10) for _ in range(110)]
# i個の品物を入れて重さがjになっているときの価値の総和の最大値
# dp[i+1][j] = dp[i][j - w[i] + v[i]] 入れるとき
# dp[i+1][j] = dp[i][j] 入れないとき
# dp[0][j] = 0 初期値設定でOK
for i in range(N + 1):
    for j in range(W + 1):
        dp[i + 1][j] = chmax(dp[i + 1][j], dp[i][j])
        if i < N:
            if j >= w[i]:
                dp[i + 1][j] = chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i])
print((dp[N][W]))

N, W = list(map(int, input().split()))
wv = [list(map(int, input().split())) for _ in range(N)]  # 1-index


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


# dp[i+1][w]: i番目までの品物を選びその重さがwを超えないときの最大価値
dp = [[0] * (W + 10) for _ in range(N + 10)]
for i in range(N):
    for w in range(W + 1):
        dp[i + 1][w] = dp[i][w]
        if w - wv[i][0] >= 0:
            dp[i + 1][w] = chmax(dp[i][w - wv[i][0]] + wv[i][1], dp[i][w])
print((dp[N][W]))

-w = [0] * N -v = [0] * N -for i in range(N): -    w[i], v[i] = list(map(int, input().split())) +wv = [list(map(int, input().split())) for _ in range(N)]  # 1-index -dp = [[0] * (10**5 + 10) for _ in range(110)] -# i個の品物を入れて重さがjになっているときの価値の総和の最大値 -# dp[i+1][j] = dp[i][j - w[i] + v[i]] 入れるとき -# dp[i+1][j] = dp[i][j] 入れないとき -# dp[0][j] = 0 初期値設定でOK -for i in range(N + 1): -    for j in range(W + 1): -        dp[i + 1][j] = chmax(dp[i + 1][j], dp[i][j]) -        if i < N: -            if j >= w[i]: -                dp[i + 1][j] = chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]) +# dp[i+1][w]: i番目までの品物を選びその重さがwを超えないときの最大価値 +dp = [[0] * (W + 10) for _ in range(N + 10)] +for i in range(N): +    for w in range(W + 1): +        dp[i + 1][w] = dp[i][w] +        if w - wv[i][0] >= 0: +            dp[i + 1][w] = chmax(dp[i][w - wv[i][0]] + wv[i][1], dp[i][w])