#include <bits/stdc++.h>
using namespace std;
const int V = 150100;
const long long ooo = 1000000000;
const long long oo = ooo * ooo;
long long val[V], tr[V];
int AB(int x) {
  if (x < 0) return -x;
  return x;
}
int N;
void update(int k, long long v) {
  while (k <= N) {
    tr[k] = max(tr[k], v);
    k += k & -k;
  }
}
long long read(int k) {
  long long ret = -oo;
  while (k) {
    ret = max(ret, tr[k]);
    k -= k & -k;
  }
  return ret;
}
int n, m, d, a, b, t;
int main() {
  while (~scanf("%d%d%d", &n, &m, &d)) {
    memset(val, 0, sizeof(val));
    memset(tr, 0, sizeof(tr));
    int tm = 1;
    N = n;
    while (m--) {
      scanf("%d%d%d", &a, &b, &t);
      long long ds = (long long)d * (t - tm);
      int p = n;
      for (int i = n; i > 0; i--) tr[i] = -oo;
      for (int i = n; i > 0; i--) {
        int l = max(1LL, i - ds);
        int r = min((long long)n, i + ds);
        while (p >= l) {
          update(p, val[p]);
          p--;
        }
        val[i] = read(r) + b - AB(a - i);
      }
      tm = t;
    }
    long long ret = -oo;
    for (int i = 1; i <= n; i++) ret = max(ret, val[i]);
    cout << ret << endl;
  }
  return 0;
}
