#include <bits/stdc++.h>
int n, m, k;
int a[150001], b[150001], t[150001];
long long f[2][150001];
long long ans = -1e18;
std::deque<int> q;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  t[0] = 1;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", a + i, b + i, t + i);
    int T = std::min((long long)(t[i] - t[i - 1]) * k, (long long)n);
    q.clear();
    for (int j = 1; j <= T; ++j) {
      while (!q.empty() && f[i & 1 ^ 1][j] >= f[i & 1 ^ 1][q.back()])
        q.pop_back();
      q.push_back(j);
    }
    for (int j = 1; j <= n; ++j) {
      if (j + T <= n) {
        while (!q.empty() && f[i & 1 ^ 1][j + T] >= f[i & 1 ^ 1][q.back()])
          q.pop_back();
        q.push_back(j + T);
      }
      while (!q.empty() && q.front() < j - T) q.pop_front();
      f[i & 1][j] = f[i & 1 ^ 1][q.front()] + b[i] - std::abs(a[i] - j);
    }
  }
  for (int i = 1; i <= n; ++i) ans = std::max(ans, f[m & 1][i]);
  printf("%lld\n", ans);
  return 0;
}
