#include <bits/stdc++.h>
using namespace std;
long long dp[150005], tmp[150005], a[305], b[305], t[305];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, d;
  cin >> n >> m >> d;
  for (int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> t[i];
  for (int i = 1; i <= n; i++) dp[i] = b[1] - abs(a[1] - i);
  for (int i = 2; i <= m; i++) {
    deque<pair<long long, long long> > window;
    while (!window.empty()) window.pop_back();
    for (int j = 1; j <= n; j++) {
      long long r = (t[i] - t[i - 1]) * d;
      r = max(1ll, j - r);
      while (!window.empty() and window.back().first < dp[j]) window.pop_back();
      window.push_back({dp[j], j});
      while (window.front().second < r) window.pop_front();
      long long mx = dp[j];
      mx = max(mx, window.front().first);
      tmp[j] = mx;
    }
    while (!window.empty()) window.pop_back();
    for (int j = n; j > 0; j--) {
      long long r = (t[i] - t[i - 1]) * d;
      r = min(n, j + r);
      while (!window.empty() and window.back().first < dp[j]) window.pop_back();
      window.push_back({dp[j], j});
      while (window.front().second > r) window.pop_front();
      long long mx = dp[j];
      mx = max(mx, window.front().first);
      tmp[j] = max(tmp[j], mx);
      dp[j] = tmp[j] + b[i] - abs(a[i] - j);
    }
  }
  long long ans = -1e18;
  for (int i = 1; i <= n; i++) ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}
