#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, t, k;
  cin >> n >> t >> k;
  long long a[n + 1], b[n + 1], c[n + 1];
  int last = 0;
  long long totalTrains = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    if (a[i] + b[i] * t > c[i]) last = i;
  }
  for (int j = 0; j < t; j++) {
    int newlast = last;
    long long passengers = 0, trains = 0;
    long long nextPassengers = 0, flag = -1, minimumPickup = 0;
    for (int i = 0; i <= last; i++) {
      if (a[i] + b[i] * (t - j) > c[i]) newlast = i;
      if (a[i] + b[i] > c[i]) {
        flag = i;
        minimumPickup = passengers + a[i] - (c[i] - b[i]);
      }
      if (i != last) {
        passengers += a[i];
        nextPassengers += a[i] + b[i];
      }
      if (i == last) {
        passengers += min(a[i] - (c[i] - b[i] * (t - j)), a[i]);
        nextPassengers += min(a[i] - (c[i] - b[i] * (t - j)), a[i]);
      }
    }
    last = newlast;
    if (flag != -1) {
      trains = ceil((double)minimumPickup / (double)k);
    }
    if (j != t - 1 && ceil((double)nextPassengers / (double)k) >=
                          ceil((double)passengers / (double)k) + 1) {
      trains = ceil((double)passengers / (double)k);
    } else
      passengers = minimumPickup;
    totalTrains += trains;
    long long capacity = trains * k;
    for (int i = 0; i < n; i++) {
      long long boarders = min(a[i], capacity);
      capacity -= boarders;
      a[i] += b[i] - boarders;
    }
  }
  cout << totalTrains << endl;
  return 0;
}
