#include <bits/stdc++.h>
using namespace std;
const int maxn = 330;
const long long inf = 1LL << 62;
int n, m;
long long d;
struct Fire {
  int a;
  long long b, t;
  bool operator<(const Fire &a) const { return t < a.t; }
};
pair<int, long long> qu[450010];
Fire fire[maxn];
long long dp[2][150010];
int main() {
  while (~scanf("%d%d%lld", &n, &m, &d)) {
    fire[0].t = 0;
    for (int i = 1; i <= m; i++)
      scanf("%d%lld%lld", &fire[i].a, &fire[i].b, &fire[i].t);
    sort(fire + 1, fire + 1 + m);
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= m; i++) {
      long long t = fire[i].t - fire[i - 1].t;
      int l = 1, r = 0;
      for (int j = 1; j <= n; j++) {
        dp[i & 1][j] = -inf;
        while (l <= r && qu[r].second < dp[!(i & 1)][j]) r--;
        qu[++r] = make_pair(j, dp[!(i & 1)][j]);
        if (j > t * d) {
          int pos = j - t * d;
          while (l <= r && qu[l].first + d * t < pos) l++;
          if (l <= r)
            dp[i & 1][pos] = max(dp[i & 1][pos], qu[l].second + fire[i].b -
                                                     abs(fire[i].a - pos));
        }
      }
      for (int j = max(1ll * n - t * d + 1, 1ll); j <= n; j++) {
        while (l <= r && qu[l].first + d * t < j) l++;
        if (l <= r)
          dp[i & 1][j] =
              max(dp[i & 1][j], qu[l].second + fire[i].b - abs(fire[i].a - j));
      }
    }
    long long res = -inf;
    for (int i = 1; i <= n; i++) res = max(res, dp[m & 1][i]);
    printf("%lld\n", res);
  }
}
