#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  int a[200] = {0};
  int b[200] = {0};
  int c[200] = {0};
  int n = 0, t = 0, k = 0;
  cin >> n >> t >> k;
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
  while (t) {
    for (int i = 0; i < n; i++) {
      a[i] = a[i] + b[i];
    }
    t--;
  }
  bool ok = false;
  for (int i = 0; i < n; i++) {
    if (a[i] > c[i]) ok = true;
  }
  int num = 0;
  if (ok) {
    while (ok) {
      for (int i = 0; i < n; i++) {
        if (a[i] > c[i]) {
          while (a[i] > c[i]) {
            a[i] = a[i] - k;
            num++;
          }
        }
        if (a[i] <= c[i]) {
          if (i == (n - 1)) {
            while (a[i] > c[i]) {
              a[i] = a[i] - k;
              num++;
            }
          } else {
            a[i + 1] = a[i + 1] - (c[i] - a[i]);
            a[i] = c[i];
          }
        }
      }
      ok = false;
    }
  }
  num++;
  cout << num;
  return 0;
}
