n,c=gets.split.map &:to_i l=gets.split.map &:to_i w=gets.split.map &:to_i r=0..50 d=(0..150).map{r.map{[0]*51}} n.times{|i|n.times{|j|n.times{|k|d[b=w[i]+w[j]+w[k]][y=l[j]][z=l[k]]=[d[b][y][z],(x=l[i])!=z&&0<(x-y)*(z-y)?x+y+z:0].max}}} r.each{|a|r.each{|x|r.each{|y|n.times{|i|d[b=a+w[i]][y][z=l[i]]=[d[b][y][z],(e=d[a][x][y])>0&&x!=z&&0<(x-y)*(z-y)?e+z:0].max}}}} p d[0,c+1].map{|f|f.map(&:max).max}.max