#include <bits/stdc++.h>
using namespace std;
const int MVAL = 2020202020;
vector<pair<int, int> > a;
int dp[303][150101];
int main() {
  int n, m, d, i, j, k, l;
  scanf("%d %d %d", &n, &m, &d);
  long long b = 0;
  a.push_back({101, -n});
  for (i = 0; i < m; ++i) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    b += y, a.push_back({x - 1, z});
  }
  for (i = 1; i <= m; ++i) {
    long long step = 1LL * d * (a[i].second - a[i - 1].second);
    int mini = dp[i - 1][0];
    for (k = 0, l = 0; l < n && l < step + 1; ++l)
      if (mini >= dp[i - 1][l]) mini = dp[i - 1][l], k = l;
    for (j = 0; j < n; ++j) {
      int dist = abs(j - a[i].first);
      dp[i][j] = mini + dist;
      if (k + 1 < n && (mini >= dp[i - 1][k + 1] || j - k + 1 > step))
        ++k, mini = dp[i - 1][k];
    }
  }
  int ans = MVAL;
  for (i = 0; i < n; ++i) ans = min(ans, dp[m][i]);
  cout << b - ans << endl;
  return 0;
}
