n,m = map(int, input().split())
v = []
w = []
s = []
for _ in range(n):
a,b,c = map(int,input().split())
v.append(a)
w.append(b)
s.append(c)
f = [[0 for _ in range(m+1)] for _ in range(n)]
for i in range(n):
for j in range(m+1):
t = s[i] if int(j/v[i]) > s[i] else int(j/v[i])
for k in range(t+1):
f[i][j] = max(f[i][j], f[i-1][j-k* v[i]] + k * w[i] )
print(f[n-1][m])