N,M,a = map(int,input().split()) D = [[] for _ in range(N+1)] for _ in range(M): l,r,p = map(int,input().split()) D[r].append((l,p)) dp = [0]*(N+1) for i in range(1,N+1): dp[i] = dp[i-1] if len(D[i])>0: for l,p in D[i]: if l==1 or dp[l-1]>dp[l-2]: if ia: dp[i] = max(dp[i],dp[l-1]+p-a) elif i==N: dp[i] = max(dp[i],dp[l-1]+p) else: if i2*a: dp[i] = max(dp[i],dp[l-1]+p-2*a) elif i==N and p>a: dp[i] = max(dp[i],dp[l-1]+p-a) print(dp[N])