#include <bits/stdc++.h>
using namespace std;
const int maxl = 15 * 1000 * 10 + 5;
long long int n, m, d, lst;
long long int dp[maxl], tmp[maxl];
deque<int> dq;
inline void insrt(int i) {
  while (!dq.empty() && dp[dq.front()] < dp[i]) dq.pop_front();
  dq.push_front(i);
}
inline void clr(int i) {
  while (!dq.empty() && dq.back() <= i) dq.pop_back();
}
int main() {
  scanf("%d %d %d", &n, &m, &d);
  for (int k = 0; k < m; k++) {
    int a, b, t;
    scanf("%d %d %d", &a, &b, &t);
    a--;
    int l = 0, r = min(n, (t - lst) * d + 1);
    for (int i = 0; i < r; i++) insrt(i);
    for (int i = 0; i < n; i++) {
      int nl = max(0ll, i - (t - lst) * d), nr = min(n, i + (t - lst) * d + 1);
      if (nr != r) insrt(r);
      if (nl != l) clr(l);
      l = nl;
      r = nr;
      tmp[i] = dp[dq.back()] + b - abs(i - a);
    }
    for (int i = 0; i < n; i++) dp[i] = tmp[i];
    lst = t;
    clr(n);
  }
  printf("%I64d\n", *max_element(dp, dp + n));
}
