#include <bits/stdc++.h>
using namespace std;
long long n, m, d, i, a[150005], b[150005], t[150005], j, h[150005], mx;
void update(long long r) {
  long long i, h1[150005];
  deque<pair<long long, long long> > deck, deck1;
  for (i = 1; i <= n; i++) {
    while ((deck.size() != 0) && (deck.back().first < h[i])) deck.pop_back();
    deck.push_back(make_pair(h[i], i));
    if (deck.front().second < i - r) deck.pop_front();
    h1[i] = deck.front().first;
  }
  for (i = n; i >= 1; i--) {
    while ((deck1.size() != 0) && (deck1.back().first < h[i])) deck1.pop_back();
    deck1.push_back(make_pair(h[i], i));
    if (deck1.front().second > i + r) deck1.pop_front();
    h1[i] = max(h1[i], deck1.front().first);
  }
  for (i = 1; i <= n; i++) h[i] = h1[i];
}
int main(void) {
  cin >> n >> m >> d;
  for (i = 1; i <= m; i++) cin >> a[i] >> b[i] >> t[i];
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) h[j] = h[j] + b[i] - max(a[i] - j, j - a[i]);
    if (i < m) update((t[i + 1] - t[i]) * d);
  }
  mx = h[1];
  for (i = 2; i <= n; i++) mx = max(mx, h[i]);
  cout << mx;
  return 0;
}
