def main(): import sys input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr +=1 M = int(input[ptr]) ptr +=1 A = int(input[ptr]) ptr +=1 intervals_by_r = [[] for _ in range(N+2)] # r can be up to N for _ in range(M): l = int(input[ptr]) ptr +=1 r = int(input[ptr]) ptr +=1 p = int(input[ptr]) ptr +=1 intervals_by_r[r].append( (l, p) ) dp = [-float('inf')] * (N+1) # since i ranges from 0 to N dp[0] = 0 current_max = 0 # max dp[j] for j < i for i in range(1, N+1): cost = A if i != N else 0 case_b = current_max - cost case_a = -float('inf') for (l, p) in intervals_by_r[i]: j = l -1 if j >=0 and dp[j] != -float('inf'): temp = dp[j] + p - cost if temp > case_a: case_a = temp dp_i = max(case_a, case_b) dp[i] = dp_i if dp_i != -float('inf') else 0 # Handle case where both are -inf if i != N: if dp[i] > current_max: current_max = dp[i] print(max(dp[N], 0)) # Ensure non-negative result as per problem's examples if __name__ == '__main__': main()