#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, d;
  cin >> n >> m >> d;
  vector<int> a(m), b(m), t(m);
  for (int i = 0; i < int(m); i++) cin >> a[i] >> b[i] >> t[i];
  vector<long long> lst(n + 1);
  for (int i = int(1); i <= int(n); i++) lst[i] = b[m - 1] - abs(a[m - 1] - i);
  for (int idx = int(m - 2); idx >= 0; idx--) {
    vector<long long> dp(n + 1);
    long long diff = t[idx + 1] - t[idx];
    if (diff == 0) {
      for (int i = int(1); i <= int(n); i++)
        dp[i] = lst[i] + b[idx] - abs(a[idx] - i);
    } else {
      diff *= d;
      deque<int> dq;
      int j = 1;
      for (int i = int(1); i <= int(n); i++) {
        while (j <= n && abs(j - i) <= diff) {
          while (!dq.empty() && lst[dq.back()] <= lst[j]) dq.pop_back();
          dq.push_back(j);
          j++;
        }
        while (!dq.empty() && abs(dq.front() - i) > diff) dq.pop_front();
        dp[i] = lst[dq.front()] + b[idx] - abs(a[idx] - i);
      }
    }
    lst.swap(dp);
  }
  cout << *max_element(lst.begin() + 1, lst.end()) << '\n';
  return 0;
}
