import sys input = sys.stdin.readline class SegmentTree: def __init__(self, N, func, ele): n_ = 1 while n_0: k = (k-1)//2 self.arr[k] = self.func(self.arr[2*k+1], self.arr[2*k+2]) def query(self, l, r): L, R = l+self.n, r+self.n res = self.ele while L>= 1 R >>= 1 return res N, M, A = map(int, input().split()) lrp = [tuple(map(int, input().split())) for _ in range(M)] lrp.sort(key=lambda k: k[0]) dp = [-10**18]*N st = SegmentTree(N, max, -10**18) ans = 0 for li, ri, pi in lrp: li -= 1 ri -= 1 if li==0: dp[ri] = max(dp[ri], pi-A) else: dp[ri] = max(dp[ri], pi-2*A) dp[ri] = max(dp[ri], st.query(0, li)+pi-2*A) dp[ri] = max(dp[ri], dp[li-1]+pi-A) st.update(ri, dp[ri]) if ri==N-1: ans = max(ans, dp[ri]+A) else: ans = max(ans, dp[ri]) print(ans)