#include <bits/stdc++.h>
using namespace std;
const int MAXM = 305;
const int MAXN = 150010;
int n, m, d;
int a[MAXN], b[MAXM], t[MAXN];
long long ans, tmp = 998244353998244353;
int f[2][MAXN], o;
int que[MAXN], id[MAXN], l, r;
int main() {
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a[i], &b[i], &t[i]);
    ans += b[i];
  }
  for (int i = 1; i <= m; i++) {
    o ^= 1;
    l = 1;
    r = 0;
    long long dt = 1LL * (t[i] - t[i - 1]) * d;
    for (int j = 1; j <= n; j++) {
      f[o][j] = f[o ^ 1][j];
      while (l <= r && j - id[l] > dt) l++;
      if (l <= r) f[o][j] = min(f[o][j], que[l]);
      while (l <= r && f[o ^ 1][j] <= que[r]) r--;
      que[++r] = f[o ^ 1][j];
      id[r] = j;
    }
    l = 1;
    r = 0;
    for (int j = n; j; j--) {
      while (l <= r && id[l] - j > dt) l++;
      if (l <= r) f[o][j] = min(f[o][j], que[l]);
      while (l <= r && f[o ^ 1][j] <= que[r]) r--;
      que[++r] = f[o ^ 1][j];
      id[r] = j;
    }
    for (int j = 1; j <= n; j++) f[o][j] += abs(a[i] - j);
  }
  for (int j = 1; j <= n; j++) tmp = min(tmp, (long long)f[o][j]);
  printf("%lld\n", ans - tmp);
  return 0;
}
