#include <bits/stdc++.h>
using namespace std;
int n, m, d;
long long a[1000005], b[1000005], t[1000005], dp[1000005];
int f, r, q[200005];
long long v[200005];
int main() {
  cin >> n >> m >> d;
  long long lst = 0;
  for (int i = 0; i < m; ++i) {
    int a;
    long long b, t;
    cin >> a >> b >> t;
    a--;
    long long len = (t - lst) * d;
    lst = t;
    f = 0, r = 0;
    for (int j = 0; j < n; ++j) {
      while (f < r && v[r] <= dp[j]) {
        r--;
      }
      q[++r] = j;
      v[r] = dp[j];
      while (f < r && q[f + 1] + len < j) {
        ++f;
      }
      dp[j] = v[f + 1];
    }
    f = 0, r = 0;
    for (int j = n - 1; j >= 0; --j) {
      while (f < r && v[r] <= dp[j]) {
        r--;
      }
      q[++r] = j;
      v[r] = dp[j];
      while (f < r && q[f + 1] - len > j) {
        f++;
      }
      dp[j] = v[f + 1];
    }
    for (int j = 0; j < n; ++j) {
      dp[j] += b - abs(a - j);
    }
  }
  long long ans = -9e18;
  for (int i = 0; i < n; ++i) {
    ans = max(ans, dp[i]);
  }
  cout << ans << '\n';
  return 0;
}
