#include <bits/stdc++.h>
using namespace std;
int t[150005], b[150005], a[150005];
long long DP[2][150005];
pair<long long, long long> st1[150005], st2[150005];
int main() {
  int n, m, d;
  cin >> n >> m >> d;
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &a[i], &b[i], &t[i]);
    a[i]--;
  }
  for (int i = 0; i < n; i++) DP[0][i] = b[0] - abs(i - a[0]);
  for (int i = 1; i < m; i++) {
    for (int j = 0; j < n; j++) DP[i & 1][j] = -1000000000000000000LL;
    long long tmp = d * 1LL * (t[i] - t[i - 1]);
    for (int first = 0; first < 2; first++) {
      int x = 0, y = 0;
      int j = 0;
      if (first) j = n - 1;
      while (1) {
        if (first && j < 0) break;
        if (!first && j == n) break;
        if (x + y > tmp) {
          if (y == 0) {
            while (x) {
              x--;
              st2[y] = make_pair(st1[x].first, st1[x].first);
              if (y) st2[y].second = max(st2[y - 1].second, st2[y].second);
              y++;
            }
          }
          y--;
        }
        st1[x] = make_pair(DP[1 - (i & 1)][j], DP[1 - (i & 1)][j]);
        if (x) st1[x].second = max(st1[x - 1].second, st1[x].second);
        x++;
        long long t = st1[x - 1].second;
        if (y) t = max(t, st2[y - 1].second);
        DP[i & 1][j] = max(DP[i & 1][j], t + b[i] - abs(j - a[i]));
        if (first)
          j--;
        else
          j++;
      }
    }
  }
  long long ans = -1000000000000000000LL;
  for (int i = 0; i < n; i++) ans = max(ans, DP[(m - 1) & 1][i]);
  cout << ans;
  return 0;
}
