#include <bits/stdc++.h>
using namespace std;
int n, m, d;
long long a[305], b[305], t[305];
long long mind[2][150005];
pair<int, int> q[550005];
int main() {
  cin >> n >> m >> d;
  for (int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> t[i];
  t[0] = 1;
  for (int i = 1; i <= m; i++) {
    int g = i % 2;
    long long f = (t[i] - t[i - 1]) * d;
    long long x = max(1LL, 1 - f);
    long long y = min(n * 1LL, 1 + f);
    long long head = 1, tail = 1;
    for (int j = x; j <= y; j++) {
      if (j == x) {
        q[head].first = x;
        q[head].second = x;
      } else {
        while (tail >= head && mind[1 - g][q[tail].first] > mind[1 - g][j] &&
               tail >= head)
          tail--;
        tail++;
        q[tail].first = j;
        q[tail].second = j;
      }
    }
    for (int j = 1; j <= n; j++) {
      int z = max(1LL, j - f);
      while (q[head].second < z && q[head].second != 0) head++;
      z = min(n * 1LL, j + f);
      while (q[tail].first > 0 && mind[1 - g][q[tail].first] > mind[1 - g][z] &&
             tail >= head)
        tail--;
      tail++;
      q[tail].first = z;
      q[tail].second = z;
      mind[g][j] = mind[1 - g][q[head].first] + abs(a[i] - j);
    }
  }
  long long ans = 2e9, sum = 0;
  for (int i = 1; i <= m; i++) sum += b[i];
  for (int i = 1; i <= n; i++) ans = min(ans, mind[m % 2][i]);
  cout << -ans + sum;
  return 0;
}
