#include <bits/stdc++.h>
using namespace std;
const int N = 301;
int n, m, d;
int a[N], b[N], t[N];
long long dp[2][150001];
int main() {
  scanf("%d%d%d", &n, &m, &d);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", a + i, b + i, t + i);
    a[i]--;
  }
  int cur = 0;
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < m; i++) {
    memset(dp[cur], 0, sizeof(dp[cur]));
    deque<pair<long long, int> > window;
    long long T = t[i] - (i == 0 ? 0 : t[i - 1]),
              inter = min((long long)n - 1, T * d);
    for (int j = 0; j <= inter; j++) {
      while (!window.empty() && window.back().first <= dp[cur ^ 1][j])
        window.pop_back();
      window.push_back(make_pair(dp[cur ^ 1][j], j));
    }
    for (int j = 0; j < n; j++) {
      if (j + inter < n) {
        int tmp = j + (int)inter;
        while (!window.empty() && window.back().first <= dp[cur ^ 1][tmp])
          window.pop_back();
        window.push_back(make_pair(dp[cur ^ 1][tmp], tmp));
      }
      dp[cur][j] = window.front().first + b[i] - abs(a[i] - j);
      while (!window.empty() && window.front().second <= (j - inter))
        window.pop_front();
    }
    cur ^= 1;
  }
  long long ans = -(long long)1e18;
  for (int i = 0; i < n; i++) ans = max(ans, dp[cur ^ 1][i]);
  printf("%lld\n", ans);
  return 0;
}
