#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1.5e5 + 10;
const long long MAXM = 3e2 + 10;
const long long INF = 1e18 + 10;
deque<pair<long long, long long> > q;
long long a[MAXN];
long long b[MAXN];
long long t[MAXN];
long long e[MAXN];
long long dp[MAXN];
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, d, s = 0, res = -INF;
  cin >> n >> m >> d;
  for (long long i = 1; i <= m; i++) {
    cin >> a[i] >> b[i] >> t[i];
    s += b[i];
  }
  for (long long i = 1; i <= n; i++) {
    dp[i] = abs(a[m] - i);
  }
  for (long long i = m - 1; i >= 1; i--) {
    q.clear();
    for (long long j = 1; j <= n; j++) {
      while (!q.empty() && q.back().first >= dp[j]) {
        q.pop_back();
      }
      if (!q.empty() && q[0].second == j - (t[i + 1] - t[i]) * d - 1) {
        q.pop_front();
      }
      q.push_back(make_pair(dp[j], j));
      e[j] = q[0].first + abs(a[i] - j);
    }
    q.clear();
    for (long long j = n; j >= 1; j--) {
      while (!q.empty() && q.back().first >= dp[j]) {
        q.pop_back();
      }
      if (!q.empty() && q[0].second == j + (t[i + 1] - t[i]) * d + 1) {
        q.pop_front();
      }
      q.push_back(make_pair(dp[j], j));
      dp[j] = min(e[j], q[0].first + abs(a[i] - j));
    }
  }
  for (long long i = 1; i <= n; i++) {
    res = max(res, s - dp[i]);
  }
  cout << res;
}
