#include <bits/stdc++.h>
using namespace std;
int dp[305][150010];
deque<pair<long long, long long> > deq;
void ins(long long ind, long long val) {
  while (!deq.empty() and deq.back().second >= val) deq.pop_back();
  deq.push_back(make_pair(ind, val));
}
long long getmin(long long alind) {
  while (!deq.empty() and deq.front().first < alind) deq.pop_front();
  if (deq.empty()) return -1000000000;
  return deq.front().second;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, m, d;
  cin >> n >> m >> d;
  long long sum = 0;
  vector<pair<long long, long long> > timePlace;
  for (long long i = 0; i < m; ++i) {
    long long a, b, t;
    cin >> a >> b >> t;
    sum += b;
    timePlace.push_back(make_pair(t, --a));
  }
  for (long long i = 0; i < n; ++i) dp[0][i] = 0;
  long long lastt = 0;
  for (long long i = 1; i < m + 1; ++i) {
    long long currt = timePlace[i - 1].first, currp = timePlace[i - 1].second;
    long long totrav = (long long)min(1ll * d * (currt - lastt), 1ll * n);
    deq.clear();
    long long l = 0, r = -1;
    for (long long j = 0; j < n; ++j) {
      while (r < min(j + totrav, n - 1)) {
        r++;
        ins(r, dp[i - 1][r]);
      }
      l = max(0ll, j - totrav);
      dp[i][j] = getmin(l) + abs(j - currp);
    }
    lastt = currt;
  }
  long long minans = n * m * 10;
  for (long long i = 0; i < n; ++i) minans = min((int)minans, dp[m][i]);
  cout << -minans + sum << "\n";
  return 0;
}
