#include <bits/stdc++.h>
using namespace std;
const int maxn = 1.5e5;
int n, m, d;
long long dp[maxn];
long long dp1[maxn];
int que[maxn];
void Move(int d) {
  int l = 0, r = 0;
  for (int i = 0, next = 0; i < n; ++i) {
    while (next < n && next - i <= d) {
      while (l < r && dp[que[r - 1]] <= dp[next]) {
        --r;
      }
      que[r++] = next++;
    }
    while (l < r && i - que[l] > d) {
      ++l;
    }
    dp1[i] = dp[que[l]];
  }
  memcpy(dp, dp1, n * sizeof(dp[0]));
}
void Insert(int x, int b) {
  for (int i = 0; i < n; ++i) {
    dp[i] += b - abs(i - x);
  }
}
int main(void) {
  scanf("%d%d%d", &n, &m, &d);
  int time = 0;
  for (int i = 0; i < m; ++i) {
    int a, b, t;
    scanf("%d%d%d", &a, &b, &t);
    --a;
    Move(min((long long)(n - 1), (long long)d * (t - time)));
    time = t;
    Insert(a, b);
  }
  printf("%lld\n", *max_element(dp, dp + n));
  return 0;
}
