#include <bits/stdc++.h>
using namespace std;
typedef long double real;
struct Node {
  int l, r, m;
  signed long long int maxv;
  Node *lson, *rson;
  Node(int l, int r) : l(l), r(r), m((l + r) / 2), maxv(0), lson(0), rson(0) {
    if (l != r) {
      lson = new Node(l, m);
      rson = new Node(m + 1, r);
    }
  }
  ~Node() {
    if (lson) {
      delete lson;
      delete rson;
    }
  }
  void set(int ind, signed long long int val) {
    if (l == r) {
      maxv = val;
      return;
    }
    if (ind < m + 1) {
      lson->set(ind, val);
    } else {
      rson->set(ind, val);
    }
    maxv = max(lson->maxv, rson->maxv);
  }
  signed long long int get(int tl, int tr) {
    if (r < tl || l > tr) {
      return -LLONG_MAX;
    }
    if (tl <= l && r <= tr) {
      return maxv;
    }
    return max(lson->get(tl, tr), rson->get(tl, tr));
  }
  void clear() {
    maxv = 0;
    if (l == r) {
      return;
    }
    lson->clear();
    rson->clear();
  }
};
struct firework {
  int a, b, t;
  firework() : a(0), b(0), t(0) {}
  firework(int a, int b, int t) : a(a), b(b), t(t) {}
  void read() { scanf("%d %d %d", &a, &b, &t); }
};
struct myque {
  vector<pair<signed long long int, signed long long int> > front, back;
  myque(int sz) {
    front.reserve(sz);
    back.reserve(sz);
  }
  void replace() {
    assert(back.size());
    while (!back.empty()) {
      front.push_back(
          make_pair(back.back().first,
                    max(back.back().first,
                        front.empty() ? -LLONG_MAX : front.back().second)));
      back.pop_back();
    }
  }
  void pop_front() {
    if (front.empty()) {
      replace();
    }
    front.pop_back();
  }
  void push_back(signed long long int e) {
    back.push_back(
        make_pair(e, max(e, back.empty() ? -LLONG_MAX : back.back().second)));
  }
  signed long long int getmax() {
    return max(back.empty() ? -LLONG_MAX : back.back().second,
               front.empty() ? -LLONG_MAX : front.back().second);
  }
  int size() { return back.size() + front.size(); }
};
bool operator<(const firework &f1, const firework &f2) {
  return f1.t < f2.t || (f1.t == f2.t && f1.a < f2.a);
}
int n, m, d;
vector<firework> L;
signed long long int dp[2][150001];
Node *tree[2];
int main() {
  scanf("%d %d %d", &n, &m, &d);
  L.resize(m + 1);
  for (int i = 1; i <= m; ++i) {
    L[i].read();
  }
  sort((L).begin(), (L).end());
  int curr = 1;
  myque Q(n);
  while (curr <= m) {
    signed long long int l = 1ll * d * (L[curr].t - L[curr - 1].t);
    int lim = curr;
    int ptr = curr;
    signed long long int sumb = 0;
    signed long long int suma = 0;
    while (lim <= m && L[lim].t == L[curr].t) {
      sumb += L[lim].b;
      suma += L[lim].a - 1;
      ++lim;
    }
    int numl = 0;
    int numr = lim - curr;
    for (int i = 1; i <= min(n * 1ll, 1 + l); ++i) {
      Q.push_back(dp[0][i]);
    }
    for (int i = 1; i <= n; ++i) {
      while (ptr < lim && L[ptr].a == i) {
        ++numl;
        --numr;
        ++ptr;
      }
      dp[1][i] = Q.getmax();
      dp[1][i] += sumb - suma;
      if (i - l > 0) {
        Q.pop_front();
      }
      if (i + l + 1 <= n) {
        Q.push_back(dp[0][i + l + 1]);
      }
      suma = suma + numl - numr;
    }
    while (Q.size()) {
      Q.pop_front();
    }
    for (int i = 1; i <= n; ++i) {
      dp[0][i] = dp[1][i];
    }
    curr = lim;
  }
  signed long long int ans = -LLONG_MAX;
  for (int i = 1; i <= n; ++i) {
    ans = max(ans, dp[0][i]);
  }
  printf("%I64d\n", ans);
}
