#include <bits/stdc++.h>
using namespace std;
const long long N = 1.5e5 + 5;
const long long M = 3e2 + 5;
const long long mod = 1e9 + 7;
const long long m1 = 1e9 + 7;
const long long m2 = 1e9 + 9;
const long long p1 = 402653189;
const long long p2 = 1610612741;
const long long LN = 32;
long long powermodm(long long x, long long n, long long M) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result * x) % M;
    x = (x * x) % M;
    n = n / 2;
  }
  return result;
}
long long power(long long _a, long long _b) {
  long long _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = (_r * _a);
    _b /= 2;
    _a = (_a * _a);
  }
  return _r;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
  return (max(a, b) / gcd(a, b)) * min(a, b);
}
long long dx[4] = {-1, 1, 0, 0};
long long dy[4] = {0, 0, 1, -1};
long long pw[LN], fact[N], invfact[N];
void pre() {
  fact[0] = 1;
  for (long long i = 0; i < LN; i++) pw[i] = power(2, i);
  for (long long i = 1; i < N; i++) fact[i] = (i * fact[i - 1]) % mod;
  for (long long i = 0; i < N; i++)
    invfact[i] = powermodm(fact[i], mod - 2, mod);
}
long long n, m, d;
long long a[M], b[M], t[M], dp[N];
long long RMQ[20][N], floorlog[N];
void precompute() {
  for (long long i = 0; (1 << i) < N; i++) {
    for (long long j = (1 << i); j < N && j < (1 << (i + 1)); j++)
      floorlog[j] = i;
  }
}
void compute() {
  for (long long i = n; i >= 1; i--) {
    RMQ[0][i] = dp[i];
    long long mxj = floorlog[n - i + 1];
    long long pw = 1;
    for (long long j = 1; j <= mxj; j++) {
      RMQ[j][i] = max(RMQ[j - 1][i], RMQ[j - 1][i + pw]);
      pw <<= 1;
    }
  }
}
long long getMax(long long L, long long R) {
  long long k = floorlog[R - L + 1];
  return max(RMQ[k][L], RMQ[k][R - (1 << k) + 1]);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long i, j;
  precompute();
  cin >> n >> m >> d;
  for (i = 1; i <= m; i++) cin >> a[i] >> b[i] >> t[i];
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) {
      long long tt = t[i] - t[i - 1];
      long long val = getMax(max(1LL, j - tt * d), min(n, j + tt * d));
      dp[j] = val + b[i] - abs(j - a[i]);
    }
    compute();
  }
  long long ans = -LLONG_MAX;
  for (i = 1; i <= n; i++) ans = max(ans, dp[i]);
  cout << ans;
  return 0;
}
