#include <bits/stdc++.h>
using namespace std;
long long int DP[150000], DP_old[150000];
struct MaxStack {
  vector<long long int> S;
  vector<long long int> M;
  void Push(long long int x) {
    S.push_back(x);
    if ((int)(M).size() == 0)
      M.push_back(x);
    else
      M.push_back((((x) > (M.back())) ? (x) : (M.back())));
  }
  long long int Pop(void) {
    long long int b = S.back();
    S.pop_back();
    M.pop_back();
    return b;
  }
  long long int Max(void) {
    if ((int)(M).size())
      return (M.back());
    else
      return -1000000000000000001LL;
  }
  int Size(void) { return ((int)(S).size()); }
  bool Empty(void) { return (Size() == 0); }
};
struct MaxQueue {
  MaxStack S1, S2;
  void Push(long long int x) { S2.Push(x); }
  long long int Pop(void) {
    if (S1.Empty())
      while (!S2.Empty()) S1.Push(S2.Pop());
    return S1.Pop();
  }
  long long int Max(void) {
    return ((((S1.Max()) > (S2.Max())) ? (S1.Max()) : (S2.Max())));
  }
  int Size(void) { return (S1.Size() + S2.Size()); }
  bool Empty(void) { return (S1.Empty() && S2.Empty()); }
};
int main() {
  ios_base::sync_with_stdio(0);
  int n, m, d;
  cin >> n >> m >> d;
  int last_t = -n;
  for (int i = (1); i <= (m); ++i) {
    int a, b, t;
    cin >> a >> b >> t;
    a--;
    MaxQueue Q;
    int it_l = 0, it_r = -1,
        dist = (((n) < ((long long int)d * (t - last_t)))
                    ? (n)
                    : ((long long int)d * (t - last_t)));
    for (int j = (0); j <= (n - 1); ++j) {
      while (it_r < n - 1 && it_r < j + dist) Q.Push(DP_old[++it_r]);
      while (it_l < j - dist) {
        ++it_l;
        Q.Pop();
      }
      DP[j] = Q.Max() + b - (((a - j) > 0) ? (a - j) : -(a - j));
    }
    for (int j = (0); j <= (n - 1); ++j) DP_old[j] = DP[j];
    last_t = t;
  }
  long long int ans = -1000000000000000001LL;
  for (int j = (0); j <= (n - 1); ++j)
    ans = (((ans) > (DP[j])) ? (ans) : (DP[j]));
  cout << ans;
  return 0;
}
