#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, d, a[305], b[305], c[305];
  long long sec[150005], left[150005], right[150005];
  while (cin >> n >> m >> d) {
    long long sum = 0, ans;
    for (int i = 0; i < m; i++) cin >> a[i] >> b[i] >> c[i];
    for (int i = 0; i < m; i++) sum += b[i];
    for (int i = 1; i <= n; i++) sec[i] = 0;
    long long int when = c[0];
    for (int i = 0; i < m; i++) {
      long long units = (c[i] - when) * d;
      if (units > n) units = n;
      left[1] = sec[1];
      for (int j = 2; j <= n; j++)
        if (sec[j] < left[j - 1])
          left[j] = sec[j];
        else
          left[j] = left[j - 1];
      right[n] = sec[n];
      for (int j = n - 1; j >= 1; j--)
        if (sec[j] < right[j + 1])
          right[j] = sec[j];
        else
          right[j] = right[j + 1];
      for (int j = 1; j <= n; j++) {
        int l = j - units;
        int r = j + units;
        if (l < 1) l = 1;
        if (r > n) r = n;
        if (right[l] == left[r])
          sec[j] = right[l];
        else if (right[l] > left[r])
          sec[j] = right[l];
        else
          sec[j] = left[r];
      }
      for (int j = 1; j <= a[i]; j++) sec[j] += a[i] - j;
      for (int j = a[i] + 1; j <= n; j++) sec[j] += j - a[i];
      when = c[i];
    }
    ans = sec[1];
    for (int i = 2; i <= n; i++)
      if (ans > sec[i]) ans = sec[i];
    cout << (sum - ans) << endl;
  }
  return 0;
}
