N, volume = map(int, input().split())
dp = [0 for _ in range(volume + 1)]
for _ in range(N):
volume_, price, num = map(int, input().split())
for v in range(volume, 0, -1):
for k in range(num + 1):
if v >= k * volume_:
dp[v] = max(dp[v], dp[v - k * volume_] + k * price)
print(dp[-1])