#include <bits/stdc++.h>
using namespace std;
const long long N = 150005;
const long long M = 305;
long long n, m, d, ans = 0;
long long a[M], b[M], t[M], dp[N];
long long RMQ[20][N], floorlog[N];
map<long long, vector<pair<long long, long long> > > event;
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;
  }
  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]);
}
void go(long long time) {
  if (time == 0) return;
  precompute();
  for (long long x = 1; x <= n; x++) {
    long long diff = t[time + 1] - t[time];
    long long minx = max(1LL, x - diff * d);
    long long maxx = min(n, x + diff * d);
    dp[x] = b[time] - abs(x - a[time]) + getMax(minx, maxx);
  }
  go(time - 1);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m >> d;
  for (long long i = 1; i <= m; i++) cin >> a[i] >> b[i] >> t[i];
  t[m + 1] = t[m];
  go(m);
  long long ans = -1e18;
  for (long long i = 1; i <= n; i++) ans = max(ans, dp[i]);
  cout << ans;
  return 0;
}
