#include <bits/stdc++.h>
using namespace std;
const int M = 15e4 + 10;
int dp[310][M], a, b, t, n, d, m, ans = 1e9 + 100, lt;
long long int B;
int main() {
  cin >> n >> m >> d;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b >> t;
    B += (long long int)b;
    int dd = d * (t - lt);
    dd = min(dd, n);
    deque<pair<int, int> > saf;
    for (int j = 1; j <= n + dd; j++) {
      if (j <= n) {
        while (saf.size() && saf.back().first >= dp[i - 1][j]) saf.pop_back();
        while (saf.size() && saf.front().second < j - 2 * dd) saf.pop_front();
        saf.push_back(make_pair(dp[i - 1][j], j));
      }
      if (j > dd) {
        while (saf.size() && saf.front().second < j - 2 * dd) saf.pop_front();
        dp[i][j - dd] = saf.front().first + abs(a - (j - dd));
      }
    }
    lt = t;
  }
  for (int j = 1; j <= n; j++) ans = min(ans, dp[m][j]);
  cout << B - (long long int)ans << endl;
  return 0;
}
