#include <bits/stdc++.h>
using namespace std;
const int N = 205;
const long long inf = 1ll << 60;
int n, t, m, a[N], b[N], c[N], i, j, k, l, x, d[N];
long long f[N][N], ans = inf, y;
int main() {
  scanf("%d%d%d", &n, &t, &m);
  for (i = 1; i <= n; ++i) scanf("%d%d%d", a + i, b + i, c + i);
  for (i = n; i && a[i] + 1ll * b[i] * t <= c[i]; --i)
    ;
  bool fl = 0;
  for (; i; --i, fl = 1) {
    if (!fl)
      memcpy(d + 1, a + 1, i << 2);
    else
      memset(d + 1, 0, i << 2);
    long long step = 0;
    for (j = 1; j <= t; ++j) f[i][j] = inf;
    for (j = 1; j <= t; ++j) {
      long long tot = 0;
      for (k = 1; k < i; ++k) tot += d[k];
      auto doo = [&](long long s) {
        step += s;
        y = 1ll * s * m;
        for (k = 1; k <= i && y; ++k)
          x = min((long long)d[k], y), d[k] -= x, y -= x;
      };
      doo(tot / m);
      bool bb = 0;
      for (k = 1; k <= i; ++k) bb |= d[k] + b[k] > c[k];
      if (bb) doo(1);
      if (d[i] + b[i] > c[i]) doo((d[i] + b[i] - c[i] + m - 1) / m);
      if (d[i] + b[i] > c[i]) doo(1);
      tot = 0;
      for (k = 1; k < i; ++k) tot += d[k];
      auto calc = [&](int s) {
        return 1ll * s * b[i] <= c[i]
                   ? (max(0ll, 1ll * s * b[i] + d[i] - c[i]) + tot + m - 1) /
                             m +
                         step
                   : inf;
      };
      if (!fl)
        f[i][j] = calc(t - j + 1);
      else
        for (k = 1; k + j - 1 <= t; ++k) {
          f[i][k + j - 1] =
              min(f[i][k + j - 1], f[i + 1][k] + calc(t - (k + j - 1) + 1));
        }
      for (k = 1; k <= i; ++k) d[k] += b[k];
    }
  }
  for (j = 1; j <= t; ++j) ans = min(ans, f[1][j]);
  printf("%lld\n", ans);
  return 0;
}
