#include <bits/stdc++.h>
using namespace std;
const int N = 2e5, M = 350;
long long dp[5][N], B, a[N], b[N], t[N], n, m, d, minans = 1e9 + 10, dpL[N],
                                                  dpR[N];
int last, ldel;
deque<int> stac;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> d;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> t[i];
    B += b[i];
  }
  for (int j = 0; j < n; j++) dp[0][j] = abs(a[0] - (j + 1));
  for (int i = 1; i < m; i++) {
    last = (i - 1) % 2;
    for (int j = 0; j < n; j++) {
      ldel = j;
      while (!stac.empty() && stac.front() < (j - ((t[i] - t[i - 1]) * d)))
        stac.pop_front();
      while (!stac.empty() && dp[last][stac.back()] >= dp[last][j])
        ldel = stac.back(), stac.pop_back();
      if (stac.empty())
        dpL[j] = dp[last][ldel];
      else
        dpL[j] = dp[last][stac.front()];
      stac.push_back(j);
    }
    for (int j = n - 1; j >= 0; j--) {
      ldel = j;
      while (!stac.empty() && stac.front() > (j + ((t[i] - t[i - 1]) * d)))
        stac.pop_front();
      while (!stac.empty() && dp[last][stac.back()] >= dp[last][j])
        ldel = stac.back(), stac.pop_back();
      if (stac.empty())
        dpR[j] = dp[last][ldel];
      else
        dpR[j] = dp[last][stac.front()];
      stac.push_back(j);
    }
    for (int j = 0; j < n; j++)
      dp[i % 2][j] =
          min(min(dpR[j], dpL[j]), dp[last][j]) + abs(a[i] - (j + 1));
    stac.clear();
  }
  for (int i = 0; i < n; i++) minans = min(minans, dp[(m - 1) % 2][i]);
  cout << B - minans;
}
