#include <bits/stdc++.h>
using namespace std;
const int maxn = 150000 + 7;
int n, m;
long long d;
long long dp[2][maxn];
long long a[305], b[305], t[305];
long long que[maxn];
int main() {
  scanf("%d%d%lld", &n, &m, &d);
  for (int i = 1; i <= m; i++) {
    scanf("%lld%lld%lld", &a[i], &b[i], &t[i]);
  }
  int now = 0;
  long long pre = t[1];
  for (int i = 1; i <= m; i++) {
    int k = 1;
    if (pre == t[i]) {
      for (int j = 1; j <= n; j++) {
        dp[now][j] = dp[now ^ 1][j] + b[i] - abs(a[i] - j);
      }
    } else {
      int L = 1, R = 0;
      long long len = d * (t[i] - pre);
      pre = t[i];
      for (int j = 1; j <= n; j++) {
        while (k <= n && k <= j + len) {
          while (L <= R && dp[now ^ 1][que[R]] < dp[now ^ 1][k]) R--;
          que[++R] = k++;
        }
        while (L <= R && j - len > que[L]) L++;
        dp[now][j] = dp[now ^ 1][que[L]] + b[i] - abs(a[i] - j);
      }
    }
    now ^= 1;
  }
  long long ans = -1e18;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, dp[now ^ 1][i]);
  }
  cout << ans << endl;
  return 0;
}
