n,m,a = map(int,input().split()) lrp = [[int(i)-1 for i in input().split()] for j in range(m)] lrp.sort() dp = [[-10**15]*2 for i in range(n+1)] dp[0][1] = 0 dp[n][1] = 0 for i in range(n): dp[i][0] = 0 for i in range(m): l,r,p = lrp[i] p += 1 r += 1 if l != 0: if r != n: dp[r][1] = max(0,dp[l][1]+p-a,dp[l][0]+p-2*a,dp[r][1]) else: dp[r][1] = max(0,dp[l][1]+p,dp[l][0]+p-a,dp[r][1]) else: if r != n: dp[r][1] = max(0,dp[l][1]+p-a,dp[l][0]+p-a,dp[r][1]) else: dp[r][1] = max(0,dp[l][1]+p,dp[l][0]+p,dp[r][1]) ans = 0 #print(dp) for i in range(n+1): ans = max(ans,dp[i][0],dp[i][1]) print(ans)