#include <bits/stdc++.h>
using namespace std;
const int maxn = 150005;
const long long INF = 1ll << 60;
long long dp[2][maxn];
int que[maxn];
int a[305];
int b[305];
int t[305];
int main(void) {
  int n, m, d;
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &a[i], &b[i], &t[i]);
  int o = 0;
  for (int i = 1; i <= m; i++) {
    int head = 1;
    int tail = 0;
    o ^= 1;
    for (int j = 1, k = 1; j <= n; j++) {
      while (k <= min(1ll * n, 1ll * d * (t[i] - t[i - 1]) + j)) {
        while (head <= tail && dp[o ^ 1][que[tail]] <= dp[o ^ 1][k]) tail--;
        que[++tail] = k;
        k++;
      }
      while (head <= tail &&
             que[head] < max(1ll, 1ll * j - 1ll * d * (t[i] - t[i - 1])))
        head++;
      dp[o][j] = dp[o ^ 1][que[head]] + b[i] - abs(a[i] - j);
    }
  }
  long long res = -INF;
  for (int i = 1; i <= n; i++) res = max(res, dp[o][i]);
  printf("%I64d\n", res);
  return 0;
}
