#include <bits/stdc++.h>
using namespace std;
const int N = 150010;
const int M = 310;
long long a[M], b[M], t[M], dp[N], L[N], R[N];
deque<int> dq;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, d;
  cin >> n >> m >> d;
  for (int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> t[i];
  for (int i = 1; i <= m; i++) {
    long long dis = (t[i] - t[i - 1]) * d;
    dq.clear();
    for (int j = 1; j <= n; j++) {
      while (!dq.empty() && dp[dq.back()] <= dp[j]) dq.pop_back();
      if (!dq.empty() && dis < j - dq.front()) dq.pop_front();
      dq.push_back(j);
      L[j] = dp[dq.front()];
    }
    dq.clear();
    for (int j = n; j >= 1; j--) {
      while (!dq.empty() && dp[dq.back()] <= dp[j]) dq.pop_back();
      if (!dq.empty() && dis < dq.front() - j) dq.pop_front();
      dq.push_back(j);
      R[j] = dp[dq.front()];
    }
    for (int j = 1; j <= n; j++) dp[j] = max(L[j], R[j]) + b[i] - abs(a[i] - j);
  }
  long long ans = -1e18;
  for (int i = 1; i <= n; i++) ans = max(ans, dp[i]);
  cout << ans;
  return 0;
}
