#include <bits/stdc++.h>
using namespace std;
int ini() {
  int x;
  scanf("%d", &x);
  return x;
}
long long inl() {
  long long x;
  scanf("%lld", &x);
  return x;
}
struct node {
  int a, b, t;
};
node nd[305];
long long dp[2][150005];
int main() {
  int n = ini(), m = ini(), d = ini();
  for (int i = 1; i <= m; i++) {
    nd[i] = {ini(), ini(), ini()};
  }
  for (int i = 1; i <= m; i++) {
    deque<pair<long long, int> > dq;
    int iv = nd[i].t - nd[i - 1].t;
    for (int k = 1; k <= min((long long)n, 1LL + 1LL * d * iv); k++) {
      while (!dq.empty() && dq.back().first <= dp[(i - 1) & 1][k])
        dq.pop_back();
      dq.push_back({dp[(i - 1) & 1][k], k});
    }
    for (int j = 1; j <= n; j++) {
      int up = min((long long)n, 1LL * d * iv + j);
      int down = max(1LL, -1LL * d * iv + j);
      while (!dq.empty() && dq.front().second < down) dq.pop_front();
      dp[i & 1][j] = dq.front().first + nd[i].b - abs(nd[i].a - j);
      if (up + 1 <= n) {
        while (!dq.empty() && dq.back().first <= dp[(i - 1) & 1][up + 1])
          dq.pop_back();
        dq.push_back({dp[(i - 1) & 1][up + 1], up + 1});
      }
    }
  }
  long long res = -LLONG_MAX;
  for (int i = 1; i <= n; i++) res = max(res, dp[m & 1][i]);
  cout << res << "\n";
  return 0;
}
