#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;
  long long a[n], b[n], c[n], ac[n];
  long last = 0;
  long long minimumTrains = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    ac[i] = a[i];
    if (a[i] + b[i] * t > c[i]) last = i;
  }
  for (int tech = 0; tech < 2; tech++) {
    long long totalTrains = 0;
    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]);
        }
        if (tech == 1) {
          if (a[i] + b[i] * (t - j) > c[i] && cummulative <= minimumPickup &&
              i != 0) {
            long long boarders = min(a[i], a[i] + b[i] * (t - j) - c[i]);
            if (minTrains(passengers + cummulativeInc + boarders, k) >
                minTrains(passengers + boarders, k))
              minimumPickup = passengers + boarders;
          }
        }
        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;
      }
    }
    if (tech == 0)
      for (int i = 0; i < n; i++) {
        a[i] = ac[i];
      }
    if (totalTrains < minimumTrains || minimumTrains == -1)
      minimumTrains = totalTrains;
  }
  cout << minimumTrains << endl;
  return 0;
}
