#include <bits/stdc++.h>
using namespace std;
int n, m, d, a[150001];
int64_t _dpa[150001], _dpb[150001], *dpa = _dpa, *dpb = _dpb, b[150001],
                                    t[150001], delta, window_end;
deque<pair<int64_t, int>> q;
int main() {
  scanf("%d%d%d", &n, &m, &d);
  scanf("%d%lld%lld", a, b, t);
  for (int i = 1; i <= n; ++i) dpa[i] = *b - abs(i - *a);
  for (int i = 1; i < m; ++i) {
    swap(dpa, dpb);
    q.clear();
    scanf("%d%lld%lld", a + i, b + i, t + i);
    delta = (t[i] - t[i - 1]) * d;
    window_end = min(delta, int64_t(n));
    for (int j = 1; j <= window_end; ++j) {
      while (!q.empty() && q.back().first <= dpb[j]) q.pop_back();
      q.emplace_back(dpb[j], j);
    }
    for (int j = 1; j <= n; ++j) {
      if (++window_end <= n) {
        while (!q.empty() && q.back().first <= dpb[window_end]) q.pop_back();
        q.emplace_back(dpb[window_end], window_end);
      }
      while (q.front().second < j - delta) q.pop_front();
      dpa[j] = q.front().first + b[i] - abs(j - i[a]);
    }
  }
  printf("%lld", *max_element(dpa + 1, dpa + 1 + n));
}
