#include using namespace std; #define int long long vector > vec[100010]; signed main(){ int n, m, a; cin >> n >> m >> a; for(int i = 0;i < m;i++){ int l, r, p; cin >> l >> r >> p; l--; vec[l].push_back(make_pair(r, p)); } int dp1[100010] = {}; int d1tmp[100010] = {}; int dp2[100010] = {}; for(int i = 0;i < 100010;i++){ dp1[i] = dp2[i] = -(1ll << 60); } dp1[0] = 0; dp2[0] = 0; d1tmp[0] = 1; for(int i = 0;i < n;i++){ for(int j = 0;j < vec[i].size();j++){ int l = i; int r = vec[i][j].first; int p = vec[i][j].second; if(d1tmp[l]){ dp1[r] = max(dp1[r], dp1[l]+p-(r == n ? 0 : a)); }else{ dp1[r] = max(dp1[r], dp1[l]+p-(r == n ? a : a*2)); } dp2[r] = max(dp2[r], dp2[l]+p-(r == n ? a : a*2)); dp1[r] = max(dp2[r], dp1[r]); d1tmp[r] = 1; } dp2[i+1] = max(dp2[i], dp2[i+1]); } int ans = 0; for(int i = 0;i <= n;i++){ ans = max(ans, max(dp1[i], dp2[i])); } cout << ans << endl; return 0; }