#include <bits/stdc++.h>
using namespace std;
const int maxn = 150000 + 10;
long long f[2][maxn];
int main() {
  int n, m, d, tt = 0;
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 1; i <= m; i++) {
    int a, b, t;
    scanf("%d%d%d", &a, &b, &t);
    long long H = 1LL * d * (t - tt);
    tt = t;
    long long qq[maxn], head = 1, tail = 0;
    int k = 1;
    for (int j = 1; j <= n; j++) {
      for (; k <= n && k <= j + H; k++) {
        while (head <= tail && f[(i - 1) % 2][k] >= f[(i - 1) % 2][qq[tail]])
          tail--;
        qq[++tail] = k;
      }
      while (head <= tail && qq[head] < j - H) head++;
      f[i % 2][j] = f[(i - 1) % 2][qq[head]] + b - abs(a - j);
    }
  }
  long long Max = -0x3f3f3f3f3f3f3f3f;
  for (int i = 1; i <= n; i++) {
    Max = max(Max, f[m % 2][i]);
  }
  printf("%lld", Max);
  return 0;
}
