#include <bits/stdc++.h>
using namespace std;
const int N = 150 << 10;
int mem[2][N];
int p[N], v[N], a[N], t[N], n, m, d;
int main() {
  cin >> n >> m >> d;
  long long s = 0;
  for (int i = 0, b; i < m; ++i) {
    cin >> a[i] >> b >> t[i];
    s += b;
  }
  for (int i = 1; i <= n; ++i) mem[0][i] = abs(a[0] - i);
  for (int i = 1; i < m; ++i) {
    int *f = mem[i - 1 & 1], *g = mem[i & 1],
        dd = min((long long)n, (t[i] - t[i - 1]) * (long long)d);
    int l = 0, r = 0;
    for (int j = 1, k = 1; j <= n; ++j) {
      for (; p[l] < j - dd && l < r; l++)
        ;
      for (; k <= j + dd && k <= n; k++) {
        for (; l < r && f[k] <= v[r - 1]; r--)
          ;
        p[r] = k;
        v[r++] = f[k];
      }
      g[j] = v[l] + abs(a[i] - j);
    }
    r = l;
  }
  cout << s - *min_element(mem[m - 1 & 1] + 1, mem[m - 1 & 1] + n + 1) << endl;
}
