#include <bits/stdc++.h>
using namespace std;
void read_file(bool outToFile = true) {}
int n, m, d;
const int nMax = 150000 + 9;
int A[nMax], B[nMax], T[nMax];
long long dp[2][nMax];
int ptr;
deque<pair<int, int> > dq;
void insert(int k) {
  while (!dq.empty() && dp[!ptr][k] <= dq.back().first) dq.pop_back();
  dq.push_back(make_pair(dp[!ptr][k], k));
}
void remove(int k) {
  if (!dq.empty() && dq.front().second == k) dq.pop_front();
}
void build_dp() {
  ptr = 0;
  for (int j = 0; j < n; j++) dp[ptr][j] = abs(j - A[0]);
  for (int i = 1; i < m; i++) {
    ptr = !ptr;
    int t = T[i] - T[i - 1];
    dq.clear();
    for (int k = 0; k <= min(n - 1 * 1LL, 1LL * d * t); k++) insert(k);
    for (int j = 0; j < n; j++) {
      dp[ptr][j] = abs(j - A[i]) + dq.front().first;
      if (j + 1LL * d * t + 1 <= n - 1) insert(j + 1LL * d * t + 1);
      if (j - 1LL * d * t >= 0) remove(j - 1LL * d * t);
    }
  }
}
int main() {
  read_file();
  while (scanf("%d%d%d", &n, &m, &d) != EOF) {
    for (int i = 0; i < m; i++) scanf("%d%d%d", &A[i], &B[i], &T[i]), A[i]--;
    build_dp();
    long long ans = LLONG_MAX;
    for (int j = 0; j < n; j++) ans = min(ans, dp[ptr][j]);
    ans = -ans;
    for (int i = 0; i < m; i++) ans += B[i];
    printf("%lld\n", ans);
  }
}
