#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
static inline int Rint() {
  struct X {
    int dig[256];
    X() {
      for (int i = '0'; i <= '9'; ++i) dig[i] = 1;
      dig['-'] = 1;
    }
  };
  static X fuck;
  int s = 1, v = 0, c;
  for (; !fuck.dig[c = getchar()];)
    ;
  if (c == '-')
    s = 0;
  else if (fuck.dig[c])
    v = c ^ 48;
  for (; fuck.dig[c = getchar()]; v = v * 10 + (c ^ 48))
    ;
  return s ? v : -v;
}
template <typename T>
static inline void cmax(T& a, const T& b) {
  if (b > a) a = b;
}
template <typename T>
static inline void cmin(T& a, const T& b) {
  if (b < a) a = b;
}
const int maxn = 150000 + 50;
long long data[2][maxn];
long long curr[maxn];
struct Events {
  long long a, b, t;
  int operator<(const Events& o) const { return t > o.t; }
};
Events event[305];
struct Cmd {
  int pos, pos1;
  long long val;
  int operator<(const Cmd& o) const { return pos < o.pos; }
};
Cmd cmds[maxn << 1];
long long que[maxn];
int main() {
  long long* from = data[0];
  long long* to = data[1];
  const int n = Rint(), m = Rint(), d = Rint();
  for (int i = 0; i < m; ++i) {
    event[i].a = Rint();
    event[i].b = Rint();
    event[i].t = Rint();
  }
  sort(event, event + m);
  for (int i = 0; i < m;) {
    int j = i;
    fill(curr, curr + n + 1, 0);
    while (j < m && event[j].t == event[i].t) {
      for (int x = 1; x <= n; ++x) {
        curr[x] += event[j].b - abs(event[j].a - x);
      }
      ++j;
    }
    long long dist =
        (long long)d * (event[i].t - (i ? event[i - 1].t : event[i].t));
    dist = abs(dist);
    if (dist >= n - 1) {
      long long best = *max_element(from + 1, from + 1 + n);
      for (int j = 1; j <= n; ++j) to[j] = curr[j] + best;
    } else {
      int p = 0, q = 0;
      for (int j = 1, k = 1; j <= n; ++j) {
        long long l = max(1LL, j - dist);
        long long r = min((long long)n, j + dist);
        while (p < q && que[p] < l) ++p;
        while (k + 1 <= r) {
          const int who = k + 1;
          while (p < q && from[que[q - 1]] <= from[who]) --q;
          que[q++] = who;
          ++k;
        }
        to[j] = curr[j] + from[que[p]];
      }
    }
    swap(from, to);
    i = j;
  }
  cout << *max_element(from + 1, from + 1 + n) << endl;
  return 0;
}
