func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m, d;   long long din[2][150003];   long long a[303];   long long mx[150003];   long long b[303];   long long t[303];   deque<long long> deq;   int main() {     cin >> n >> m >> d;     t[0] = 0;     for (int i = 0; i < m; i++) {       cin >> a[i + 1] >> b[i + 1] >> t[i + 1];     }     for (int i = 1; i <= m; i++) {       deq.clear();       long long T = (t[i] - t[i - 1]) * d;       for (int j = 0; j < n && j < T; j++) {         while (deq.size() && deq.back() < din[(i - 1) % 2][j]) {           deq.pop_back();         }         deq.push_back(din[(i - 1) % 2][j]);       }       for (int j = 0; j < n; j++) {         if (T + j < n) {           while (deq.size() && deq.back() < din[(i - 1) % 2][T + j]) {             deq.pop_back();           }           deq.push_back(din[(i - 1) % 2][T + j]);         }         mx[j] = deq.front();         if (j - T >= 0 && deq.front() == din[(i - 1) % 2][j - T]) deq.pop_front();       }       for (int j = 0; j < n; j++) {         din[i % 2][j] = mx[j] + (b[i] - abs(a[i] - (j + 1)));       }     }     long long res = din[m % 2][0];     for (int i = 0; i < n; i++) {       if (din[m % 2][i] > res) res = din[m % 2][i];     }     cout << res << endl;     return 0;   }   