#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5e4 + 10;
const int K = 3e2 + 10;
long long dp[2][N];
long long a[K], b[K], t[K];
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, d;
  cin >> n >> m >> d;
  for (int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> t[i];
  int p = 1;
  t[0] = 1;
  for (int i = 1; i <= m; i++) {
    deque<int> dq;
    long long range = min(n, (t[i] - t[i - 1]) * d);
    for (int j = 1; j <= range; j++) {
      while (dq.size() && dp[1 ^ p][dq.back()] <= dp[1 ^ p][j]) dq.pop_back();
      dq.push_back(j);
    }
    for (int j = 1; j <= n; j++) {
      int right = j + range;
      if (right <= n) {
        while (dq.size() && dp[1 ^ p][dq.back()] <= dp[1 ^ p][right])
          dq.pop_back();
        dq.push_back(right);
      }
      dp[p][j] = dp[1 ^ p][dq[0]] + b[i] - abs(a[i] - j);
      while (dq.size() && dq[0] <= (j - range)) dq.pop_front();
    }
    p = 1 ^ p;
  }
  cout << *max_element(dp[1 ^ p] + 1, dp[1 ^ p] + n + 1);
  return 0;
}
