#include <bits/stdc++.h>
using namespace std;
int n, m, d;
long long happy[2][150001];
deque<pair<long long, int> > dq;
int main() {
  cin >> n >> m >> d;
  int lastt = 1;
  long long* src = happy[0];
  long long* des = happy[1];
  while (m--) {
    int a, b, t;
    cin >> a >> b >> t;
    a--;
    long long dis = min((long long)d * (t - lastt), (long long)n);
    lastt = t;
    for (int i = 0; i < n; i++) {
      des[i] = (long long)1 << 63;
    }
    dq.clear();
    for (int i = 0; i < n; i++) {
      while (!dq.empty() && dq.front().second < i - dis) {
        dq.pop_front();
      }
      while (!dq.empty() && dq.back().first <= src[i]) {
        dq.pop_back();
      }
      dq.push_back(make_pair(src[i], i));
      des[i] = max(des[i], dq.front().first + b - abs(a - i));
    }
    dq.clear();
    for (int i = n - 1; i >= 0; i--) {
      while (!dq.empty() && dq.front().second > i + dis) {
        dq.pop_front();
      }
      while (!dq.empty() && dq.back().first <= src[i]) {
        dq.pop_back();
      }
      dq.push_back(make_pair(src[i], i));
      des[i] = max(des[i], dq.front().first + b - abs(a - i));
    }
    swap(src, des);
  }
  cout << *max_element(src, src + n) << endl;
  return 0;
}
