#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% N, M, A = map(int, readline().split()) m = map(int, read().split()) LRP = zip(m, m, m) # %% intervals = [[] for _ in range(N + 1)] for l, r, p in LRP: intervals[r].append((l, p)) # %% dp = [0] + [-A] * N dp_cummax = [0] * (N + 1) for r in range(1, N + 1): for l, p in intervals[r]: x = dp[l - 1] + p - A if dp[r] < x: dp[r] = x if l > 1: x = dp_cummax[l - 2] + p - 2 * A if dp[r] < x: dp[r] = x dp_cummax[r] = max(dp_cummax[r - 1], dp[r]) dp[N] += A # %% print(max(dp))