#include <bits/stdc++.h>
using namespace std;
const int N = 150005, M = 305;
const long long INF = 4485090715960753727;
int n, m, d;
int a[M], b[M], t[M];
long long f[2][N];
deque<pair<long long, int> > q;
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]);
  memset(f, -63, sizeof(f));
  int cur = 0;
  for (int i = 1; i <= n; i++) f[0][i] = 0;
  for (int i = 1; i <= m; i++) {
    cur ^= 1;
    memset(f[cur], -63, sizeof(f[cur]));
    while (!q.empty()) q.pop_back();
    for (int j = 1; j <= n; j++) {
      while (!q.empty() && j - q.front().second > 1LL * (t[i] - t[i - 1]) * d)
        q.pop_front();
      while (!q.empty() && q.back().first <= f[cur ^ 1][j]) q.pop_back();
      q.push_back(make_pair(f[cur ^ 1][j], j));
      int k = q.front().second;
      f[cur][j] = max(f[cur][j], f[cur ^ 1][k] + b[i] - abs(a[i] - j));
    }
    while (!q.empty()) q.pop_back();
    for (int j = n; j >= 1; j--) {
      while (!q.empty() && q.front().second - j > 1LL * (t[i] - t[i - 1]) * d)
        q.pop_front();
      while (!q.empty() && q.back().first <= f[cur ^ 1][j]) q.pop_back();
      q.push_back(make_pair(f[cur ^ 1][j], j));
      int k = q.front().second;
      f[cur][j] = max(f[cur][j], f[cur ^ 1][k] + b[i] - abs(a[i] - j));
    }
  }
  long long ans = -INF;
  for (int i = 1; i <= n; i++) ans = max(ans, f[cur][i]);
  printf("%lld", ans);
  return 0;
}
