n,C=map(int,input().split()) L=50 V=list(map(int,input().split())) W=list(map(int,input().split())) q=[[[-1]*(L+1) for j in range(L+1)] for i in range(L+1)] for i1 in range(n): for i2 in range(n): v1,w1=V[i1],W[i1] v2,w2=V[i2],W[i2] if w1+w2<=C and v1!=v2: q[C-w1-w2][v1][v2]=v1+v2 ans=0 for c in reversed(range(L+1)): for v1 in range(L+1): for v2 in range(L+1): if q[c][v1][v2]!=-1: for i3 in range(n): v3,w3=V[i3],W[i3] if c-w3>=0 and v1!=v3 and v2!=v3: if v1v3 or v1>v2