#include <bits/stdc++.h>
using namespace std;
const int MAXN = 150000, MAXM = 300;
int n, m, d, f, Head, Tail, Que[MAXN + 5];
long long sum, dp[2][MAXN + 5];
struct Firwork {
  int dex, hap, t;
} a[MAXM + 5];
int Abs(int x) { return x < 0 ? -x : x; }
int main() {
  scanf("%d %d %d", &n, &m, &d);
  for (int i = 1; i <= m; i++)
    scanf("%d %d %d", &a[i].dex, &a[i].hap, &a[i].t), sum += a[i].hap;
  for (int i = 1; i <= m; i++) {
    long long delt = 1ll * (a[i].t - a[i - 1].t) * d;
    Head = 1, Tail = 0;
    for (int j = 1; j <= n; j++) {
      while (Head <= Tail && Que[Head] < j - delt) Head++;
      while (Head <= Tail && dp[f][Que[Tail]] > dp[f][j]) Tail--;
      Que[++Tail] = j;
      dp[!f][j] = dp[f][Que[Head]] + Abs(a[i].dex - j);
    }
    Head = 1, Tail = 0;
    for (int j = n; j >= 1; j--) {
      while (Head <= Tail && Que[Head] > j + delt) Head++;
      while (Head <= Tail && dp[f][Que[Tail]] > dp[f][j]) Tail--;
      Que[++Tail] = j;
      dp[!f][j] = min(dp[!f][j], dp[f][Que[Head]] + Abs(a[i].dex - j));
    }
    f ^= 1;
  }
  long long Ans = (long long)1e20;
  for (int i = 1; i <= n; i++) Ans = min(Ans, dp[f][i]);
  printf("%lld", sum - Ans);
  return 0;
}
