Problem: In a simplified version of a "Mini Metro" game, there is only one subway line, and all the trains go in the same direction. There are n stations on the line, a_i people are waiting for the train at the i-th station at the beginning of the game. The game starts at the beginning of the 0-th hour. At the end of each hour (couple minutes before the end of the hour), b_i people instantly arrive to the i-th station. If at some moment, the number of people at the i-th station is larger than c_i, you lose.

A player has several trains which he can appoint to some hours. The capacity of each train is k passengers. In the middle of the appointed hour, the train goes from the 1-st to the n-th station, taking as many people at each station as it can accommodate. A train can not take people from the i-th station if there are people at the i-1-th station.

If multiple trains are appointed to the same hour, their capacities are being added up and they are moving together.

The player wants to stay in the game for t hours. Determine the minimum number of trains he will need for it.

Input

The first line contains three integers n, t, and k (1 ≤ n, t ≤ 200, 1 ≤ k ≤ 10^9) — the number of stations on the line, hours we want to survive, and capacity of each train respectively.

Each of the next n lines contains three integers a_i, b_i, and c_i (0 ≤ a_i, b_i ≤ c_i ≤ 10^9) — number of people at the i-th station in the beginning of the game, number of people arriving to i-th station in the end of each hour and maximum number of people at the i-th station allowed respectively.

Output

Output a single integer number — the answer to the problem.

Examples

Input

3 3 10
2 4 10
3 3 9
4 2 8


Output

2


Input

4 10 5
1 1 1
1 0 1
0 5 8
2 7 100


Output

12

Note

<image>

Let's look at the sample. There are three stations, on the first, there are initially 2 people, 3 people on the second, and 4 people on the third. Maximal capacities of the stations are 10, 9, and 8 respectively.

One of the winning strategies is to appoint two trains to the first and the third hours. Then on the first hour, the train takes all of the people from the stations, and at the end of the hour, 4 people arrive at the first station, 3 on the second, and 2 on the third.

In the second hour there are no trains appointed, and at the end of it, the same amount of people are arriving again.

In the third hour, the train first takes 8 people from the first station, and when it arrives at the second station, it takes only 2 people because it can accommodate no more than 10 people. Then it passes by the third station because it is already full. After it, people arrive at the stations once more, and the game ends.

As there was no such moment when the number of people at a station exceeded maximal capacity, we won using two trains.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long inf = 2147383647;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(
                chrono::high_resolution_clock::now().time_since_epoch())
                .count());
template <typename S, typename T>
void xmin(S& a, T const& b) {
  if (b < a) a = b;
}
template <typename S, typename T>
void xmax(S& a, T const& b) {
  if (b > a) a = b;
}
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
inline long long gcd(long long a, long long b) {
  a = ((a) < 0 ? -(a) : (a));
  b = ((b) < 0 ? -(b) : (b));
  while (b) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
long long ext_gcd(long long A, long long B, long long* X, long long* Y) {
  long long x2, y2, x1, y1, x, y, r2, r1, q, r;
  x2 = 1;
  y2 = 0;
  x1 = 0;
  y1 = 1;
  for (r2 = A, r1 = B; r1 != 0;
       r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y) {
    q = r2 / r1;
    r = r2 % r1;
    x = x2 - (q * x1);
    y = y2 - (q * y1);
  }
  *X = x2;
  *Y = y2;
  return r2;
}
inline long long modInv(long long a, long long m) {
  long long x, y;
  ext_gcd(a, m, &x, &y);
  x %= m;
  if (x < 0) x += m;
  return x;
}
inline long long power(long long a, long long p) {
  long long res = 1, x = a;
  while (p) {
    if (p & 1) res = (res * x);
    x = (x * x);
    p >>= 1;
  }
  return res;
}
inline long long bigmod(long long a, long long p, long long m) {
  long long res = 1 % m, x = a % m;
  while (p) {
    if (p & 1) res = (res * x) % m;
    x = (x * x) % m;
    p >>= 1;
  }
  return res;
}
signed gen(int T) {
  auto get_rand = [&](int64_t l, int64_t r) {
    return uniform_int_distribution<int64_t>(l, r)(rng);
  };
  ofstream o("gen.txt");
  const int N = T;
  T = 1;
  o << T << "\n";
  for (int cas = 0; cas < T; ++cas) {
    o << "\n";
    int n = get_rand(1, N), t = get_rand(1, N), k = get_rand(1, N);
    o << n << ' ' << t << ' ' << k << "\n";
    for (long long i = (1); i <= (n); ++i) {
      int a = get_rand(0, N), b = get_rand(0, N),
          c = get_rand(((a) > (b) ? (a) : (b)), N);
      o << a << ' ' << b << ' ' << c << "\n";
    }
  }
  o << endl;
  o.close();
  return 0;
}
const int N = 200;
const long long INF = inf << 30;
long long dp[N + 2][N + 1][2], dp2[N + 2][N + 1][2], A[N + 2], B[N + 2],
    C[N + 2], SA[N + 2], SB[N + 2], SC[N + 2];
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  int n, t, K;
  cin >> n >> t >> K;
  for (long long i = (1); i <= (n); ++i) {
    cin >> A[i] >> B[i] >> C[i];
    SA[i] = SA[i - 1] + A[i];
    SB[i] = SB[i - 1] + B[i];
    SC[i] = SC[i - 1] + C[i];
  }
  A[n + 1] = INF;
  B[n + 1] = 0;
  C[n + 1] = 2 * INF;
  SA[n + 1] = SA[n] + A[n + 1];
  SB[n + 1] = SB[n] + B[n + 1];
  SC[n + 1] = SC[n] + C[n + 1];
  memset(dp, -1, sizeof(dp));
  memset(dp2, -1, sizeof(dp2));
  for (long long i = (0); i <= (n + 1); ++i) {
    for (long long j = (0); j <= (t); ++j) {
      for (long long k = (0); k <= (1); ++k) {
        if (i == 0) {
          dp[i][j][k] = dp2[i][j][k] = 0;
        } else {
          if (k * A[i] + j * B[i] <= C[i]) {
            if (dp[i - 1][j][k] != -1) {
              dp[i][j][k] = dp[i - 1][j][k];
              long long val = (k * SA[i - 1] + j * SB[i - 1] + K - 1) / K;
              if (val * K <= k * SA[i] + j * SB[i]) {
                dp2[i][j][k] = val;
              }
            }
          }
          for (long long jj = (0); jj <= (j - 1); ++jj) {
            long long aux = dp2[i][jj][k];
            if (aux != -1) {
              long long rem = k * SA[i] + jj * SB[i] - K * aux,
                        val = (((0) > (rem + (j - jj) * B[i] - C[i])
                                    ? (0)
                                    : (rem + (j - jj) * B[i] - C[i])) +
                               K - 1) /
                              K;
              if (val * K <= rem) {
                if (dp[i - 1][j - jj][0] != -1) {
                  long long newValue = aux + val + dp[i - 1][j - jj][0];
                  if (dp[i][j][k] == -1 || dp[i][j][k] > newValue) {
                    dp[i][j][k] = newValue;
                  }
                  long long x = ((j - jj) * SB[i - 1] + K - 1) / K;
                  if (x * K <= (j - jj) * SB[i] + rem - val * K) {
                    newValue = aux + val + x;
                    if (dp2[i][j][k] == -1 || dp2[i][j][k] > newValue) {
                      dp2[i][j][k] = newValue;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  long long res = dp[n + 1][t][1];
  cout << res << "\n";
  return 0;
}