#include <bits/stdc++.h>
const int MAXN = 150005, MAXM = 310;
using namespace std;
struct minQueue {
  int l, r;
  deque<pair<long long, int> > q;
  minQueue() { l = 1, r = 0; }
  void insert(long long val) {
    while (q.size() > 0 && q.back().first <= val) q.pop_back();
    q.push_back(make_pair(val, ++r));
  }
  void pop() {
    if (q.size() == 0) return;
    if (q.front().second == l) q.pop_front();
    l++;
  }
  long long get() { return q.front().first; }
  void clear() {
    while (q.size() > 0) q.pop_back();
    l = 1, r = 0;
  }
};
minQueue q;
int n, m, d;
int a[MAXN], b[MAXN], t[MAXN];
long long dp[MAXN];
int main() {
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 1; i < m + 1; i++) scanf("%d%d%d", &a[i], &b[i], &t[i]);
  for (int i = 1; i < m + 1; i++) {
    int R = n, L = 1;
    long long h = 1LL * d * (t[i] - t[i - 1]);
    if (h + 1 < 1LL * n) R = h + 1;
    for (int j = 1; j <= R; j++) q.insert(dp[j]);
    for (int j = 1; j <= n; j++) {
      if (1LL * L < 1LL * (j - h)) q.pop(), L++;
      if (1LL * R < h + j && h + j <= n) q.insert(dp[++R]);
      dp[j] = q.get();
    }
    q.clear();
    for (int j = 1; j < n + 1; j++) dp[j] += b[i] - abs(j - a[i]);
  }
  printf("%lld\n", *max_element(dp + 1, dp + 1 + n));
}
