var
n,v,z,k,c,w,i:longint;
f:array[0..40000]of longint;
procedure bp01(c,w:longint);
begin
for i:=v downto c do
if f[i]<f[i-c]+w then
f[i]:=f[i-c]+w;
end;
begin
assign(input,'treasure.in');
reset(input);
assign(output,'treasure.out');
rewrite(output);
read(n,v);
repeat
read(w,c,z);
if c*z>=v then
begin
for i:=c to v do
if f[i-c]+w>f[i] then f[i]:=f[i-c]+w
end
else
begin
k:=1;
while z>k do
begin
bp01(c*k,w*k);
dec(z,k);
k:=k<<1;
end;
bp01(z*c,z*w);
end;
dec(n);
until n=0;
writeln(f[v]);
close(input);
close(output);
end.