#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m, A, l, r, c; cin >> n >> m >> A; vector>> g(n); for(int i = 0; i < m; i++){ cin >> l >> r >> c; l--, r--; g[l].emplace_back(r, c); } const ll INF = 1ll << 60; vector> dp(n, array({-INF, -INF, -INF})); dp[0][0] = dp[0][1] = dp[0][2] = 0; for(int i = 0; i + 1 < n; i++){ for(auto &&pa : g[i]){ tie(r, c) = pa; dp[r][2] = max(dp[r][2], dp[i][1] + c); } dp[i + 1][0] = max(dp[i + 1][0], dp[i][0]); dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] - A); dp[i + 1][0] = max(dp[i + 1][0], dp[i][2] - A); dp[i + 1][1] = max(dp[i + 1][1], dp[i][2] - A); } cout << *max_element(dp[n - 1].begin(), dp[n - 1].end()) << '\n'; }