#include <bits/stdc++.h>
using namespace std;
long long n, m, d;
long long dp[2][150005];
int a[305][3];
void go_mono(int id) {
  deque<pair<long long, long long> > window;
  vector<long long> v(n + 1, LLONG_MIN);
  int cnt = 0;
  for (int j = 1; j <= n; j++) {
    cnt++;
    while (!window.empty() && window.back().first <= dp[(id - 1) & 1][j])
      window.pop_back();
    window.push_back({dp[(id - 1) & 1][j], j});
    while (j - window.front().second > (a[id][2] - a[id - 1][2]) * d)
      window.pop_front();
    v[j] = max(v[j], window.front().first);
  }
  window.clear();
  for (int j = n; j >= 1; j--) {
    cnt++;
    while (!window.empty() && window.back().first <= dp[(id - 1) & 1][j])
      window.pop_back();
    window.push_back({dp[(id - 1) & 1][j], j});
    while (window.front().second - j > (a[id][2] - a[id - 1][2]) * d)
      window.pop_front();
    v[j] = max(v[j], window.front().first);
    dp[id & 1][j] += v[j];
  }
}
int main() {
  scanf("%lld%lld%lld", &n, &m, &d);
  for (int i = 1; i <= m; i++)
    for (int j = 0; j < 3; j++) scanf("%d", &a[i][j]);
  a[0][2] = a[1][2];
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) dp[i & 1][j] = a[i][1] - abs(j - a[i][0]);
    go_mono(i);
  }
  long long ans = LLONG_MIN;
  for (int j = 1; j <= n; j++) ans = max(ans, dp[m & 1][j]);
  cout << ans << '\n';
  return 0;
}
