#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long n, m, d;
long long a[305];
long long b[305];
long long t[305];
long long dp[150001];
long long ma[150001];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
  cin >> n >> m >> d;
  for (long long i = 1; i <= m; i++) {
    cin >> a[i];
    cin >> b[i];
    cin >> t[i];
  }
  deque<long long> curMa;
  for (long long j = 1; j <= m; j++) {
    memset(ma, 0, sizeof(ma));
    curMa.clear();
    long long r = 0;
    long long newD = min(n, (t[j] - t[j - 1]) * d);
    for (long long i = 1; i <= n; i++) {
      if (!curMa.empty() && curMa.front() < i - newD) curMa.pop_front();
      while (r < min(i + newD, n)) {
        r++;
        while (!curMa.empty() && dp[curMa.back()] <= dp[r]) curMa.pop_back();
        curMa.push_back(r);
      }
      ma[i] = dp[curMa.front()];
    }
    for (long long i = 1; i <= n; i++) {
      dp[i] = ma[i] - abs(a[j] - i);
    }
  }
  long long ans = -1000000000;
  for (long long i = 1; i <= n; i++) ans = max(ans, (long long)dp[i]);
  for (long long j = 1; j <= m; j++) ans += b[j];
  cout << ans << endl;
}
