#include <bits/stdc++.h>
using namespace std;
const int n_max = 150005;
int n, m, d, a[n_max], b[n_max], t[n_max];
int p, q, i, j, l, r;
long long dp[n_max][3], ans, D;
deque<pair<long long, int> > DD;
int main() {
  scanf("%d%d%d", &n, &m, &d);
  for (i = 1; i <= m; i++) scanf("%d%d%d", &a[i], &b[i], &t[i]);
  for (i = 1; i <= n; i++) dp[i][0] = b[1] - abs(a[1] - i);
  for (i = 2; i <= m; i++) {
    D = (long long)(t[i] - t[i - 1]) * d;
    p = q;
    q = 1 - q;
    DD.clear();
    l = 0;
    r = 1;
    for (j = 1; j <= n; j++) {
      while (r <= n && r - j <= D) {
        while (DD.size() && DD.back().first < dp[r][p]) DD.pop_back();
        DD.push_back(make_pair(dp[r][p], r));
        r++;
      }
      while (l < j && j - l > D) {
        while (DD.size() && DD.front().second <= l) DD.pop_front();
        l++;
      }
      dp[j][q] = DD.front().first + b[i] - abs(a[i] - j);
    }
  }
  ans = -200000000000000000LL;
  for (i = 1; i <= n; i++) ans = (ans > dp[i][q] ? ans : dp[i][q]);
  cout << ans << endl;
}
