#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
class Event {
 public:
  Event(const int _time = 0, const int _position = 0)
      : time(_time), position(_position) {}
  int Time() const { return time; }
  int Position() const { return position; }

 private:
  int time, position;
};
int N, M, D;
vector<Event> Events;
long long Answer;
void Solve() {
  int time = 0;
  vector<int> dp = vector<int>(N, 0);
  for (int m = 0; m < M; ++m) {
    vector<int> newDP = vector<int>(N, oo);
    int newTime = Events[m].Time();
    int range = int(min(1LL * N, 1LL * (newTime - time) * D));
    deque<pair<int, int> > deq;
    for (int n = 0, r = 0; n <= Events[m].Position(); ++n) {
      for (; !deq.empty() && deq.front().first < n - range; deq.pop_front())
        ;
      for (; r < N && r <= n + range; ++r) {
        for (; !deq.empty() && deq.back().second >= dp[r]; deq.pop_back())
          ;
        deq.push_back(make_pair(r, dp[r]));
      }
      newDP[n] = min(newDP[n], deq.front().second + Events[m].Position() - n);
    }
    deq = deque<pair<int, int> >();
    for (int n = N - 1, l = N - 1; n > Events[m].Position(); --n) {
      for (; !deq.empty() && deq.front().first > n + range; deq.pop_front())
        ;
      for (; l >= 0 && l >= n - range; --l) {
        for (; !deq.empty() && deq.back().second >= dp[l]; deq.pop_back())
          ;
        deq.push_back(make_pair(l, dp[l]));
      }
      newDP[n] = min(newDP[n], deq.front().second + n - Events[m].Position());
    }
    dp = newDP;
    time = newTime;
  }
  int minDP = oo;
  for (int n = 0; n < N; ++n) minDP = min(minDP, dp[n]);
  Answer -= minDP;
}
void Read() {
  Answer = 0;
  cin >> N >> M >> D;
  Events = vector<Event>(M);
  for (int i = 0; i < M; ++i) {
    int time, position, add;
    cin >> position >> add >> time;
    --position;
    --time;
    Events[i] = Event(time, position);
    Answer += add;
  }
}
void Print() { cout << Answer << "\n"; }
int main() {
  Read();
  Solve();
  Print();
  return 0;
}
