#include <bits/stdc++.h>
using namespace std;
int m;
long long n, d;
long long f[150010];
pair<long long, long long> q[150010];
int l, r;
void push(pair<long long, long long> a) {
  while (r >= l && q[r].first > a.first) r--;
  q[++r] = a;
}
int main() {
  long long ans = 0;
  int lastt = 0;
  scanf("%I64d%d%I64d", &n, &m, &d);
  for (int i = 1; i <= m; i++) {
    long long a, b, t;
    l = 1, r = 0;
    scanf("%I64d%I64d%I64d", &a, &b, &t);
    ans += b;
    long long len = min((t - lastt) * d + 1, n);
    for (int j = 1; j <= len; j++) push(make_pair(f[j], j));
    int j = len + 1;
    for (int i = 1; i <= n; i++) {
      while (l <= r && q[l].second < i - len + 1) l++;
      f[i] = q[l].first + abs(a - i);
      if (j <= n) push(make_pair(f[j], j)), j++;
    }
    lastt = t;
  }
  long long t = 0x7fffffffffffffff;
  for (int i = 1; i <= n; i++) t = min(t, f[i]);
  ans -= t;
  printf("%I64d\n", ans);
  return 0;
}
