#include <bits/stdc++.h>
using namespace std;
const int N = 150005;
const int INF = 0x3f3f3f3f;
int n, m, k, a[N], p, b[N], c[N];
long long dp[2][N], s[N];
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
int main() {
  n = read(), m = read(), k = read();
  for (int i = (1), iend = (m); i <= iend; i++)
    a[i] = read(), b[i] = read(), c[i] = read();
  for (int i = (1), iend = (m); i <= iend; i++) {
    int l = 1, r = 0, t = 1;
    long long tmp = 1ll * k * (c[i] - c[i - 1]);
    for (int j = (1), jend = (n); j <= jend; j++) {
      while (t <= n && t <= j + tmp) {
        while (l <= r && dp[p][s[r]] <= dp[p][t]) r--;
        s[++r] = t, t++;
      }
      while (l <= r && s[l] < j - tmp) l++;
      dp[p ^ 1][j] = dp[p][s[l]] + b[i] - abs(a[i] - j);
    }
    p = p ^ 1;
  }
  long long ans = -INF;
  for (int i = (1), iend = (n); i <= iend; i++) ans = max(ans, dp[p][i]);
  printf("%lld", ans);
  return 0;
}
