#include <bits/stdc++.h>
using namespace std;
long long n, m, d;
long long dp[150005][5];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m >> d;
  long long pt;
  long long prev, curr;
  for (long long i = 0; i < m; i++) {
    long long a, b, t;
    cin >> a >> b >> t;
    if (i == 0) {
      prev = 0;
      curr = 1;
      for (long long j = 1; j <= n; j++) dp[j][i] = b - abs(a - j);
      pt = t;
    } else {
      for (long long j = 1; j <= n; j++) dp[j][curr] = b - abs(a - j);
      long long s = (t - pt) * d;
      pt = t;
      deque<long long> mq;
      for (long long j = 1; j <= s + 1 && j <= n; j++) {
        while (!mq.empty() && dp[mq.back()][prev] < dp[j][prev]) mq.pop_back();
        mq.push_back(j);
      }
      for (long long j = 1; j <= n; j++) {
        while (!mq.empty() && mq.front() < j - s) mq.pop_front();
        dp[j][curr] += dp[mq.front()][prev];
        if (j + s + 1 <= n) {
          while (!mq.empty() && j + s + 1 <= n &&
                 dp[mq.back()][prev] < dp[j + 1 + s][prev])
            mq.pop_back();
          mq.push_back(j + s + 1);
        }
      }
      swap(prev, curr);
    }
  }
  long long sol = dp[1][prev];
  for (int i = 2; i <= n; i++)
    if (sol < dp[i][prev]) sol = dp[i][prev];
  cout << sol << endl;
  return 0;
}
