#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair P; #define yn {puts("Yes");}else{puts("No");} #define MAX_N 200005 vector

G[MAX_N]; int main() { ll n, m, A; cin >> n >> m >> A; vector> v; rep(i,m){ int l, r, p; cin >> l >> r >> p; G[l].push_back(P(r,p)); } rep(i,MAX_N) sort(G[i].begin(), G[i].end()); ll dp[n+1] = {}; srep(i,1,n) dp[i] = -A; srep(j,1,n+1){ dp[j] = max(dp[j-1], dp[j]); rep(i,G[j].size()){ int l = j; int r = G[j][i].first; ll p = G[j][i].second; if(r == n){ dp[r] = max(dp[r], dp[l-1] + p); }else{ dp[r] = max(dp[r], dp[l-1] + p - A); } } } ll ans = 0; rep(i,n+1) ans = max(ans, dp[i]); cout << ans << endl; return 0; }