INFTY = 10**10

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

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

dp = [[[-INFTY for _ in range(3*(N-1)+1)] for _ in range(N+1)] for _ in range(N+1)]

for i in range(N+1):

    dp[i][0][0] = 0

for i in range(1,N+1):

    for j in range(1,i+1):

        for k in range(3*(N-1)+1):

            dp[i][j][k] = dp[i-1][j][k]

            if k>=X[i-1][0]-X[0][0]:

                dp[i][j][k] = max(dp[i][j][k],dp[i-1][j-1][k-X[i-1][0]+X[0][0]]+X[i-1][1])

cmax = 0

for j in range(1,N+1):

    for k in range(3*(N-1)+1):

        if j*X[0][0]+k<=W:

            cmax = max(cmax,dp[N][j][k])

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

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

w1 = A[0][0]

C = {0:[],1:[],2:[],3:[]}

for i in range(N):

    w,v = A[i]

    C[w-w1].append(v)

C[0] = sorted(C[0],reverse=True)

C[1] = sorted(C[1],reverse=True)

C[2] = sorted(C[2],reverse=True)

C[3] = sorted(C[3],reverse=True)

n0 = len(C[0])

n1 = len(C[1])

n2 = len(C[2])

n3 = len(C[3])

vmax = 0

for a0 in range(n0+1):

    for a1 in range(n1+1):

        for a2 in range(n2+1):

            for a3 in range(n3+1):

                if a0*w1+a1*(w1+1)+a2*(w1+2)+a3*(w1+3)<=W:

                    v = sum(C[0][:a0])+sum(C[1][:a1])+sum(C[2][:a2])+sum(C[3][:a3])

                    vmax = max(vmax,v)

print(vmax)
INFTY = 10**10
N, W = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
dp = [
    [[-INFTY for _ in range(3 * (N - 1) + 1)] for _ in range(N + 1)]
    for _ in range(N + 1)
]
for i in range(N + 1):
    dp[i][0][0] = 0
for i in range(1, N + 1):
    for j in range(1, i + 1):
        for k in range(3 * (N - 1) + 1):
            dp[i][j][k] = dp[i - 1][j][k]
            if k >= X[i - 1][0] - X[0][0]:
                dp[i][j][k] = max(
                    dp[i][j][k],
                    dp[i - 1][j - 1][k - X[i - 1][0] + X[0][0]] + X[i - 1][1],
                )
cmax = 0
for j in range(1, N + 1):
    for k in range(3 * (N - 1) + 1):
        if j * X[0][0] + k <= W:
            cmax = max(cmax, dp[N][j][k])
print(cmax)

N, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
w1 = A[0][0]
C = {0: [], 1: [], 2: [], 3: []}
for i in range(N):
    w, v = A[i]
    C[w - w1].append(v)
C[0] = sorted(C[0], reverse=True)
C[1] = sorted(C[1], reverse=True)
C[2] = sorted(C[2], reverse=True)
C[3] = sorted(C[3], reverse=True)
n0 = len(C[0])
n1 = len(C[1])
n2 = len(C[2])
n3 = len(C[3])
vmax = 0
for a0 in range(n0 + 1):
    for a1 in range(n1 + 1):
        for a2 in range(n2 + 1):
            for a3 in range(n3 + 1):
                if a0 * w1 + a1 * (w1 + 1) + a2 * (w1 + 2) + a3 * (w1 + 3) <= W:
                    v = (
                        sum(C[0][:a0])
                        + sum(C[1][:a1])
                        + sum(C[2][:a2])
                        + sum(C[3][:a3])
                    )
                    vmax = max(vmax, v)
print(vmax)

-INFTY = 10**10 -X = [list(map(int, input().split())) for _ in range(N)] -dp = [ -    [[-INFTY for _ in range(3 * (N - 1) + 1)] for _ in range(N + 1)] -    for _ in range(N + 1) -] -for i in range(N + 1): -    dp[i][0][0] = 0 -for i in range(1, N + 1): -    for j in range(1, i + 1): -        for k in range(3 * (N - 1) + 1): -            dp[i][j][k] = dp[i - 1][j][k] -            if k >= X[i - 1][0] - X[0][0]: -                dp[i][j][k] = max( -                    dp[i][j][k], -                    dp[i - 1][j - 1][k - X[i - 1][0] + X[0][0]] + X[i - 1][1], -                ) -cmax = 0 -for j in range(1, N + 1): -    for k in range(3 * (N - 1) + 1): -        if j * X[0][0] + k <= W: -            cmax = max(cmax, dp[N][j][k]) -print(cmax) +A = [list(map(int, input().split())) for _ in range(N)] +w1 = A[0][0] +C = {0: [], 1: [], 2: [], 3: []} +for i in range(N): +    w, v = A[i] +    C[w - w1].append(v) +C[0] = sorted(C[0], reverse=True) +C[1] = sorted(C[1], reverse=True) +C[2] = sorted(C[2], reverse=True) +C[3] = sorted(C[3], reverse=True) +n0 = len(C[0]) +n1 = len(C[1]) +n2 = len(C[2]) +n3 = len(C[3]) +vmax = 0 +for a0 in range(n0 + 1): +    for a1 in range(n1 + 1): +        for a2 in range(n2 + 1): +            for a3 in range(n3 + 1): +                if a0 * w1 + a1 * (w1 + 1) + a2 * (w1 + 2) + a3 * (w1 + 3) <= W: +                    v = ( +                        sum(C[0][:a0]) +                        + sum(C[1][:a1]) +                        + sum(C[2][:a2]) +                        + sum(C[3][:a3]) +                    ) +                    vmax = max(vmax, v) +print(vmax)