#include <bits/stdc++.h>
using namespace std;
bool debug = false;
const long long mod = 1e9 + 7;
const int N = 201;
const int H = 201;
int n, t;
long long z;
long long a[N], b[N], c[N];
long long pa[N], pb[N];
array<long long, H> cn2[N];
array<long long, H> cl1[N], cl2[N];
array<long long, H> oh1[N], oh2[N];
long long d[N];
void compute(int i, long long& c, long long& r) {
  c = 0, r = 0;
  long long s = 0;
  for (int k = 1; k < i; k++) s += d[k];
  c = (s + z - 1) / z;
  s = (z - s % z) % z;
  r = max(0LL, d[i] - s);
}
void cl(int i) {
  long long s = 0;
  for (int k = 1; k <= i; k++) s += d[k];
  s -= s % z;
  for (int k = 1; k <= i; k++) {
    long long w = min(d[k], s);
    d[k] -= w;
    s -= w;
  }
}
long long cal(int i) {
  bool need = false;
  long long s = 0;
  for (int k = 1; k < i; k++)
    if (d[k] > 0) s = z;
  for (int k = 1; k < i; k++) {
    long long w = min(d[k], s);
    s -= w;
  }
  if (d[i] < s) return -1;
  return d[i] - s;
}
void getcl(int i, array<long long, H>& ci, array<long long, H>& ri) {
  cl(i);
  ci[0] = 1;
  bool ok = true;
  for (int j = 1; j <= t; j++) {
    for (int k = 1; k <= i; k++) {
      d[k] += b[k];
      if (d[k] > c[k]) ok = false;
    }
    if (!ok) {
      ci[j] = -1;
      continue;
    }
    cl(i);
    ci[j] = 1;
  }
}
void getcan(int i, array<long long, H>& can) {
  can[0] = true;
  for (int j = 1; j <= t; j++) {
    can[j] = can[j - 1];
    for (int k = 1; k <= i; k++) {
      d[k] += b[k];
      if (d[k] > c[k]) can[j] = false;
    }
    if (!can[j]) continue;
    cl(i - 1);
  }
}
void getoh(int i, array<long long, H>& ci, array<long long, H>& oh) {
  cl(i - 1);
  oh[0] = cal(i);
  bool ok = true;
  for (int j = 1; j <= t; j++) {
    for (int k = 1; k <= i; k++) {
      d[k] += b[k];
      if (d[k] > c[k]) ok = false;
    }
    if (!ok) {
      oh[j] = -1;
      continue;
    }
    cl(i - 1);
    oh[j] = cal(i);
    if (debug) {
      cout << i << ' ' << j << ": ";
      for (int k = 1; k <= i; k++) {
        cout << d[k] << ' ';
      }
      cout << endl;
    }
  }
  for (int j = 1; j <= t; j++) {
    for (int p = 0; p < j; p++) {
      if (oh[p] == -1) continue;
      if (!cn2[i][j - p]) continue;
      if (oh[p] % z + (j - p) * b[i] > c[i]) continue;
      long long dm = (oh[p] + pb[i] * (j - p)) % z;
      long long s = oh[p] + (j - p) * b[i];
      long long duh = (s - dm + z) % z;
      s -= duh;
      if (s > c[i]) {
        long long b = (s - c[i] + z - 1) / z;
        s -= b * z;
      }
      oh[j] = max(oh[j], s);
    }
  }
}
long long dp[N][H], dp2[N][H];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> t >> z;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i] >> c[i];
    pa[i] = pa[i - 1] + a[i];
    pb[i] = pb[i - 1] + b[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int k = 1; k <= i; k++) d[k] = 0;
    getcan(i, cn2[i]);
    for (int k = 1; k <= i; k++) d[k] = 0;
    getcl(i, cl2[i], oh2[i]);
    for (int k = 1; k <= i; k++) d[k] = 0;
    getoh(i, cl2[i], oh2[i]);
    for (int k = 1; k <= i; k++) d[k] = a[k];
    getcl(i, cl1[i], oh1[i]);
    for (int k = 1; k <= i; k++) d[k] = a[k];
    getoh(i, cl1[i], oh1[i]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= t; j++) {
      dp2[i][j] = 1e18;
      if (j * b[i] <= c[i]) {
        dp2[i][j] = dp2[i - 1][j];
        continue;
      }
      for (int p = 1; p <= j; p++) {
        if (oh2[i][p] == -1) continue;
        if ((j - p) * b[i] > c[i]) continue;
        long long x = c[i] - (j - p) * b[i];
        if (x < oh2[i][p] % z) continue;
        long long cost = (pb[i] * p - oh2[i][p]) / z;
        long long red = max(0LL, (oh2[i][p] - x + z - 1) / z);
        dp2[i][j] = min(dp2[i][j], cost + red + dp2[i][j - p]);
      }
      for (int p = 1; p <= j; p++) {
        if (cl2[i][p] == -1) continue;
        long long cost = (pb[i] * p + z - 1) / z;
        dp2[i][j] = min(dp2[i][j], cost + dp2[i][j - p]);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= t; j++) {
      dp[i][j] = 1e18;
      if (a[i] + j * b[i] <= c[i]) {
        dp[i][j] = dp[i - 1][j];
        continue;
      }
      for (int p = 0; p <= j; p++) {
        if (oh1[i][p] == -1) continue;
        if ((j - p) * b[i] > c[i]) continue;
        long long x = c[i] - (j - p) * b[i];
        if (x < oh1[i][p] % z) continue;
        long long cost = (pb[i] * p + pa[i] - oh1[i][p]) / z;
        long long red = max(0LL, (oh1[i][p] - x + z - 1) / z);
        dp[i][j] = min(dp[i][j], cost + red + dp2[i][j - p]);
      }
      for (int p = 0; p <= j; p++) {
        if (cl1[i][p] == -1) continue;
        long long cost = (pb[i] * p + pa[i] + z - 1) / z;
        dp[i][j] = min(dp[i][j], cost + dp2[i][j - p]);
      }
    }
  }
  cout << dp[n][t] << '\n';
}
