#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long Q = 1, K = 1;
  while (Q--) {
    long long n, m, d;
    cin >> n >> m >> d;
    long long a[m + 1], b[m + 1], t[m + 1];
    t[0] = 1;
    for (long long(i) = 0; (i) < (m); (i)++)
      cin >> a[i + 1] >> b[i + 1] >> t[i + 1];
    long long dp[2][n + 1];
    for (long long(i) = 0; (i) < (n + 1); (i)++) dp[0][i] = dp[1][i] = 0;
    for (long long i = 1; i <= m; i++) {
      long long clo = 0, chi = 0;
      deque<pair<long long, long long>> dq;
      for (long long j = 1; j <= n; j++) {
        long long lo = max(j - (t[i] - t[i - 1]) * d, 1LL),
                  hi = min(j + (t[i] - t[i - 1]) * d, n);
        for (; chi <= hi; chi++) {
          while (!dq.empty() && dq.back().first <= dp[0][chi]) dq.pop_back();
          dq.push_back({dp[0][chi], chi});
        }
        while (dq.front().second < lo) dq.pop_front();
        dp[1][j] = dq.front().first + b[i] - abs(j - a[i]);
      }
      for (long long j = 1; j <= n; j++) dp[0][j] = dp[1][j];
    }
    long long ans = LLONG_MIN;
    for (long long(i) = 1; (i) < (n + 1); (i)++) ans = max(dp[0][i], ans);
    cout << ans;
  }
}
