#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
pair<long long, long long> dq[MAXN];
long long dp[MAXN], tdp[MAXN];
int dqh, dqt;
int n, m, d;
int a, b, t;
vector<pair<int, int> > ab;
void dowork(int currtime, int lasttime) {
  sort(ab.begin(), ab.end());
  int absz = ab.size();
  int abidx = 0;
  long long reward = 0, penalty = 0;
  int rcnt = 0, lcnt = 0;
  for (int j = 0; j < absz; j++) {
    reward += ab[j].second;
    penalty -= (ab[j].first - 1);
    if (ab[j].first == 1)
      lcnt++;
    else if (ab[j].first > 1)
      rcnt++;
  }
  abidx = lcnt;
  int nextpush = 1;
  dqh = 0;
  dqt = 0;
  for (int j = 1; j <= n; j++) {
    while (nextpush <= n &&
           abs(nextpush - j) <= 1LL * d * (currtime - lasttime)) {
      while (dqh != dqt && dp[nextpush] >= dq[dqh - 1].first) dqh--;
      dq[dqh++] = make_pair(dp[nextpush], nextpush);
      nextpush++;
    }
    while (dqh != dqt &&
           abs(dq[dqt].second - j) > 1LL * d * (currtime - lasttime))
      dqt++;
    tdp[j] = dq[dqt].first + reward + penalty;
    penalty = penalty - lcnt + rcnt;
    while (abidx < absz && ab[abidx].first == j + 1) {
      lcnt++;
      rcnt--;
      abidx++;
    }
  }
  memcpy(dp, tdp, sizeof tdp);
  ab.clear();
}
int main() {
  cin >> n >> m >> d;
  int currtime = 0, lasttime = 0;
  memset(dp, 0, sizeof dp);
  memset(tdp, 0, sizeof tdp);
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> t;
    if (t != currtime && currtime > 0) {
      dowork(currtime, lasttime);
      lasttime = currtime;
    }
    ab.push_back(make_pair(a, b));
    currtime = t;
  }
  dowork(currtime, lasttime);
  long long res = -2000000000;
  for (int i = 1; i <= n; i++) {
    res = max(res, dp[i]);
  }
  cout << res << endl;
  return 0;
}
