#include <bits/stdc++.h>
using namespace std;
int n, m, d;
long long a[150005], b[150005], Time[150005];
long long dp[2][150005];
long long q[150005];
void ok() { cout << "ok" << endl; }
int main() {
  while (~scanf("%d%d%d", &n, &m, &d)) {
    for (int i = 1; i <= m; i++) {
      scanf("%d%d%d", &a[i], &b[i], &Time[i]);
    }
    for (int i = 1; i <= n; i++) dp[0][i] = b[1] - abs(a[1] - i);
    int cur = 0;
    for (int i = 2; i <= m; i++) {
      int h = 0, t = 0;
      cur ^= 1;
      memset(dp[cur], 0, sizeof(dp[cur]));
      long long k = (Time[i] - Time[i - 1]) * d;
      if (k > n) k = n;
      for (int j = 1; j <= k; j++) {
        while (h < t && dp[cur ^ 1][j] > dp[cur ^ 1][q[t - 1]]) t--;
        q[t++] = j;
      }
      for (int j = 1; j <= n; j++) {
        int l = j - k;
        int r = j + k;
        if (l <= 0) l = 1;
        while (h < t && q[h] < l) h++;
        if (r <= n) {
          while (h < t && dp[cur ^ 1][r] > dp[cur ^ 1][q[t - 1]]) t--;
          q[t++] = r;
        }
        dp[cur][j] = dp[cur ^ 1][q[h]] + b[i] - abs(a[i] - j);
      }
    }
    long long ans = dp[cur][1];
    for (int i = 1; i <= n; i++) ans = max(ans, dp[cur][i]);
    printf("%lld\n", ans);
  }
  return 0;
}
