#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int maxm = 5e5 + 10;
const long long INF = 1e18;
long long powmod(long long x, long long y) {
  long long t;
  for (t = 1; y; y >>= 1, x = x * x % mod)
    if (y & 1) t = t * x % mod;
  return t;
}
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
int n, m, d, pre = 0, tmp;
int dp[maxn], dp1[maxn], dp2[maxn], sk[maxn];
long long sum = 0;
void solve1(int x) {
  int l = 1, r = 0;
  for (int(i) = (1); (i) < (n + 1); (i)++) {
    while (l <= r && sk[l] + x < i) l++;
    if (l > r)
      dp1[i] = INT32_MAX;
    else
      dp1[i] = dp[sk[l]];
    while (l <= r && dp[sk[r]] >= dp[i]) r--;
    sk[++r] = i;
  }
}
void solve2(int x) {
  int l = 1, r = 0;
  for (int i = n; i >= 1; i--) {
    while (l <= r && i + x < sk[l]) l++;
    if (l > r)
      dp2[i] = INT32_MAX;
    else
      dp2[i] = dp[sk[l]];
    while (l <= r && dp[sk[r]] >= dp[i]) r--;
    sk[++r] = i;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> d;
  for (int(i) = (0); (i) < (m); (i)++) {
    int a, b, t;
    cin >> a >> b >> t;
    sum += b;
    tmp = min(1LL * (t - pre) * d, 1LL * n);
    if (tmp) solve1(tmp), solve2(tmp);
    for (int(j) = (1); (j) < (n + 1); (j)++) {
      if (tmp) dp[j] = min(dp[j], min(dp1[j], dp2[j]));
      dp[j] += (int)abs(j - a);
    }
    pre = t;
  }
  for (int(i) = (2); (i) < (n + 1); (i)++) dp[1] = min(dp[i], dp[1]);
  cout << sum - dp[1] << "\n";
  return 0;
}
