#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, d;
  cin >> n >> m >> d;
  pair<long long, long long> ta[300];
  long long bs = 0;
  for (int i = 0; i < m; i++) {
    int a, b, t;
    cin >> a >> b >> t;
    ta[i] = make_pair(t, a);
    bs += b;
  }
  sort(ta, ta + m);
  long long slope[700] = {0}, slmin = -1, slnear0 = -1, slmax = 1;
  slope[310 + -1] = -100;
  slope[310 + 0] = ta[0].second;
  slope[310 + 1] = ta[0].second;
  long long mini = 0, f0 = slope[310 + 0], f1 = slope[310 + 1];
  for (int t = 1; t < m; t++) {
    long long dist = (ta[t].first - ta[t - 1].first) * d;
    if (dist > n) {
      slope[310 + -1] = -100;
      slope[310 + 0] = 0;
      slope[310 + 1] = n;
      f0 = slope[310 + 0];
      f1 = slope[310 + 1];
    } else if (dist > 0) {
      for (int i = slmin; i <= slmax; i++) {
        if (i <= 0) {
          slope[310 + i] -= dist;
        } else if (i > 0) {
          slope[310 + i] += dist;
        }
      }
    }
    f0 = slope[310 + 0];
    f1 = slope[310 + 1];
    int f = 1, nsl = 0;
    for (int i = slmin; i <= slmax; i++) {
      if (slope[310 + i] < ta[t].second) {
        slope[310 + i - 1] = slope[310 + i];
      } else if (f) {
        nsl = slope[310 + i + 1];
        slope[310 + i + 1] = slope[310 + i];
        slope[310 + i] = slope[310 + i - 1] = ta[t].second;
        f = 0;
      } else {
        int nst = slope[310 + i + 1];
        slope[310 + i + 1] = nsl;
        nsl = nst;
      }
    }
    if (slope[310 + slmax] < ta[t].second)
      slope[310 + slmax + 1] = slope[310 + slmax] = ta[t].second;
    --slmin;
    ++slmax;
    if (ta[t].second < f0) {
      mini += f0 - ta[t].second;
    } else if (ta[t].second > f1) {
      mini += ta[t].second - f1;
    }
  }
  cout << bs - mini << endl;
  return 0;
}
