#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair P; int main(){ int n, m, a; cin >> n >> m >> a; vector> v(n+1); for (int i = 0; i < m; i++) { int l, r, p; cin >> l >> r >> p; v[r].emplace_back(make_pair(l,p)); } ll res = 0; vector dp(n+1,0); for (int i = 1; i <= n; i++) { dp[i] = res - a; for (auto x : v[i]) { dp[i] = max(dp[i], dp[x.first - 1] + x.second - (i == n ? 0 : a)); } res = max(res, dp[i]); } cout << res << endl; return 0; }