#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 15e4 + 100, MAXM = 310;
long long dp[2][MAXN], cost[MAXN], sum[MAXM];
long long b[MAXM], temp[MAXM], id[MAXM], a[MAXM], t[MAXM];
bool byT(long long a, long long b) { return t[a] < t[b]; }
bool byB(long long x, long long y) { return b[x] < b[y]; }
void putbyid(long long *x, long long *id, long long *des, long long l,
             long long r) {
  for (long long i = l; i < r; i++) des[i] = x[id[i]];
}
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cerr << MAXN;
  long long n, m, cd;
  cin >> n >> m >> cd;
  for (long long i = 0; i < m; i++)
    cin >> b[i] >> a[i] >> t[i], b[i]--, id[i] = i;
  sort(id, id + m, byT);
  long long pre = 0, cur = 1, lastt = -n;
  for (long long p = 0; p < m; p++) {
    long long s = p, e = s + 1, d = (t[id[s]] - lastt) * cd;
    lastt = t[id[s]];
    long long overall = a[id[s]];
    while (e < m && t[id[s]] == t[id[e]]) overall += a[id[e++]];
    sort(id + s, id + e, byB);
    putbyid(b, id, temp, s, e);
    sum[0] = 0;
    for (long long i = 1; i <= e - s; i++)
      sum[i] = sum[i - 1] + temp[i + s - 1];
    for (long long i = 0; i < n; i++) {
      cost[i] = 0;
      long long x = lower_bound(temp + s, temp + e, i) - (temp + s);
      cost[i] = (x * i - sum[x]) + (sum[e - s] - sum[x] - ((e - s - x) * i));
    }
    deque<long long> q;
    long long prel = 0, prer = 0;
    for (long long i = 0; i < n; i++) {
      long long l = max((i - d), 0LL), r = min(i + d + 1, n);
      for (long long j = prer; j < r; j++) {
        while (q.size() && dp[pre][q.back()] < dp[pre][j]) q.pop_back();
        q.push_back(j);
      }
      while (q.size() && (q.front() < l || q.front() >= r)) q.pop_front();
      dp[cur][i] = dp[pre][q.front()];
      prer = r, prel = l;
    }
    for (long long i = 0; i < n; i++) dp[cur][i] += overall - cost[i];
    p = e - 1;
    swap(cur, pre);
  }
  long long ans = -(-1LLu / 4);
  for (long long i = 0; i < n; i++) ans = max(ans, dp[pre][i]);
  cout << ans << endl;
}
