#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  long n, k;
  long long result = 0;
  cin >> n >> t >> k;
  long a[n], b[n], c[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  for (int i = 0; i < t; i++) {
    long long currentSum = 0, incrementSum = 0;
    long long trains = 0;
    for (int j = 0; j < n; j++) {
      currentSum += a[j];
      incrementSum += b[j];
      if (i < t - 1 && (currentSum + incrementSum >= c[j] + (trains + 1) * k ||
                        currentSum - trains * k + b[j] > c[j])) {
        trains = ceil((double)currentSum / (double)k);
      } else if (i == t - 1 && a[j] + b[j] > c[j] &&
                 currentSum - trains * k + b[j] > c[j]) {
        trains = ceil((double)currentSum / (double)k);
      }
    }
    result += trains;
    long long maxCapacity = trains * k;
    for (int j = 0; j < n; j++) {
      long long boarders = min(maxCapacity, (long long int)a[j]);
      maxCapacity -= boarders;
      a[j] -= boarders;
      a[j] += b[j];
    }
  }
  cout << result << endl;
  return 0;
}
