#include <bits/stdc++.h>
using namespace std;
const int N = 15e4 + 5;
const int M = 3e2 + 5;
const long long NINF = -1e12 + 5;
long long dp[2][N], a[M], b[M], t[M], n, m, d, interval, curr, nxt;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> d;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i] >> t[i];
  }
  for (int i = 1; i <= m; i++) {
    nxt = i & 1;
    curr = nxt ^ 1;
    interval = min(n, (t[i] - t[i - 1]) * d);
    deque<long long> dq;
    for (int j = 1; j <= interval; j++) {
      while (!dq.empty() && dp[curr][dq.back()] <= dp[curr][j]) dq.pop_back();
      dq.push_back(j);
    }
    for (int j = 1; j <= n; j++) {
      int k = j + interval;
      if (k <= n) {
        while (!dq.empty() && dp[curr][dq.back()] <= dp[curr][k]) dq.pop_back();
        dq.push_back(k);
      }
      dp[nxt][j] = dp[curr][dq.front()] + b[i] - abs(a[i] - j);
      while (!dq.empty() && dq.front() <= (j - interval)) dq.pop_front();
    }
  }
  long long ans = NINF;
  for (int i = 1; i <= n; i++) ans = max(ans, dp[nxt][i]);
  cout << ans << "\n";
  return 0;
}
