#include <bits/stdc++.h>
using namespace std;
deque<pair<long long, long long> > q;
long long dp[2][150005];
int main() {
  long long m, n, k, a, b, t;
  cin >> n >> m >> k;
  long long tt = 0;
  int s1 = 0, s2 = 1;
  for (int ii = 1; ii <= m; ++ii) {
    q.clear();
    cin >> a >> b >> t;
    long long d = k * (t - tt);
    tt = t;
    long long i;
    for (i = 1; abs(i - 1) <= d && i <= n; ++i) {
      while (!q.empty() && q.back().first <= dp[s1][i]) q.pop_back();
      q.push_back(make_pair(dp[s1][i], i));
    }
    for (int j = 1; j <= n; ++j) {
      while (abs(q.front().second - j) > d) q.pop_front();
      dp[s2][j] = q.front().first + b - abs(a - j);
      if (i <= n) {
        while (!q.empty() && q.back().first <= dp[s1][i]) q.pop_back();
        q.push_back(make_pair(dp[s1][i], i));
        i++;
      }
    }
    swap(s1, s2);
  }
  long long g = dp[s1][1];
  for (int i = 2; i <= n; ++i) {
    if (dp[s1][i] > g) g = dp[s1][i];
  }
  cout << g << endl;
  return 0;
}
