#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 303;
int n, m, d;
int a[maxn], b[maxn], t[maxn];
int dt[maxn];
long long que[150001];
int id[150001];
long long dp[150001][2];
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);
    dt[i] = t[i] - t[i - 1];
  }
  dt[1] = n;
  for (int ii = 1; ii <= m; ++ii) {
    int i = ii % 2;
    int l = 1, r = 1, nl = 1, nr = 1;
    int lt, rt;
    for (int j = 1; j <= n; ++j) {
      lt = max(1ll, 1ll * j - 1ll * dt[ii] * d);
      rt = min(1ll * n, 1ll * j + 1ll * dt[ii] * d);
      while (nr <= rt) {
        while (r > l && dp[nr][1 - i] >= que[r - 1]) r--;
        que[r] = dp[nr][1 - i];
        id[r] = nr;
        r++;
        nr++;
      }
      while (r > l && id[l] < lt) l++;
      dp[j][i] = que[l] + 1ll * b[ii] - 1ll * abs(a[ii] - j);
    }
  }
  long long ans = dp[1][m % 2];
  for (int i = 2; i <= n; ++i) {
    ans = max(ans, dp[i][m % 2]);
  }
  cout << ans << endl;
  return 0;
}
