#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long MOD = 1000000000 + 7;
long long dp[2][150005];
int main() {
  long long n, m;
  long long d;
  scanf("%I64d%I64d%I64d", &n, &m, &d);
  int cur = 0;
  memset(dp, 0, sizeof(dp));
  long long a, b, t;
  long long pret = -250000;
  long long L, R;
  long long ans = 0;
  for (int l = 0, _END_ = (int)(m); l < _END_; l++) {
    deque<pair<long long, int> > Q;
    scanf("%I64d%I64d%I64d", &a, &b, &t);
    ans += b;
    L = 1LL - (t - pret) * d;
    R = 1LL + (t - pret) * d;
    for (int i = max(L, 1LL), _END_ = (int)(min(R, n)); i <= _END_; i++) {
      while (!Q.empty() && -Q.back().first > dp[cur][i]) Q.pop_back();
      Q.push_back(make_pair(-dp[cur][i], -i));
    }
    memset(dp[cur ^ 1], 0, sizeof(dp[cur ^ 1]));
    for (int i = 1; i <= (int)(n); i++) {
      dp[cur ^ 1][i] = -Q.front().first + abs(a - i);
      L += 1LL;
      if (L > 0)
        while (!Q.empty() && -Q.front().second < L) Q.pop_front();
      if (R < n) {
        R++;
        while (!Q.empty() && -Q.back().first > dp[cur][R]) Q.pop_back();
        Q.push_back(make_pair(-dp[cur][R], -R));
      }
    }
    pret = t;
    cur ^= 1;
  }
  long long tmp = dp[cur][1];
  for (int i = 1; i <= (int)(n); i++) tmp = min(tmp, dp[cur][i]);
  cout << ans - tmp << endl;
}
