#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; templateusing min_priority_queue = priority_queue, greater>; const ll MOD = 1e9 + 7; const ll inf = 1LL << 60; #define all(x) (x).begin(),(x).end() #define puts(x) cout << x << endl; #define rep(i,m,n) for(ll i = m;i < n;++i) #define pb push_back #define fore(i,a) for(auto &i:a) #define rrep(i,m,n) for(ll i = m;i >= n;--i) #define INF INT_MAX/2 //segtree const ll N = 1 << 18; ll seg[2 * N]; void st(ll p, ll v) { p += N - 1; seg[p] = v; while (p>0) { p = (p - 1) / 2; seg[p] = max(seg[2 * p + 1], seg[2 * p + 2]); } } ll query(ll l, ll r, ll a, ll b, ll k) { if (r <= a || b <= l)return -inf; if (l <= a && b <= r)return seg[k]; int m = (a + b) / 2; return max(query(l, r, a, m, 2 * k + 1), query(l, r, m, b, 2 * k + 2)); } //[l,r] ll get(int l, int r) { return query(l, r+1, 0, N, 0); } ll oneget(int i) { return get(i,i); } //endsegtree vector>R[101010]; int main() { ll n, m, a; cin >> n >> m >> a; rep(i, 0, m) { ll l, r, p; cin >> l >> r >> p; R[r].pb({ l,p }); } rep(i,0,n+1)st(i, -inf); st(0, 0); for (ll r = 1; r <= n; r++) { fore(pa, R[r]) { ll l = pa.first; ll p = pa.second; ll ma = -inf; ll fl = (r == n) ? 0 : a; ma = max(ma,oneget(l-1)-fl+p); ma = max(ma,get(0,l-2)-a-fl+p); st(r,max(oneget(r),ma)); } } puts(get(0, n)); return 0; }