Problem: You have a malfunctioning microwave in which you want to put some bananas. You have time-steps before the microwave stops working completely. At each time-step, it displays a new operation.
Let be the number of bananas in the microwave currently. Initially, . In the -th operation, you are given three parameters , , in the input. Based on the value of , you must do one of the following:
Type 1: (, , ) — pick an , such that , and perform the following update times: .
Type 2: (, , ) — pick an , such that , and perform the following update times: .
Note that can be a fractional value. See input format for more details. Also, is the smallest integer .
At the -th time-step, you must apply the -th operation exactly once.
For each such that , output the earliest time-step at which you can create exactly bananas. If you cannot create exactly bananas, output .
Input Format: The first line contains two space-separated integers and .
Then, lines follow, where the -th line denotes the operation for the -th timestep. Each such line contains three space-separated integers , and (, ).
Note that you are given , which is . Thus, to obtain , use the formula .
For type 1 operations, , and for type 2 operations, .
Output Format: Print integers, where the -th integer is the earliest time-step when you can obtain exactly bananas (or if it is impossible).
Note: In the first sample input, let us see how to create number of bananas in three timesteps. Initially, .
- In timestep 1, we choose , so we apply the type 1 update — — two times. Hence, is now 6.
- In timestep 2, we choose , hence value of remains unchanged.
- In timestep 3, we choose , so we are applying the type 1 update once. Hence, is now 16.
It can be shown that cannot be reached in fewer than three timesteps with the given operations.
In the second sample input, let us see how to create number of bananas in two timesteps. Initially, .
- In timestep 1, we choose , so we apply the type 1 update — — once. Hence, is now 4.
- In timestep 2, we choose , so we apply the type 2 update — — once. Hence, is now 17.
It can be shown that cannot be reached in fewer than two timesteps with the given operations.