#include <bits/stdc++.h>
using namespace std;
int n, m, d;
long long cval[150005];
long long indx[150005];
int main() {
  scanf("%d %d %d", &n, &m, &d);
  int prev_tm = 0;
  int ai, bi, ti;
  while (m--) {
    scanf("%d %d %d", &ai, &bi, &ti);
    int k = (int)min((long long)n, (long long)(ti - prev_tm) * (long long)d);
    prev_tm = ti;
    deque<int> dq;
    for (int i = 1; i < (int)n + 1; i++) {
      while (!dq.empty() && dq.front() < (i - k)) dq.pop_front();
      while (!dq.empty() && cval[dq.back()] < cval[i]) dq.pop_back();
      dq.push_back(i);
      indx[i] = cval[dq.front()];
    }
    dq.clear();
    for (int i = n; i > 0; i--) {
      while (!dq.empty() && dq.front() > (i + k)) dq.pop_front();
      while (!dq.empty() && cval[dq.back()] < cval[i]) dq.pop_back();
      dq.push_back(i);
      indx[i] = max(indx[i], cval[dq.front()]);
    }
    for (int i = 1; i < (int)n + 1; i++) {
      cval[i] = indx[i] + bi - abs(ai - i);
    }
  }
  long long ans = -1000000000000000000LL;
  for (int i = 1; i < (int)n + 1; i++) ans = max(ans, cval[i]);
  cout << ans << endl;
  return 0;
}
