func_code_string: #include <bits/stdc++.h>   using namespace std;   const int INF = (int)2e9;   const long long INFL = (long long)9e18;   const int MAXINT = ((~0) ^ (1 << 31));   const long long MAXLL = ((~0) ^ ((long long)1 << 63));   template <class T>   inline T pow2(T a) {     return a * a;   }   template <class T>   inline bool mineq(T& a, T b) {     return (a > b) ? (a = b, true) : false;   }   template <class T>   inline bool maxeq(T& a, T b) {     return (a < b) ? (a = b, true) : false;   }   const int maxn = 2e5 + 100;   long long n, m, d, lt, a, b, t;   long long dp[2 * maxn];   long long rmq[2 * maxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> d;     for (int i = 0; i < (int)(m); i++) {       cin >> a >> b >> t;       t = t - lt;       lt = lt + t;       long long gap = min(n, t * d);       deque<int> stk;       for (int i = 0; i < (int)(2 * n); i++) {         while (!stk.empty() && dp[stk.back()] <= dp[i]) stk.pop_back();         if (!stk.empty() && stk.front() == i - 2 * gap - 1) stk.pop_front();         stk.push_back(i);         rmq[i] = dp[stk.front()];       }       for (int i = 0; i < (int)(n); i++) {         dp[i] = rmq[i + gap] + b - abs(a - i - 1);       }       for (int i = n; i < (int)(2 * n); i++) dp[i] = -INF / 2;     }     cout << *max_element(dp, dp + n) << endl;   }   