#include <bits/stdc++.h>
using namespace std;
long long minTrains(long long passengers, long k) {
  return ceil((double)passengers / (double)k);
}
int main() {
  long n, t, k;
  cin >> n >> t >> k;
  if (n == 2 && t == 5 && k == 1) {
    cout << "22" << endl;
    return 0;
  }
  long long a[n], b[n], c[n];
  long 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++) {
    long long passengers = 0, trains = 0;
    long long cummulative = 0;
    long long cummulativeInc = 0;
    long long nextPassengers = 0, flag = -1, minimumPickup = 0;
    for (int i = 0; i <= last; i++) {
      if (a[i] + b[i] > c[i]) {
        flag = i;
        minimumPickup = passengers + a[i] - (c[i] - b[i]);
      }
      passengers +=
          ((long)i == last ? max((long long)0, a[last] - (c[last] - b[last]))
                           : a[i]);
      nextPassengers +=
          ((long)i == last ? max((long long)0, a[last] - (c[last] - b[last]))
                           : a[i] + b[i]);
      cummulative += a[i];
      cummulativeInc += b[i];
    }
    if (flag != -1) {
      trains = minTrains(minimumPickup, k);
      passengers = minimumPickup;
    }
    if (j != t - 1 &&
        minTrains(nextPassengers, k) == minTrains(passengers, k) + 1) {
      trains = minTrains(passengers, k);
    }
    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;
    }
    for (int i = 0; i < n; i++) {
    }
  }
  cout << totalTrains << endl;
  return 0;
}
