#include <bits/stdc++.h>
using namespace std;
const int maxn = 305;
const int inf = 1e9;
inline int read() {
  char c = getchar();
  int t = 0, f = 1;
  while ((!isdigit(c)) && (c != EOF)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while ((isdigit(c)) && (c != EOF)) {
    t = (t << 3) + (t << 1) + (c ^ 48);
    c = getchar();
  }
  return t * f;
}
int n, t, k, a[maxn], b[maxn], c[maxn], sum, p[maxn], ans = 1e9;
void dfs(int now, int cnt) {
  if (cnt >= ans) return;
  if (now == t + 1) {
    ans = min(ans, cnt);
    return;
  }
  int flag = 1;
  if (flag) {
    dfs(now + 1, cnt);
  }
  int alfa[11];
  for (int j = 1; j <= n; j++) alfa[j] = p[j];
  for (int i = 0; i <= sum / k + 1; i++) {
    int tmp = i * k;
    for (int j = 1; j <= n; j++) {
      int num = min(tmp, p[j]);
      p[j] = p[j] - num;
      tmp = tmp - num;
      if (tmp == 0) break;
    }
    int flag = 1;
    for (int j = 1; j <= n; j++) {
      p[j] += b[j];
      if (p[j] > c[j]) {
        flag = 0;
        break;
      }
    }
    if (!flag) {
      for (int j = 1; j <= n; j++) p[j] = alfa[j];
      continue;
    }
    dfs(now + 1, cnt + i);
    for (int j = 1; j <= n; j++) p[j] = alfa[j];
  }
}
void dfs2(int now, int cnt) {
  if (now == t + 1) {
    ans = min(ans, cnt);
    return;
  }
  int alfa[101];
  for (int j = 1; j <= n; j++) alfa[j] = p[j];
  for (int i = 0; i <= sum / k + 1; i++) {
    int tmp = i * k;
    for (int j = 1; j <= n; j++) {
      int num = min(tmp, p[j]);
      p[j] = p[j] - num;
      tmp = tmp - num;
      if (tmp == 0) break;
    }
    int flag = 1;
    for (int j = 1; j <= n; j++) {
      p[j] += b[j];
      if (p[j] > c[j]) {
        flag = 0;
        break;
      }
    }
    if (!flag) {
      for (int j = 1; j <= n; j++) p[j] = alfa[j];
      continue;
    }
    dfs2(now + 1, cnt + i);
    for (int j = 1; j <= n; j++) p[j] = alfa[j];
  }
}
int f[maxn];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    q;
int alfa[maxn];
signed main() {
  n = read();
  t = read();
  k = read();
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    b[i] = read();
    c[i] = read();
    sum += b[i];
  }
  if (n <= 10) {
    for (int i = 1; i <= n; i++) p[i] = a[i];
    dfs(1, 0);
    printf("%d\n", ans);
  } else if (t <= 1) {
    for (int i = 1; i <= n; i++) p[i] = a[i];
    dfs2(1, 0);
    printf("%d\n", ans);
  } else {
    for (int i = 1; i <= n; i++) {
      p[i] = a[i];
      if (b[i]) {
        f[i] = (c[i] - a[i]) / b[i] + 1;
        q.push(pair<int, int>(f[i], i));
      }
    }
    int lst = 0, ans = 0;
    while (!q.empty()) {
      pair<int, int> u = q.top();
      q.pop();
      int o1 = u.first, o2 = u.second;
      if (f[o2] != o1) continue;
      if (o1 > t) break;
      for (int i = 1; i <= n; i++) {
        p[i] = p[i] + (o1 - lst) * b[i];
      }
      lst = o1;
      for (int i = 1; i; i++) {
        int tmp = i * k;
        for (int j = 1; j <= n; j++) alfa[j] = p[j];
        for (int j = 1; j <= n; j++) {
          int num = min(tmp, p[j]);
          p[j] -= num;
          tmp -= num;
          if (tmp == 0) break;
        }
        if (p[o1] <= c[o1]) {
          ans += i;
          break;
        }
        for (int j = 1; j <= n; j++) {
          p[j] = alfa[j];
        }
      }
      for (int j = 1; j <= n; j++) {
        if (b[j]) {
          f[j] = lst + (c[j] - p[j]) / b[j];
          q.push(pair<int, int>(f[j], j));
        }
      }
    }
    printf("%d\n", ans - 1);
  }
  return 0;
}
