#include <bits/stdc++.h>
using namespace std;
const int M = 150005;
long long n, m, d, head, tail;
long long ans = -1e9 - 7;
long long a[M], b[M], t[M];
long long dp[2][M], q[M];
int main() {
  scanf("%lld%lld%lld", &n, &m, &d);
  for (int i = 1; i <= m; i++) {
    scanf("%lld%lld%lld", &a[i], &b[i], &t[i]);
  }
  for (int i = 1; i <= m; i++) {
    head = 1;
    tail = 0;
    long long dti = t[i] - t[i - 1];
    long long k = 1;
    for (int j = 1; j <= n; j++) {
      for (; k <= min(n, j + dti * d); k++) {
        while (head <= tail && dp[(i - 1) % 2][q[tail]] <= dp[(i - 1) % 2][k])
          tail--;
        q[++tail] = k;
      }
      while (head <= tail && q[head] + dti * d < j) head++;
      dp[i % 2][j] = dp[(i - 1) % 2][q[head]] + b[i] - abs(a[i] - j);
    }
  }
  for (int i = 1; i <= n; i++) ans = max(ans, dp[m % 2][i]);
  printf("%lld", ans);
}
