#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
template <typename T>
vector<T> slide_min(const vector<T> &a, int k) {
  vector<T> res;
  deque<int> deq;
  for (int i = 0; i < (int)a.size(); i++) {
    while (!deq.empty() && a[deq.back()] >= a[i]) deq.pop_back();
    deq.emplace_back(i);
    if (i - k + 1 >= 0) {
      res.emplace_back(a[deq.front()]);
      if (deq.front() == i - k + 1) deq.pop_front();
    }
  }
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  long long d;
  cin >> 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 i = 0, prv = 1; i < m; i++) {
    int mi = min<long long>((t[i] - prv) * d, n - 1);
    vector<long long> v;
    for (int p = 0; p < mi; p++) v.emplace_back(INF);
    for (int p = 0; p < n; p++) v.emplace_back(dp[p]);
    for (int p = 0; p < mi; p++) v.emplace_back(INF);
    vector<long long> range_min = slide_min(v, mi * 2 + 1);
    for (int p = 0; p < n; p++) dp[p] = range_min[p] + abs(a[i] - p);
    prv = t[i];
  }
  cout << accumulate(b.begin(), b.end(), 0LL) -
              *min_element(dp.begin(), dp.end())
       << endl;
  return 0;
}
