N, W, D = map(int, input().split()) stones = [list(map(int, input().split())) for _ in range(N)] dp = [[-1 for _ in range(W+1)] for _ in range(N+1)] dp[0][0] = 0 for i in range(N): t, w, v = stones[i] for j in range(W-w+1): if dp[i][j] != -1: dp[i+1][j+w] = max(dp[i+1][j+w], dp[i][j] + v) answer = max(dp[N]) print(answer)