#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long llINF = 1e18;
const int mod = 998244353;
const double eps = 1e-6;
const int maxn = 3e5 + 10;
long long n, m, d;
long long dp[2][maxn];
long long a[maxn];
long long b[maxn];
long long t[maxn];
deque<int> q;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> d;
  for (int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> t[i];
  bool flag = 0;
  for (int i = 1; i <= n; i++) dp[flag][i] = b[1] - abs(a[1] - i);
  int now;
  for (int i = 2; i <= m; i++) {
    flag = !flag;
    long long add = t[i] - t[i - 1];
    now = 1;
    q.clear();
    for (int j = 1; j <= n; j++) {
      while (now <= min(1ll * n, j + d * add)) {
        while (!q.empty() && dp[!flag][now] > dp[!flag][q.back()]) q.pop_back();
        q.push_back(now);
        now++;
      }
      dp[flag][j] = dp[!flag][q.front()] + b[i] - abs(a[i] - j);
      if (q.front() <= j - add * d) q.pop_front();
    }
  }
  long long ans = -llINF;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, dp[flag][i]);
  }
  cout << ans << endl;
}
