#include <bits/stdc++.h>
using namespace std;
const int N = 150000 + 100;
struct dabt {
  int pos;
  long long v;
} q[N];
int head, tail, n, m, d, a[N], b[N], t[N], now, k;
long long dp[2][N], all, tt;
int main() {
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a[i], &b[i], &t[i]);
    all += b[i];
  }
  for (int i = 1; i <= n; i++) dp[now][i] = abs(a[1] - i);
  for (int j = 2; j <= m; j++) {
    tt = t[j] - t[j - 1];
    tt *= d;
    if (tt > n) tt = n;
    head = 1, tail = 0;
    for (int i = 1; i <= tt; i++) {
      while (head <= tail && dp[now][i] < q[tail].v) tail--;
      q[++tail] = (dabt){i, dp[now][i]};
    }
    for (int i = 1; i <= n; i++) {
      int l = i - tt <= 0 ? 1 : i - tt;
      int r = i + tt;
      while (head <= tail && q[head].pos < l) head++;
      if (r <= n) {
        while (head <= tail && dp[now][r] < q[tail].v) tail--;
        q[++tail] = (dabt){r, dp[now][r]};
      }
      dp[now ^ 1][i] = q[head].v + abs(a[j] - i);
    }
    now ^= 1;
  }
  long long minn = dp[now][1];
  for (int i = 2; i <= n; i++) minn = min(minn, dp[now][i]);
  cout << all - minn << endl;
  return 0;
}
