#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
using pll = pair<LL, LL>;
const int INF = 0x3fffffff;
const double EPS = 1e-9;
const double PI = 2 * asin(1);
const int MX = 150000 + 10;
int g_len, g_n, g_k;
deque<pll> dqpll;
LL dp[2][MX];
void pretreat() {}
bool input() {
  cin >> g_len >> g_n >> g_k;
  if (cin.eof()) return false;
  dqpll.clear();
  memset(dp, 0, sizeof(dp));
  return true;
}
void solve() {
  int p, b, tu = 0, tv, s1 = 0, s2 = 1;
  for (int t = 0; t < g_n; ++t) {
    scanf("%d%d%d", &p, &b, &tv);
    LL len = (LL)g_k * (LL)(tv - tu);
    tu = tv;
    dqpll.clear();
    LL l;
    for (l = 1; abs(l - 1) <= len && l <= g_len; ++l) {
      while (!dqpll.empty() && dqpll.back().first <= dp[s1][l])
        dqpll.pop_back();
      dqpll.emplace_back(dp[s1][l], l);
    }
    for (int i = 1; i <= g_len; ++i) {
      while (abs(dqpll.front().second - i) > len) dqpll.pop_front();
      dp[s2][i] = dqpll.front().first + b - (abs(p - i));
      if (l <= g_len) {
        while (!dqpll.empty() && dqpll.back().first <= dp[s1][l])
          dqpll.pop_back();
        dqpll.emplace_back(dp[s1][l], l);
        ++l;
      }
    }
    swap(s1, s2);
  }
  LL ans = dp[s1][1];
  for (int i = 2; i <= g_len; ++i) ans = max(ans, dp[s1][i]);
  cout << ans << endl;
}
int main() {
  pretreat();
  while (input()) {
    solve();
  }
  return 0;
}
