#include <bits/stdc++.h>
using namespace std;
const int N = 150000 + 10;
const int M = 300 + 10;
int n, m, d;
int a[M], b[M], t[M];
int now, pas, pre, dis;
long long f[2][N];
int head, tail;
long long g[N];
int w[N];
long long ans;
inline void Add(int pos, long long val) {
  while (head <= tail && val >= g[tail]) --tail;
  ++tail, g[tail] = val, w[tail] = pos;
}
int main() {
  scanf("%d %d %d ", &n, &m, &d);
  for (int i(0); i < (m); ++i) scanf("%d %d %d ", a + i, b + i, t + i);
  now = 1, pas = 0, pre = 1;
  for (int launch(0); launch < (m); ++launch) {
    dis = ((long long)d * (t[launch] - pre) < n) ? d * (t[launch] - pre) : n;
    pre = t[launch];
    swap(now, pas), head = 1, tail = 0;
    for (int i(1); i <= (dis); ++i) Add(i, f[pas][i]);
    for (int i(1); i <= (n); ++i) {
      if (i + dis <= n) Add(i + dis, f[pas][i + dis]);
      while (w[head] + dis < i) ++head;
      f[now][i] = g[head] + b[launch] - abs(a[launch] - i);
    }
  }
  ans = f[now][1];
  for (int i(2); i <= (n); ++i) ans = max(ans, f[now][i]);
  printf("%I64d\n", ans);
  return 0;
}
