#include using i64 = long long; int main() { unsigned n, m; i64 a; std::cin >> n >> m >> a; std::vector, i64>> v; for (unsigned i = 0; i < m; i++) { int l, r; i64 p; std::cin >> l >> r >> p; v.emplace_back(std::piecewise_construct, std::make_tuple(r, l), std::make_tuple(p)); } std::sort(v.begin(), v.end()); std::vector> dp(n + 1, std::vector(2)); for (unsigned i = 1, j = 0; i <= n; i++) { dp[i][0] = std::max(dp[i - 1][0], dp[i - 1][1]); dp[i][1] = dp[1][0] - a; while (j < m && v[j].first.first == i) { dp[i][1] = std::max({ dp[i][1], dp[v[j].first.second - 1][0] + v[j].second - a * 2, dp[v[j].first.second - 1][1] + v[j].second - a }); j++; } } std::cout << std::max(dp[n][0], dp[n][1] + a) << std::endl; return 0; }