#include <bits/stdc++.h>
using namespace std;
const int MAXN = 150005;
const int MAXM = 303;
long long dp[2][MAXN];
int a[MAXM];
int b[MAXM];
int t[MAXM];
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, d;
  cin >> n >> m >> d;
  long long ans = -1e18;
  for (int i = 1; i <= m; ++i) {
    cin >> a[i] >> b[i] >> t[i];
  }
  for (int i = 1; i <= m; ++i) {
    deque<int> q;
    int curr = 1;
    ans = -1e18;
    for (int j = 1; j <= n; ++j) {
      while (curr - j <= (long long)d * (t[i] - t[i - 1]) and curr <= n) {
        while (!q.empty() and
               dp[1 - (i & 1)][curr] >= dp[1 - (i & 1)][q.back()]) {
          q.pop_back();
        }
        q.push_back(curr);
        ++curr;
      }
      while (j - q.front() > (long long)d * (t[i] - t[i - 1])) {
        q.pop_front();
      }
      dp[i & 1][j] = b[i] - abs(a[i] - j) + dp[1 - (i & 1)][q.front()];
      ans = max(ans, dp[i & 1][j]);
    }
  }
  cout << ans;
}
