Bitstock

Given share prices, income rates, and a support forest where each owned share can subsidize its children at half price, find the minimum time until income reaches P per second.

Hard8GreedyTreeDynamic programmingBinary searchNo attempts yetTime limit1sMemory limit128 MB

Problem

Mirko is hooked on Bitstock, an MMORPG where players buy shares. The market offers exactly NN types of shares, and Mirko can buy any amount of any type at any moment. One share of type ii costs cic_i kuna and, from the moment he buys it, produces gig_i kuna per second. Shares can also be bought in real amounts, as long as the amount is positive. For example, if Mirko buys 0.70.7 shares of AA, they produce 0.21gA0.21 g_A kuna over the next 0.30.3 seconds.

The twist in Bitstock is that some shares support other shares, and a supported share can be bought at half price. If AA supports BB and CC, then 11 share of AA that Mirko owns lets him buy 0.70.7 shares of BB and 0.30.3 shares of CC at half price. That share of AA cannot finance any further purchase afterwards, although it keeps producing money. In other words, one owned share finances at most 11 share in total among the types it supports. A share bought at half price supports its own types in exactly the same way. Every type is supported by at most one type, and no type supports itself, directly or indirectly.

Money is available for new purchases the moment it is produced. The goal is to reach a profit of PP kuna per second in the shortest time. Mirko starts with EE kuna and owns no shares.

Input

The first line contains the number of share types NN, the starting amount EE, and the target profit rate PP (1N10001 \le N \le 1000, 1E,P1091 \le E, P \le 10^9).

Each of the next NN lines contains the price cic_i, the profit per second gig_i, and the number pip_i of the share type that supports type ii (1ci1091 \le c_i \le 10^9, 0gi1090 \le g_i \le 10^9, 0piN0 \le p_i \le N). A value pi=0p_i = 0 means no type supports type ii. At least one gig_i is positive.

Output

Print the minimum time in seconds needed to reach a profit of PP kuna per second. Round the value up to an integer. For example, if 17.217.2 seconds are needed, print 1818. If the starting money reaches the target immediately, print 00.

The input is such that the exact minimum time is 00 or differs from every integer by at least 10610^{-6}.