#include <bits/stdc++.h>
using namespace std;
long long a[305], b[305], t[305], d[2][150005], n, m, p, ans = -2e18;
int main() {
  cin >> n >> m >> p;
  for (long long i = 1; i <= m; i++) {
    scanf("%lld%lld%lld", &a[i], &b[i], &t[i]);
  }
  long long now = 1, last = 0, cur = 1;
  for (long long i = 1; i <= m; i++) {
    long long pos = 1, dis = (t[i] - now) * p;
    deque<long long> q;
    for (int j = 1; j <= n; j++) {
      while (q.size() && j - q.front() > dis) q.pop_front();
      while (pos <= n && pos - j <= dis) {
        while (q.size() && d[last][pos] >= d[last][q.back()]) q.pop_back();
        q.push_back(pos);
        pos++;
      }
      d[cur][j] = d[last][q.front()] + b[i] - abs(a[i] - j);
    }
    swap(cur, last);
    now = t[i];
  }
  for (long long i = 1; i <= n; i++) {
    ans = max(ans, d[last][i]);
  }
  cout << ans << endl;
}
