#include <bits/stdc++.h>
using namespace std;
long long x, y, l, i, j, n, k, k1, k2, k3, m, fldgjdflgjhrthrl,
    fldggfhfghjdflgjl, fldgjdflgrtyrtyjl, ffgfldgjdflgjl, r, z, max1, tx, pnt,
    flag;
vector<long long> divisors, ans;
long long a[150500], dp[150505], new_dp[150505], t[600500];
long long Abs(long long x) { return x > 0 ? x : -x; }
void build() {
  for (int i = n - 1; i >= 1; --i) t[i] = max(t[i << 1], t[i << 1 | 1]);
}
long long query(long long l, long long r) {
  long long res = -((long long)1e+18);
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res = max(res, t[l++]);
    if (r & 1) res = max(res, t[--r]);
  }
  return res;
}
int main() {
  long long d;
  cin >> n >> m >> d;
  long long val = 0;
  for (i = 0; i < m; i++) {
    scanf("%I64d%I64d%I64d", &x, &y, &z);
    long long dif;
    if (i == 0) {
      val = z;
      dif = 0;
    } else {
      dif = z - val;
      val = z;
    }
    for (j = 1; j <= n; j++) t[j + n - 1] = dp[j];
    build();
    for (j = 1; j <= n; j++) new_dp[j] = y - Abs(x - j);
    for (j = 1; j <= n; j++) {
      long long l = max(1LL, j - d * dif);
      long long r = min(n, j + d * dif);
      new_dp[j] += query(l - 1, r);
    }
    for (j = 1; j <= n; j++) dp[j] = new_dp[j];
  }
  long long max1 = -((long long)1e+18);
  for (i = 1; i <= n; i++) max1 = max(max1, dp[i]);
  cout << max1 << endl;
  return 0;
}
