#include <bits/stdc++.h>
using namespace std;
const long long maxn = 150050;
long long n, m, d, dp[2][maxn], a[maxn], b[maxn], t[maxn];
deque<pair<long long, long long> > dq;
void insert(long long i, long long x) {
  while (!dq.empty() and dq.back().second < x) dq.pop_back();
  dq.push_back({i, x});
}
long long query(long long i) {
  while (!dq.empty() and dq.front().first < i) dq.pop_front();
  return dq.front().second;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> d;
  for (long long i = 1; i <= m; i++) cin >> a[i] >> b[i] >> t[i];
  for (long long i = 1; i <= m; i++) {
    dq.clear();
    long long Len = (t[i] - t[i - 1]) * d;
    for (long long j = 1, k = 1; j <= n; j++) {
      long long cost = b[i] - abs(a[i] - j);
      while (k <= min(n, j + Len)) insert(k, dp[(i & 1) ^ 1][k]), k++;
      dp[i & 1][j] = query(j - Len) + cost;
    }
  }
  long long ans = -1e18;
  for (long long i = 1; i <= n; i++) ans = max(ans, dp[m & 1][i]);
  cout << ans;
}
