#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) const long long INF = 1LL<<60; long long dp[100000+1][2]; vector > v[100000+1]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, a; cin >> n >> m >> a; for (int i = 0; i < m; i++) { int l, r, p; cin >> l >> r >> p; v[r].emplace_back(--l, p); } for (int i = 0; i <= n; i++) for (int j = 0; j < 2; j++) dp[i][j] = -INF; dp[0][0] = dp[0][1] = 0; for (int i = 1; i <= n; i++) { dp[i][0] = max(dp[i-1][0], dp[i-1][1]); for (auto &[l, p]: v[i]) { if (dp[l][1] != -INF) dp[i][1] = max(dp[i][1], dp[l][1] + p - (i == n ? 0 : a)); dp[i][1] = max(dp[i][1], dp[l][0] + p - (i == n ? a : 2 * a)); } } cout << max(dp[n][0], dp[n][1]) << endl; return 0; }