#include <bits/stdc++.h>
using namespace std;
int n, t, m, a[210], b[210], c[210], x[210], w[210];
long long f[210];
inline long long calc(int n, int u) {
  int i, j;
  long long p = 0, q = 1e18, k;
  while (u < t) {
    for (i = n; i > 0; i--)
      if (w[i] + (long long)b[i] * (t - u) > c[i]) break;
    k = w[i] + (long long)b[i] * (t - u) - c[i];
    for (i--; i > 0; i--) k += w[i];
    k = (k - 1) / m + 1;
    q = min(q, p + k + f[u]);
    for (i = n; i > 0; i--)
      if (w[i] + b[i] > c[i]) break;
    k = w[i] + b[i] - c[i];
    for (i--; i > 0; i--) k += w[i];
    if (k) k = (k - 1) / m + 1;
    p += k;
    k *= m;
    for (i = 1; i <= n; i++)
      if (k >= w[i])
        k -= w[i], w[i] = 0;
      else
        w[i] -= k, k = 0;
    u++;
    for (i = 1; i <= n; i++) w[i] += b[i];
  }
  q = min(p, q);
  return q;
}
int main() {
  int i, j;
  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 = 0; i <= t; i++) {
    for (j = n; j > 0; j--)
      if ((long long)b[j] * (t - i) > c[j]) break;
    x[i] = j;
  }
  for (i = t - 2; i >= 0; i--) {
    for (j = 1; j <= x[i]; j++) w[j] = b[j];
    f[i] = calc(x[i], i + 1);
  }
  for (i = 1; i <= n; i++) w[i] = a[i];
  printf("%lld\n", calc(n, 0));
  return 0;
}
