#include <bits/stdc++.h>
using std::vector;
int main() {
  int n, t, k;
  scanf("%d %d %d", &n, &t, &k);
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) scanf("%d %d %d", &a[i], &b[i], &c[i]);
  vector<vector<vector<long long> > > dp(
      t + 1,
      vector<vector<long long> >(t + 1, vector<long long>(n, 1LL << 61)));
  int ost = 0;
  for (int xt = t - 1; xt >= 0; xt--)
    for (int ct = -1; ct < xt; ct++) {
      long long min_ok = 0;
      long long clean = 0;
      long long pas_left = 0;
      int pop = -1;
      ost = 0;
      for (int i = 0; i < n; i++) {
        const long long cur =
            (ct < 0 ? a[i] - b[i] : 0) + (1LL * (xt - ct)) * b[i];
        const long long fin = cur + (1LL * (t - xt)) * b[i];
        const long long next = cur + b[i] - pas_left;
        if (next > c[i]) {
          long long add = (next - c[i] + k - 1) / k;
          min_ok = clean + add;
        }
        if (fin > c[i]) ost = i;
        long long new_clean = clean;
        long long new_pas = pas_left;
        if (cur <= pas_left) {
          new_pas = pas_left - cur;
        } else {
          long long add = (cur - pas_left + k - 1) / k;
          new_clean = clean + add;
          new_pas = pas_left + add * k - cur;
        }
        if (fin - cur <= c[i]) {
          long long sol = clean;
          long long u = cur - pas_left;
          long long can = c[i] - (fin - cur);
          if (u > can) {
            long long add = (u - can + k - 1) / k;
            sol += add;
          }
          if (min_ok == new_clean) {
            dp[ct + 1][xt][i] =
                (pop == -1 ? 0 : dp[xt + 1][xt + 1][pop]) + new_clean;
          } else {
            dp[ct + 1][xt][i] =
                std::min(dp[ct + 1][xt + 1][i],
                         (pop == -1 ? 0 : dp[xt + 1][xt + 1][pop]) + sol);
          }
        } else {
          pop = i;
          if (min_ok == new_clean) {
            dp[ct + 1][xt][i] = dp[xt + 1][xt + 1][i] + new_clean;
          } else {
            dp[ct + 1][xt][i] = dp[ct + 1][xt + 1][i];
          }
        }
        clean = new_clean;
        pas_left = new_pas;
      }
    }
  std::cout << dp[0][0][ost] << std::endl;
  return 0;
}
