#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline int read(T& x) {
  x = 0;
  char c = getchar(), f = 1;
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    if (c == -1) return -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  x *= f;
  return 1;
}
template <typename T, typename... Args>
inline int read(T& x, Args&... args) {
  return read(x) + read(args...);
}
template <typename T>
inline int write(T x) {
  if (x < 0) return putchar('-') & write((~x) + 1);
  if (x / 10) return write(x / 10) & putchar(x % 10 | 48);
  return putchar(x | 48);
}
template <typename T>
inline int write(T x, char c) {
  return write(x) + putchar(c);
}
int n, m, d;
long long a[150005], b[150005], t[150005];
long long dp[2][150005];
deque<int> dq;
signed main() {
  read(n, m, d);
  long long ans = 1e18, sum = 0;
  for (int i = 1; i <= m; i++) {
    memset(dp[i & 1], 0x3f, sizeof dp[i & 1]);
    read(a[i], b[i], t[i]);
    sum += b[i];
    long long dis = (t[i] - t[i - 1]) * d;
    dq.clear();
    for (int j = 1; j <= n; j++) {
      while (!dq.empty() && dq.front() < j - dis) dq.pop_front();
      while (!dq.empty() && dp[i & 1 ^ 1][dq.back()] > dp[i & 1 ^ 1][j])
        dq.pop_back();
      dq.push_back(j);
      dp[i & 1][j] =
          ((dp[i & 1][j]) < (dp[i & 1 ^ 1][dq.front()] +
                             ((a[i] - j) < 0 ? (-(a[i] - j)) : (a[i] - j)))
               ? (dp[i & 1][j])
               : (dp[i & 1 ^ 1][dq.front()] +
                  ((a[i] - j) < 0 ? (-(a[i] - j)) : (a[i] - j))));
    }
    dq.clear();
    for (int j = n; j >= 1; j--) {
      while (!dq.empty() && dq.front() > j + dis) dq.pop_front();
      while (!dq.empty() && dp[i & 1 ^ 1][dq.back()] > dp[i & 1 ^ 1][j])
        dq.pop_back();
      dq.push_back(j);
      dp[i & 1][j] =
          ((dp[i & 1][j]) < (dp[i & 1 ^ 1][dq.front()] +
                             ((a[i] - j) < 0 ? (-(a[i] - j)) : (a[i] - j)))
               ? (dp[i & 1][j])
               : (dp[i & 1 ^ 1][dq.front()] +
                  ((a[i] - j) < 0 ? (-(a[i] - j)) : (a[i] - j))));
    }
  }
  for (int i = 1; i <= n; i++)
    ans = ((ans) < (dp[m & 1][i]) ? (ans) : (dp[m & 1][i]));
  write(sum - ans, '\n');
}
