#include <bits/stdc++.h>
using namespace std;
const int N = 310;
const int inf = 0x3f3f3f3f;
const long long oo = 0x3f3f3f3f3f3f3f3fll;
int n, m, d;
int a[N], b[N], t[N];
long long dp[2][150010];
int que[150010], l, r;
int main() {
  scanf("%d%d%d", &n, &m, &d);
  t[0] = 0;
  long long sum = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a[i], &b[i], &t[i]);
    sum += b[i];
  }
  for (int i = 1; i <= m; i++) {
    l = r = 0;
    memset(dp[i & 1], 0x3f, sizeof(dp[i & 1]));
    for (int j = 1, k = 1; j <= n; j++) {
      while (k <= n && k - j <= 1ll * (t[i] - t[i - 1]) * d) {
        while (l < r) {
          if (dp[(i - 1) & 1][que[r - 1]] >= dp[(i - 1) & 1][k])
            r--;
          else
            break;
        }
        que[r++] = k++;
      }
      while (l < r) {
        if (j - que[l] > 1ll * (t[i] - t[i - 1]) * d)
          l++;
        else
          break;
      }
      dp[i & 1][j] = dp[(i - 1) & 1][que[l]] + abs(a[i] - j);
    }
  }
  long long ans = inf;
  for (int i = 1; i <= n; i++) ans = min(ans, dp[m & 1][i]);
  cout << sum - ans << endl;
  return 0;
}
