#include <bits/stdc++.h>
using namespace std;
int N, M, D, A, B, T;
long long dp[2][150000];
int st[150000], s, t;
int main() {
  scanf("%d%d%d", &N, &M, &D);
  int lt = 1;
  for (int(i) = 0; (i) < (M); (i)++) {
    scanf("%d%d%d", &A, &B, &T);
    A--;
    s = 0, t = 0;
    for (int(j) = 0; (j) < (N); (j)++) {
      while (s < t && dp[i % 2][st[t - 1]] <= dp[i % 2][j]) t--;
      st[t++] = j;
      dp[(i + 1) % 2][j] = dp[i % 2][st[s]] + B - abs(A - j);
      if (st[s] == j - D * (T - lt)) s++;
    }
    s = t = 0;
    for (int j = N - 1; j >= 0; j--) {
      while (s < t && dp[i % 2][st[t - 1]] <= dp[i % 2][j]) t--;
      st[t++] = j;
      dp[(i + 1) % 2][j] =
          max(dp[(i + 1) % 2][j], dp[i % 2][st[s]] + B - abs(A - j));
      if (st[s] == j + D * (T - lt)) s++;
    }
    lt = T;
  }
  long long ans = -(1LL << 60);
  for (int(i) = 0; (i) < (N); (i)++) ans = max(ans, dp[M % 2][i]);
  printf("%I64d\n", ans);
}
