N, M = map(int, input().split()) INF = 1 << 63 dp = [-INF] * (M + 1) dp[0] = 0 for i in range(N): dp2 = [-INF] * (M + 1) a, b, c = map(int, input().split()) for j in range(M + 1): if j >= a: dp2[j] = dp[j - a] + b * c for j in range(M + 1): if j >= a - b: dp2[j] = max(dp2[j], dp2[j - a + b] + b * c) for j in range(M + 1): dp2[j] = max(dp2[j], dp[j]) dp, dp2 = dp2, dp ans = 0 for a in dp[1:]: ans = max(ans, a) print(ans)