func_code_string: #include <bits/stdc++.h>   using namespace std;   struct event {     long long int peakval;     long long int pos;     long long int time1;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, m, d;     cin >> n >> m >> d;     struct event e1[m + 1];     e1[0].time1 = 0;     for (long long int i = 1; i <= m; i++) {       cin >> e1[i].pos >> e1[i].peakval >> e1[i].time1;     }     long long int dp[2][n + 1];     for (long long int i = 1; i <= n; i++) {       dp[0][i] = 0;     }     deque<pair<long long int, long long int> > dq1;     long long int delta, store;     for (long long int i = 1; i <= m; i++) {       delta = e1[i].time1 - (e1[i - 1].time1);       delta *= d;       for (long long int j = 1; j <= min(delta + 1, n); j++) {         while (!dq1.empty() && dp[0][j] >= dq1.back().first) {           dq1.pop_back();           if (dq1.empty()) {             break;           }         }         dq1.push_back({dp[0][j], j});       }       for (long long int j = 1; j <= n; j++) {         while (dq1.front().second < (j - delta)) {           dq1.pop_front();         }         store = e1[i].peakval - fabs(e1[i].pos - j);         dp[1][j] = dq1.front().first + store;         if ((j + delta + 1) <= n) {           while (dp[0][j + delta + 1] >= dq1.back().first) {             dq1.pop_back();             if (dq1.empty()) {               break;             }           }           dq1.push_back({dp[0][j + delta + 1], j + delta + 1});         }       }       for (long long int i = 1; i <= n; i++) {         dp[0][i] = dp[1][i];       }       dq1.clear();     }     long long int ans = -1000000000000000007;     for (long long int i = 1; i <= n; i++) {       ans = max(ans, dp[1][i]);     }     cout << ans;     return 0;   }   