#include <bits/stdc++.h>
using namespace std;
const int N = 150001;
int n, m, d, k;
int t[2];
long long f[2][N], sum, ans = 1e18;
deque<long long> Q;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> d;
  for (int i = 1; i <= m; ++i) {
    int a, b;
    cin >> a >> b >> t[k ^ 1];
    sum += b;
    long long len = 1LL * (t[k ^ 1] - t[k]) * d;
    Q.clear();
    for (int j = 1; j <= n; ++j) {
      while (!Q.empty() && j - Q.front() > len) Q.pop_front();
      while (!Q.empty() && f[k][j] < f[k][Q.back()]) Q.pop_back();
      Q.push_back(j);
      f[k ^ 1][j] = f[k][Q.front()] + abs(a - j);
    }
    Q.clear();
    for (int j = n; j >= 1; --j) {
      while (!Q.empty() && Q.front() - j > len) Q.pop_front();
      while (!Q.empty() && f[k][j] < f[k][Q.back()]) Q.pop_back();
      Q.push_back(j);
      f[k ^ 1][j] = min(f[k ^ 1][j], f[k][Q.front()] + abs(a - j));
    }
    k ^= 1;
  }
  for (int i = 1; i <= n; ++i) ans = min(ans, f[k][i]);
  printf("%lld\n", sum - ans);
  return 0;
}
