#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma optimize("JARU SOSISONI")
using namespace std;
const long long INF = 1e18 + 100;
const long long MOD1 = 998244353;
const long long MOD = 1e9 + 7;
const long long N = 30000;
const long long SIZE = 30100;
const long long LOG = 19;
const long long K = 19;
long long dp[310][N];
struct sparse_table {
  vector<long long> a;
  vector<vector<long long> > s;
  vector<long long> lg;
  long long n;
  sparse_table(long long ind, long long sz) {
    a.resize(sz + 1, -INF);
    n = sz + 1;
    for (long long i = 1; i < n; i++) {
      a[i] = dp[ind][i];
    }
    s.resize(LOG, vector<long long>(n, -INF));
    lg.resize(n + 1, 0);
    build();
  }
  void upd(long long ind) {
    a.assign(n, -INF);
    for (long long i = 1; i < n; i++) {
      a[i] = dp[ind][i];
    }
    build();
  }
  void build() {
    for (long long i = 2; i <= n; i++) {
      lg[i] = lg[i / 2] + 1;
    }
    for (long long j = 0; j < n; j++) {
      s[0][j] = a[j];
    }
    for (long long i = 1; i < LOG; i++) {
      for (long long j = 0; j + (1 << i) <= n; j++) {
        s[i][j] = max(s[i - 1][j], s[i - 1][j + (1 << (i - 1))]);
      }
    }
  }
  long long get(long long i, long long j) {
    if (i > j) swap(i, j);
    long long sz = lg[j - i];
    return max(s[sz][i], s[sz][j - (1 << sz)]);
  }
};
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  long long n, m, d;
  cin >> n >> m >> d;
  vector<long long> a(m), b(m), t(m);
  for (long long i = 0; i < m; i++) cin >> a[i] >> b[i] >> t[i];
  for (long long j = 1; j <= n; j++) {
    dp[0][j] = b[0] - abs(a[0] - j);
  }
  sparse_table smth(0, n);
  for (long long i = 1; i < m; i++) {
    long long time = t[i] - t[i - 1];
    for (long long j = 1; j <= n; j++) {
      dp[i][j] = -INF;
      long long l = max(1ll, j - time * d), r = min(n, j + time * d);
      long long maxx = smth.get(l, r + 1);
      dp[i][j] = maxx + b[i] - abs(a[i] - j);
    }
    smth.upd(i);
  }
  long long ans = -INF;
  for (long long j = 1; j <= n; j++) {
    ans = max(ans, dp[m - 1][j]);
  }
  cout << ans << '\n';
}
