#include <bits/stdc++.h>
using namespace std;
const int MAXN = 150005;
deque<long long> dq;
long long f[MAXN], g[MAXN];
int a[MAXN], b[MAXN], t[MAXN];
int n, m, d;
int main() {
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &a[i], &b[i], &t[i]);
  for (int fireworks = 1; fireworks <= m;) {
    int nextFirework;
    for (nextFirework = fireworks + 1; nextFirework <= m + 1; nextFirework++)
      if (nextFirework == m + 1 || t[nextFirework] != t[nextFirework - 1])
        break;
    long long len =
        ((long long)t[fireworks] - (long long)t[fireworks - 1]) * (long long)d;
    if (len > n) len = n;
    dq.clear();
    for (int section = 1; section <= min(n - 1, (int)len); section++) {
      while (!dq.empty() && f[section] > f[dq.back()]) dq.pop_back();
      dq.push_back(section);
    }
    for (int section = min(n, (int)len + 1); section <= n; section++) {
      while (!dq.empty() && f[section] > f[dq.back()]) dq.pop_back();
      dq.push_back(section);
      while (!dq.empty() && section - dq.front() + 1 > len * 2 + 1)
        dq.pop_front();
      int idx = max(1, section - (int)len);
      g[idx] = f[dq.front()];
      for (int i = fireworks; i < nextFirework; i++)
        g[idx] += (long long)b[i] - (long long)abs(a[i] - idx);
      if (section == n) {
        for (int i = idx + 1; i <= n; i++) {
          while (!dq.empty() && i - dq.front() + 1 > len + 1) dq.pop_front();
          g[i] = f[dq.front()];
          for (int j = fireworks; j < nextFirework; j++)
            g[i] += (long long)b[j] - (long long)abs(a[j] - i);
        }
      }
    }
    for (int section = 1; section <= n; section++) f[section] = g[section];
    fireworks = nextFirework;
  }
  long long res = -(long long)1e18;
  for (int section = 1; section <= n; section++) res = max(res, f[section]);
  cout << res << endl;
  return 0;
}
