#include <bits/stdc++.h>
using namespace std;
const long long Max = 151000;
long long dp[2][Max];
int t[Max];
int a[Max];
long long n, m, d;
long long solve() {
  deque<long long> que;
  for (long long i = 0; i < n; i++) {
    dp[0][i] = abs(a[0] - i);
  }
  long long f = 0;
  for (long long i = 1; i < m; i++) {
    long long y;
    y = (t[i] - t[i - 1]) * d;
    if (y > n - 1) y = n - 1;
    que.clear();
    long long l, r;
    l = r = 0;
    for (long long j = 0; j <= y; j++) {
      while (!que.empty() && dp[f][que[que.size() - 1]] > dp[f][j])
        que.pop_back();
      que.push_back(j);
    }
    for (long long j = 0; j < n; j++) {
      l = j - y;
      r = j + y;
      if (l < 0) l = 0;
      while (!que.empty() && que.front() < l) que.pop_front();
      if (r < n) {
        while (!que.empty() && dp[f][que[que.size() - 1]] > dp[f][r])
          que.pop_back();
        que.push_back(r);
      }
      dp[f ^ 1][j] = dp[f][que.front()] + abs(a[i] - j);
    }
    f = f ^ 1;
  }
  long long m = dp[f][0];
  for (long long i = 1; i < n; i++) {
    m = min(dp[f][i], m);
  }
  return m;
}
int main() {
  long long b = 0;
  int te;
  cin >> n >> m >> d;
  for (long long i = 0; i < m; i++) {
    scanf("%d%d%d", &a[i], &te, &t[i]);
    a[i] -= 1;
    b += te;
  }
  cout << b - solve() << endl;
  return 0;
}
