#include <bits/stdc++.h>
using namespace std;
int dp[301][150001], n, m, d, eve[301], que[150001][2], t[301];
int solve() {
  memset(dp, 0x3f, sizeof dp);
  int r = dp[0][0];
  for (int x = 1; x <= n; ++x) dp[0][x] = 0;
  for (int e = 0; e < m; ++e) {
    int a = 0, b = 0, p = 1;
    for (int x = 1; x <= n; ++x) {
      long long v = 1LL * d * (t[e + 1] - t[e]);
      while (b > a && que[a][1] < x - v) ++a;
      while (p <= x + v && p <= n) {
        int y = dp[e][p];
        while (b > a && que[b - 1][0] >= y) --b;
        que[b][0] = y;
        que[b++][1] = p++;
      }
      dp[e + 1][x] = min(dp[e + 1][x], que[a][0] + abs(x - eve[e]));
    }
  }
  for (int x = 1; x <= n; ++x) r = min(r, dp[m][x]);
  return r;
}
int main() {
  scanf("%d%d%d", &n, &m, &d);
  long long r = 0;
  for (int i = 0; i < m; ++i) {
    int b;
    scanf("%d%d%d", eve + i, &b, t + i + 1);
    r += b;
  }
  cout << r - solve() << endl;
}
