#include <bits/stdc++.h>
using namespace std;
const long long N = 15e4 + 10, M = 3e2 + 10;
long long n, m, d, ans = (long long)-1e15, dp[2][N];
deque<long long> deq;
struct fire {
  long long a, b, t;
  fire() { a = b = t = 0; }
} ar[M];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> d;
  for (long long i = 0; i < m; i++) {
    cin >> ar[i].a >> ar[i].b >> ar[i].t;
    ar[i].a--;
  }
  for (long long i = 0; i < n; i++) dp[0][i] = ar[0].b - abs(i - ar[0].a);
  for (long long j = 1; j < m; j++) {
    deq.clear();
    long long now = (j & 1), prv = ((j - 1) & 1);
    long long dis = d * (ar[j].t - ar[j - 1].t);
    for (long long i = 0; i <= min(dis, n - 1); i++) {
      while (deq.size() && dp[prv][deq.back()] <= dp[prv][i]) deq.pop_back();
      deq.push_back(i);
    }
    dp[now][0] = dp[prv][deq.front()] + ar[j].b - ar[j].a;
    for (long long i = 1; i < n; i++) {
      if (i + dis < n) {
        while (deq.size() && dp[prv][deq.back()] <= dp[prv][i + dis])
          deq.pop_back();
        deq.push_back(i + dis);
      }
      while (deq.size() && deq.front() < i - dis) deq.pop_front();
      assert(deq.size());
      dp[now][i] = dp[prv][deq.front()] + ar[j].b - abs(ar[j].a - i);
    }
  }
  for (long long i = 0; i < n; i++) ans = max(ans, dp[(m - 1) & 1][i]);
  cout << ans;
}
