#include template inline bool cmx (T1& a, T2 b) { if (a < b) { a = b; return true; } return false; } int main() { std::cin.tie(0); std::cin.sync_with_stdio(false); int n, m, a; std::cin >> n >> m >> a; std::vector> itv; while (m--) { int l, r, p; std::cin >> l >> r >> p; l--; itv.emplace_back(l, r, p); } std::sort(itv.begin(), itv.end()); std::vector dp (n + 1, -a); std::vector cum(n + 1, -a); dp[0] = 0; int now = 1; for (auto [l, r, p] : itv) { for (; now <= l; now++) { cum[now] = std::max(cum[now - 1], dp[now - 1]); } cmx(dp[r], dp[l] + p - a); cmx(dp[r], cum[l] + p - a * 2); } for (; now <= n; now++) { cum[now] = std::max(cum[now - 1], dp[now - 1]); } long long ret = std::max(cum[n], dp[n] + a); std::cout << ret << std::endl; return 0; }