#include <bits/stdc++.h>
using namespace std;
long long n, m, d, a[305], b, t[305], cnt = 0, dp[150005][2];
deque<long long> q;
void doit(long long x, long long k, long long v, long long m) {
  q.clear();
  for (long long i = 1; i <= n + m / 2; i++) {
    if (i <= n) {
      while (!q.empty() && dp[i][v] > dp[q.back()][v]) q.pop_back();
      q.push_back(i);
    }
    if (q.front() < i - m + 1) q.pop_front();
    if (i > m / 2) dp[i - m / 2][k] = dp[q.front()][v] - abs(i - m / 2 - x);
  }
}
int main() {
  cin >> n >> m >> d;
  for (long long i = 1; i <= m; i++) {
    cin >> a[i] >> b >> t[i];
    cnt += b;
  }
  for (long long j = 1; j <= n; j++) {
    dp[j][1] = -abs(j - a[1]);
  }
  for (int i = 2; i <= m; i++) {
    doit(a[i], i % 2, (i + 1) % 2,
         min(2 * n + 1, (t[i] - t[i - 1]) * d * 2 + 1));
  }
  long long ans = dp[1][m % 2];
  for (int i = 2; i <= n; i++) ans = max(ans, dp[i][m % 2]);
  ans += cnt;
  cout << ans << endl;
  return 0;
}
