#include <bits/stdc++.h>
using namespace std;
long long dp[2][150000];
int main() {
  int nw = 1, pt = 1;
  long long n, m, d;
  cin >> n >> m >> d;
  long long a, B, t;
  for (int b = 1; b <= m; b++) {
    cin >> a >> B >> t;
    int len = min(n, (t - pt) * d);
    deque<int> dq;
    for (int i = 1; i <= len; i++) {
      while (dq.size() && dp[1 - nw][dq[dq.size() - 1]] <= dp[1 - nw][i])
        dq.pop_back();
      dq.push_back(i);
    }
    for (int i = 1; i <= n; i++) {
      int k = i + len;
      if (k <= n) {
        while (dq.size() && dp[1 - nw][dq[dq.size() - 1]] <= dp[1 - nw][k])
          dq.pop_back();
        dq.push_back(k);
      }
      dp[nw][i] = dp[1 - nw][dq.front()] - abs(i - a) + B;
      while (dq.size() && dq[0] <= (i - len)) dq.pop_front();
    }
    pt = t, nw = 1 - nw;
  }
  cout << *max_element(dp[1 - nw] + 1, dp[1 - nw] + n + 1) << endl;
  return 0;
}
