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