#include <bits/stdc++.h>
using namespace std;
const int mxn = 205;
const long long INF = 1e13;
long long n, m, i, j, t, k, s, K, f[mxn][mxn][2], g[mxn][mxn][2], a[mxn],
    b[mxn], c[mxn], qza[mxn], qzb[mxn];
int main() {
  scanf("%lld%lld%lld", &n, &m, &K);
  memset(f, 0x3f3f3f3f, sizeof(f));
  memset(g, 0x3f3f3f3f, sizeof(g));
  memset(f, 0, sizeof(*f));
  memset(g, 0, sizeof(*g));
  for (i = 1; i <= n; ++i)
    scanf("%lld%lld%lld", &a[i], &b[i], &c[i]), qza[i] = qza[i - 1] + a[i],
                                                qzb[i] = qzb[i - 1] + b[i];
  ++n;
  a[n] = 19198101919810514ll;
  b[n] = 0ll;
  c[n] = a[n] + 1ll;
  qza[n] = qza[n - 1] + a[n];
  qzb[n] = qzb[n - 1] + b[n];
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) {
      long long ed = b[i] * 1ll * j, tmp;
      if (ed <= c[i]) {
        f[i][j][0] = f[i - 1][j][0];
        tmp = (qzb[i - 1] * j + K - 1) / K;
        if (tmp * K <= qzb[i] * j)
          g[i][j][0] = tmp, f[i][j][0] = min(f[i][j][0], g[i][j][0]);
        if (ed + a[i] <= c[i]) {
          f[i][j][1] = f[i - 1][j][1];
          tmp = (qzb[i - 1] * j + qza[i - 1] + K - 1) / K;
          if (tmp * K <= qzb[i] * j + qza[i])
            g[i][j][1] = tmp, f[i][j][1] = min(f[i][j][1], g[i][j][1]);
        }
      }
      for (k = j - 1; k > 0 && (j - k) * b[i] <= c[i]; --k) {
        if (g[i][k][0] < INF) {
          tmp = (qzb[i - 1] * (j - k) +
                 max(0ll, b[i] * j - (K * g[i][k][0] - qzb[i - 1] * k) - c[i]) +
                 K - 1) /
                K;
          if (tmp * K <= qzb[i] * j)
            g[i][j][0] = min(g[i][j][0], g[i][k][0] + tmp);
          tmp =
              (max(0ll, min(b[i] * j - (K * g[i][k][0] - qzb[i - 1] * k) - c[i],
                            b[i] * k - (K * g[i][k][0] - qzb[i - 1] * k))) +
               K - 1) /
              K;
          if (b[i] * j - (K * (g[i][k][0] + tmp) - qzb[i - 1] * k) <= c[i])
            f[i][j][0] = min(f[i][j][0], g[i][k][0] + f[i - 1][j - k][0] + tmp);
        }
        if (g[i][k][1] < INF) {
          tmp = (qzb[i - 1] * (j - k) +
                 max(0ll, b[i] * j + a[i] -
                              (K * g[i][k][1] - qzb[i - 1] * k - qza[i - 1]) -
                              c[i]) +
                 K - 1) /
                K;
          if (tmp * K <= qzb[i] * j + qza[i])
            g[i][j][1] = min(g[i][j][1], g[i][k][1] + tmp);
          tmp = (max(0ll,
                     min(b[i] * j + a[i] -
                             (K * g[i][k][1] - qzb[i - 1] * k - qza[i - 1]) -
                             c[i],
                         b[i] * k + a[i] -
                             (K * g[i][k][1] - qzb[i - 1] * k - qza[i - 1]))) +
                 K - 1) /
                K;
          if (b[i] * j + a[i] -
                  (K * (g[i][k][1] + tmp) - qzb[i - 1] * k - qza[i - 1]) <=
              c[i])
            f[i][j][1] = min(f[i][j][1], g[i][k][1] + f[i - 1][j - k][0] + tmp);
        }
      }
    }
  printf("%lld\n", f[n][m][1]);
  return 0;
}
