#include <bits/stdc++.h>
using namespace std;
int n, m, d, a, b, t, a2, b2, t2, k, x, y;
int q[1510000], l, r;
long long f[2][151000], p;
void init() {
  scanf("%d%d%d", &n, &m, &d);
  x = 1;
  y = 0;
  memset(f, 0, sizeof(f));
  a2 = b2 = 0;
  t2 = 1;
}
void work() {
  while (m--) {
    x ^= 1;
    y ^= 1;
    memset(f[y], 243, sizeof(f[y]));
    scanf("%d%d%d", &a, &b, &t);
    p = (long long)d * (t - t2);
    if (p > n) p = n;
    l = 1;
    r = 0;
    for (int i = (1); i <= (p); ++i) {
      while (l <= r && f[x][q[r]] <= f[x][i]) r--;
      q[++r] = i;
    }
    for (int i = (1); i <= (n); ++i) {
      k = p + i;
      if (k <= n) {
        while (l <= r && f[x][q[r]] <= f[x][k]) r--;
        q[++r] = k;
      }
      while (l <= r && abs(i - q[l]) > p) l++;
      f[y][i] = f[x][q[l]];
      f[y][i] += b - abs(a - i);
    }
    a2 = a;
    b2 = b;
    t2 = t;
  }
  long long ans = -100000000;
  ans *= 10000000;
  for (int i = (1); i <= (n); ++i)
    if (f[y][i] >= ans) ans = f[y][i];
  cout << ans;
}
int main() {
  init();
  work();
  return 0;
}
