#include <bits/stdc++.h>
using namespace std;
int n, m, d;
int a[305], b[305], t[305];
long long dp[2][150005];
int main() {
  cin >> n >> m >> d;
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &a[i], &b[i], &t[i]);
  long long tn = 0;
  int p = 0;
  for (int i = 1; i <= m; i++) {
    deque<int> deq;
    long long interval = min((long long)n, (t[i] - tn) * d);
    for (long long j = 1; j <= interval; j++) {
      while (deq.size() && dp[p ^ 1][deq[deq.size() - 1]] <= dp[p ^ 1][j])
        deq.pop_back();
      deq.push_back(j);
    }
    for (long long j = 1; j <= n; j++) {
      long long k = j + interval;
      if (k <= n) {
        while (deq.size() && dp[p ^ 1][deq[deq.size() - 1]] <= dp[p ^ 1][k])
          deq.pop_back();
        deq.push_back(k);
      }
      dp[p][j] = dp[p ^ 1][deq[0]] + b[i] - abs(a[i] - j);
      while (!deq.empty() && deq[0] <= j - interval) deq.pop_front();
    }
    p ^= 1;
    tn = t[i];
  }
  long long ans = -999999999;
  for (int i = 1; i <= n; i++) ans = max(dp[p ^ 1][i], ans);
  cout << ans << endl;
  return 0;
}
