#include <bits/stdc++.h>
using namespace std;
const long long INF64 = (long long)1e16;
const int INF = 1e9 + 500;
const int mod = (int)1e9 + 7;
void test_case() {
  int n, m, d;
  cin >> n >> m >> d;
  vector<int> a(m), b(m), t(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> t[i];
    a[i]--;
  }
  vector<long long> dp(n);
  for (int j = 0; j < n; j++) {
    dp[j] = b[0] - llabs(a[0] - j);
  }
  for (int e = 1; e < m; e++) {
    vector<long long> ndp(n);
    deque<long long> dq;
    int tim = t[e] - t[e - 1], right = 0;
    for (int i = 0; i < n; i++) {
      long long dis = (long long)tim * d;
      int l = max(0LL, (long long)(i - dis)),
          r = min((long long)(n - 1), (long long)(i + dis));
      while (dq.size() && dq.front() < l) dq.pop_front();
      while (right <= r) {
        while (dq.size() && dp[dq.back()] < dp[right]) dq.pop_back();
        dq.push_back(right++);
      }
      assert(dq.size() > 0);
      long long mx = dp[dq.front()];
      ndp[i] = mx + b[e] - llabs(a[e] - i);
    }
    dp = ndp;
  }
  long long ans = -INF64;
  for (int i = 0; i < n; i++) ans = max(ans, dp[i]);
  cout << ans;
}
int main() {
  int t = 1;
  while (t--) test_case();
}
