#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 2e9;
const long long INF64 = 1e18;
const long double EPS = 1e-12;
const long double PI = 3.1415926535897932384626433832795028841;
const long long MD = 925262732;
const long long T = 634521;
const int N = 150010;
const int M = 301;
struct st {
  stack<pair<long long, long long> > s1, s2;
  void cle() {
    while (!s1.empty()) s1.pop();
    while (!s2.empty()) s2.pop();
  }
  void push(long long first) {
    long long q = -INF64;
    if (!s1.empty()) q = s1.top().second;
    s1.push(make_pair(first, max(first, q)));
  }
  void pop() {
    if (s2.empty()) {
      while (!s1.empty()) {
        long long q = -INF64;
        if (!s2.empty()) q = s2.top().second;
        s2.push(make_pair(s1.top().first, max(s1.top().first, q)));
        s1.pop();
      }
    }
    if (!s2.empty()) s2.pop();
  }
  long long maxi() {
    long long q = -INF64;
    if (!s1.empty()) q = max(q, s1.top().second);
    if (!s2.empty()) q = max(q, s2.top().second);
    return q;
  }
} s;
int n, m;
long long d[N], d1[N], dd;
int a[M], b[M], t[M];
int main() {
  cin >> n >> m >> dd;
  t[0] = 1;
  for (int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> t[i];
  for (int i = 1; i <= m; i++) {
    for (int first = 1; first <= n; first++) {
      d1[first] = d[first];
      d[first] = 0;
    }
    long long q = dd * (t[i] - t[i - 1]);
    s.cle();
    for (int first = 1; first <= n; first++) {
      if (first - q > 1) s.pop();
      s.push(d1[first]);
      d[first] = s.maxi() + b[i] - abs(a[i] - first);
    }
    s.cle();
    for (int first = n; first >= 1; first--) {
      if (first + q < n) s.pop();
      s.push(d1[first]);
      d[first] = max(d[first], s.maxi() + b[i] - abs(a[i] - first));
    }
  }
  long long ans = -INF64;
  for (int i = 1; i <= n; i++) ans = max(ans, d[i]);
  cout << ans;
  return 0;
}
