#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 int main() { ll n, m, A; cin >> n >> m >> A; vector> v; rep(i,m){ pair p; cin >> p.first.first >> p.first.second >> p.second; v.push_back(p); } sort(v.begin(), v.end()); ll dp[n+1] = {}; srep(i,1,n) dp[i] = -A; rep(i,m){ int l = v[i].first.first; int r = v[i].first.second; ll p = v[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; }