#include <bits/stdc++.h>
using namespace std;
long long dp[2][150002];
long long a[150002], b[150002], t[150002], tm[303];
list<long long> lst;
inline void Add(long long x) {
  while (!lst.empty() && lst.back() < x) lst.pop_back();
  lst.push_back(x);
}
inline void Remove(long long x) {
  if (x == lst.front()) lst.pop_front();
}
inline long long tog(int x) {
  if (x == 0)
    x = 1;
  else
    x = 0;
  return x;
}
int main() {
  long long n, m, k, d, max, dist, nextt, x;
  cin >> n >> m >> d;
  for (long long i = 1; i <= m; i++) cin >> a[i] >> b[i] >> t[i];
  x = 0;
  for (long long i = 0; i <= 1; i++)
    for (long long j = 0; j <= n; j++) dp[i][j] = 0;
  t[m + 1] = 0;
  for (long long i = 1; i <= m; i++) {
    nextt = t[i + 1];
    dist = d * (nextt - t[i]);
    lst.clear();
    for (long long j = 1; j <= n; j++) {
      dp[x][j] += b[i] - ((a[i] > j) ? (a[i] - j) : (j - a[i]));
      if (t[i + 1] > t[i]) {
        Add(dp[x][j]);
        if (j > 2 * dist + 1) Remove(dp[x][j - 2 * dist - 1]);
        if (j > dist) dp[tog(x)][j - dist] = lst.front();
      }
    }
    if (t[i + 1] > t[i]) {
      if (n > 2 * dist + 1)
        for (k = n - dist + 1; k <= n; k++) {
          Remove(dp[x][k - dist - 1]);
          dp[tog(x)][k] = lst.front();
        }
      else if (n <= dist + 1)
        for (k = 1; k <= n; k++) {
          dp[tog(x)][k] = lst.front();
        }
      else {
        for (k = n - dist + 1; k <= dist + 1; k++) {
          dp[tog(x)][k] = lst.front();
        }
        for (; k <= n; k++) {
          Remove(dp[x][k - dist - 1]);
          dp[tog(x)][k] = lst.front();
        }
      }
      x = tog(x);
    }
  }
  max = dp[x][1];
  for (long long i = 2; i <= n; i++) {
    if (dp[x][i] > max) max = dp[x][i];
  }
  cout << max;
  return 0;
}
