#include <bits/stdc++.h>
#pragma comment(linker, "/stack:256000000")
using namespace std;
const int N = 150010;
const int M = 310;
const long long INF = (1LL << 60);
int a[M], t[M];
long long dp[2][N];
long long sp[19][N];
int pw[N];
void build(int id, int n) {
  for (int i = 1; i <= n; i++) {
    sp[0][i] = dp[id][i];
  }
  for (int i = 1; (1 << i) <= n; i++) {
    for (int j = 1; j + (1 << i) - 1 <= n; j++) {
      sp[i][j] = min(sp[i - 1][j], sp[i - 1][j + (1 << (i - 1))]);
    }
  }
}
inline int get(int L, int R) {
  int id = pw[R - L + 1];
  return min(sp[id][L], sp[id][R - (1 << id) + 1]);
}
int main() {
  int n, m, d, x;
  scanf("%d %d %d", &n, &m, &d);
  long long res = 0;
  for (int(i) = 0; (i) < (m); (i)++) {
    scanf("%d %d %d", &a[i + 1], &x, &t[i + 1]);
    res += x;
  }
  for (int i = 0; (1 << i) < N; i++) {
    pw[1 << i] = 1;
  }
  pw[0] = -1;
  for (int i = 1; i < N; i++) {
    pw[i] += pw[i - 1];
  }
  for (int i = 1; i <= m; i++) {
    int lf = 1, rg = 0, nlf, nrg;
    int delta = (int)min((long long)n, (long long)(t[i] - t[i - 1]) * d);
    int cur = i % 2;
    int pr = 1 - cur;
    build(pr, n);
    for (int j = 1; j <= n; j++) {
      nlf = max(1, j - delta);
      nrg = min(n, j + delta);
      dp[cur][j] = get(nlf, nrg) + abs(a[i] - j);
    }
  }
  res -= *min_element(dp[m % 2] + 1, dp[m % 2] + n + 1);
  cout << res << endl;
  return 0;
}
