#include <bits/stdc++.h>
using namespace std;
struct data {
  long long a, b, t;
  data() {}
  data(int x, int y, int z) { a = x, b = y, t = z; }
};
vector<data> tt[333];
long long dp[2][150005];
int dq[150005], S, E;
long long val[150005];
int n, m, N;
long long d;
int main() {
  cin >> n >> m >> d;
  vector<int> times;
  map<int, int> tid;
  vector<data> xx;
  long long ans = 0;
  xx.push_back(data(1, 0, 0));
  times.push_back(0);
  for (int i = 0; i < m; ++i) {
    int a, b, t;
    cin >> a >> b >> t;
    times.push_back(t);
    xx.push_back(data(a, b, t));
    ans += b;
  }
  sort(times.begin(), times.end());
  times.erase(unique(times.begin(), times.end()), times.end());
  N = times.size();
  for (int i = 0; i < N; ++i) tid[times[i]] = i;
  for (int i = 0; i < m + 1; ++i) tt[tid[xx[i].t]].push_back(xx[i]);
  memset(dp, 0, sizeof(dp));
  int cur = 0, nxt = 1;
  for (int i = 1; i < N; ++i) {
    int len = min((long long)n, d * (times[i] - times[i - 1])), s, e;
    val[1] = 0;
    for (int j = 0; j < tt[i].size(); ++j) val[1] += abs(1 - tt[i][j].a);
    s = max(1, 1 - len), e = min(n, 1 + len), S = 0, E = 0;
    for (int j = s; j <= e; ++j) {
      while (S < E && dp[cur][dq[E - 1]] < dp[cur][j]) E--;
      dq[E++] = j;
    }
    dp[nxt][1] = dp[cur][dq[S]] - val[1];
    for (int c = 2; c <= n; ++c) {
      val[c] = 0;
      for (int j = 0; j < tt[i].size(); ++j) {
        val[c] += abs(c - tt[i][j].a);
      }
      s = max(1, c - len), e = min(n, c + len);
      while (c + len <= n && S < E && dp[cur][dq[E - 1]] < dp[cur][e]) E--;
      if (c + len <= n) dq[E++] = e;
      while (S < E && dq[S] < s) S++;
      dp[nxt][c] = dp[cur][dq[S]] - val[c];
    }
    swap(cur, nxt);
  }
  long long add = -(1ll << 62);
  for (int c = 1; c <= n; ++c) add = max(add, dp[cur][c]);
  cout << add + ans << endl;
}
