#include <bits/stdc++.h>
using namespace std;
inline long long gin() {
  char c = getchar();
  long long s = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    s = (s << 3) + (s << 1) + (c ^ 48);
    c = getchar();
  }
  return s * f;
}
const long long N = 150005;
long long n, m, d, sum, a[N], b[N], t[N], f[2][N], q[N];
signed main() {
  n = gin(), m = gin(), d = gin();
  memset(f, 0x3f, sizeof(f));
  for (long long i = 1; i <= m; i++)
    a[i] = gin(), b[i] = gin(), t[i] = gin(), sum += b[i];
  for (long long i = 1; i <= n; i++) f[1][i] = abs(a[1] - i);
  for (long long i = 2; i <= m; i++) {
    long long now = i & 1, last = now ^ 1, ti = t[i] - t[i - 1];
    memset(f[now], 0x3f, sizeof(f[now]));
    long long l = 1, r = 0;
    for (long long j = 1; j <= n; j++) {
      while (l <= r && q[l] < j - ti * d) l++;
      while (l <= r && f[last][q[r]] > f[last][j]) r--;
      q[++r] = j;
      f[now][j] = min(f[now][j], f[last][q[l]] + abs(a[i] - j));
    }
    l = 1, r = 0;
    for (long long j = n; j >= 1; j--) {
      while (l <= r && q[l] > j + ti * d) l++;
      while (l <= r && f[last][q[r]] > f[last][j]) r--;
      q[++r] = j;
      f[now][j] = min(f[now][j], f[last][q[l]] + abs(a[i] - j));
    }
  }
  long long ans = 1e18;
  for (long long i = 1; i <= n; i++) ans = min(ans, f[m & 1][i]);
  printf("%lld\n", sum - ans);
  return 0;
}
