#include <bits/stdc++.h>
using namespace std;
long long dp[150150];
vector<long long> w(const vector<long long> &v, long long k) {
  int n = v.size();
  vector<int> upto(n);
  stack<int> s;
  vector<long long> ans;
  for (int i = 0; i < n; i++) {
    while (!s.empty() && v[s.top()] < v[i]) {
      upto[s.top()] = i - 1;
      s.pop();
    }
    s.push(i);
  }
  while (!s.empty()) {
    upto[s.top()] = n - 1;
    s.pop();
  }
  int j = 0;
  for (int i = 0; i <= n - k; i++) {
    while (j < i || upto[j] < i + k - 1) {
      j++;
    }
    ans.push_back(v[j]);
  }
  return ans;
}
void solve(int qq) {
  int n, m, d;
  cin >> n >> m >> d;
  for (int i = 0; i <= n; i++) {
    dp[i] = 0;
  }
  int prev = 2e9;
  for (int j = 1; j <= m; j++) {
    int a, b, t;
    cin >> a >> b >> t;
    vector<long long> v;
    vector<long long> temp(n + 1);
    for (int i = 1; i <= n; i++) {
      v.push_back(dp[i]);
    }
    long long k = d * (max(0ll, (t - prev) * 1ll));
    k = min(n * 1ll, k + 1);
    vector<long long> to = w(v, k);
    for (int i = 1; i <= n; i++) {
      int cur = i - 1;
      long long mx = -2e18;
      if (cur + k - 1 < n) {
        mx = max(mx, to[cur]);
      } else {
        mx = max(mx, to[to.size() - 1]);
      }
      if (cur < k) {
        mx = max(mx, to[0]);
      } else {
        mx = max(mx, to[cur - k + 1]);
      }
      temp[i] = mx + b - abs(a - i);
    }
    for (int i = 1; i <= n; i++) {
      dp[i] = temp[i];
    }
    prev = t;
  }
  long long ans = -2e18;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
  return 0;
}
