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