#include <bits/stdc++.h>
using namespace std;
long long n, m, d, i, j, res, sum, T, S, l, r;
long long b[200000], a[200000], t[200000], DP[200000], ans[200000];
pair<int, int> q[200000];
void insert(pair<int, int> now) {
  while (r >= l && now.first > q[r].first) r--;
  if (r < l) {
    l = 1;
    r = 1;
    q[1] = now;
    return;
  }
  r++;
  q[r] = now;
}
int main() {
  scanf("%d%d%d", &n, &m, &d);
  for (i = 1; i <= m; i++)
    scanf("%d%I64d%I64d", &a[i], &b[i], &t[i]), sum += b[i];
  for (j = 1; j <= m; j++) {
    T = t[j] - t[j - 1];
    S = T * d;
    l = 1;
    r = 0;
    for (i = 1; i <= min(S, n); i++) insert(make_pair(DP[i], i));
    for (i = 1; i <= n; i++) {
      if (i + S <= n) insert(make_pair(DP[i + S], i + S));
      while (q[l].second < i - S) l++;
      ans[i] = DP[q[l].second] - abs(a[j] - i);
    }
    for (i = 1; i <= n; i++) DP[i] = ans[i];
  }
  res = -100000000000LL;
  for (i = 1; i <= n; i++) res = max(res, DP[i]);
  printf("%I64d\n", res + sum);
}
