#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 150 * 1000 + 10, MAX_M = 300 + 10;
int a[MAX_N], b[MAX_N], t[MAX_N], n, m, d;
long long dp[MAX_N], next_dp[MAX_N];
deque<int> min_num;
void read_input() {
  cin >> n >> m >> d;
  for (int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> t[i];
}
void update_min_num(int i, int j, int k) {
  while (!min_num.empty() && dp[min_num.back()] >= dp[k]) min_num.pop_back();
  min_num.push_back(k);
  while (min_num.front() < 1LL * j - 1LL * (t[i] - t[i - 1]) * d)
    min_num.pop_front();
}
void solve() {
  for (int i = 1; i <= m; i++) {
    for (int k = 1; k <= min(1LL * n, 1LL * (t[i] - t[i - 1]) * d); k++)
      update_min_num(i, 0, k);
    for (int j = 1; j <= n; j++) {
      long long k = 1LL * j + 1LL * (t[i] - t[i - 1]) * d;
      k = min(k, 1LL * n);
      update_min_num(i, j, k);
      update_min_num(i, j, k);
      next_dp[j] = dp[min_num.front()] + abs(a[i] - j);
    }
    for (int j = 1; j <= n; j++) dp[j] = next_dp[j];
    min_num.clear();
  }
}
void print_output() {
  long long ans = (long long)1e16;
  for (int i = 1; i <= n; i++) ans = min(ans, dp[i]);
  ans *= -1;
  for (int i = 1; i <= m; i++) ans += b[i];
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  read_input();
  solve();
  print_output();
}
