#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7F7F7F7F;
const int MAXN = 500;
const int MAXM = 150000 + 10;
int n, m, d, a[MAXN], b[MAXN], t[MAXN], now, last, L, R, l, Q[MAXM];
long long dp[2][MAXM];
void f1(long long x) {
  while (L <= R && Q[L] < x) ++L;
}
void f3(int l) {
  while (L <= R && dp[last][Q[R]] < dp[last][l]) --R;
  Q[++R] = l;
}
void f2(long long y) {
  while (l <= n && l <= y) f3(l), ++l;
}
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 i = 1; i <= m; ++i) {
    now ^= 1;
    last = now ^ 1;
    L = l = 1, R = 0;
    for (int j = 1; j <= n; ++j) {
      long long k1 = j - 1LL * (t[i] - t[i - 1]) * d;
      long long k2 = j + 1LL * (t[i] - t[i - 1]) * d;
      f1(k1);
      f2(k2);
      dp[now][j] = dp[last][Q[L]] + b[i] - abs(a[i] - j);
    }
  }
  long long ans = -INF;
  for (long long i = 1; i <= n; ++i) ans = max(ans, dp[now][i]);
  cout << ans << endl;
  return 0;
}
