#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long dp[2][150005];
long long b[305], a[305], ti[305], inf = 1e17;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long now = 0;
  long long n, m, d;
  cin >> n >> m >> d;
  for (long long i = 1; i <= m; i++) {
    cin >> a[i] >> b[i] >> ti[i];
  }
  long long t, l, r;
  for (long long i = 1; i <= m; i++) {
    t = ti[i] - ti[i - 1];
    now ^= 1;
    deque<long long> q;
    for (long long j = 1; j <= min(t * d, n); j++) {
      while (!q.empty() && dp[now ^ 1][q.back()] < dp[now ^ 1][j]) q.pop_back();
      q.emplace_back(j);
    }
    for (long long j = 1; j <= n; j++) {
      l = max(1ll, j - t * d);
      r = min(n, j + t * d);
      if (j + t * d <= n) {
        while (!q.empty() && dp[now ^ 1][q.back()] < dp[now ^ 1][r])
          q.pop_back();
        q.emplace_back(r);
      }
      if (q.front() < l) q.pop_front();
      dp[now][j] = dp[now ^ 1][q.front()];
      dp[now][j] += b[i] - abs(a[i] - j);
    }
  }
  long long ans = -inf;
  for (long long i = 1; i <= n; i++) {
    ans = max(ans, dp[now][i]);
  }
  cout << ans;
  return 0;
}
