import sys #sys.setrecursionlimit((1<<19)-1) #import pypyjit #pypyjit.set_param('max_unroll_recursion=-1') input=sys.stdin.buffer.readline inf=(1<<61)-1 N,M=map(int,input().split()) can=[tuple(map(int,input().split())) for i in range(N)] dp=[-inf]*(M+1) dp[0]=0 for a,b,c in can: ndp=[-inf]*(M+1) for i in range(M+1): if i+a>M: break ndp[i+a]=dp[i]+b*c for i in range(M+1): if i+a-b>M: break ndp[i+a-b]=max(ndp[i+a-b],ndp[i]+b*c) for i in range(M+1): dp[i]=max(dp[i],ndp[i]) print(max(dp))