Jam#8509

Jam

1 second
128 megabytes
Very hard

The most annoying thing in Paris traffic jams is that drivers constantly try to suddenly change lanes in order to move faster. In this problem you'll have to find out whether this is a reasonable strategy or not.

We'll study a relatively simple mathematical model of a traffic jam. Assume that there's an -lane road, lanes numbered from to , and -th lane is moving with speed b_i + a_i \cdot \sin(t + \delta_i) at the moment . It is always true that b_i > a_i, i.e., the speed of movement is always positive. You can change the lane you're in at any time, it takes c \cdot |x - y| to change from -th lane to -th. We'll assume that you're not moving forward during that period.

Determine the time you need to travel the distance of , and the method of achieving that time. You're starting at the moment at lane , you may finish at any lane.

Input

The first line contains two integers and and a floating-point number (1 \leq n \leq 5, 1 \leq d \leq 1000, 0.001 \leq c \leq 1000). The next lines describe lanes, each containing two integers a_i and b_i and a floating-point number \delta_i (0 \leq a_i < b_i \leq 100, 0 \leq \delta_i < 2\pi).

Output

On the first line print the minimal time required to travel the distance of . On the second line print the number of lane changes required to do that. should not be more than 10^6, it is guaranteed that there always exists an optimal strategy requiring not more than 10^6 lane changes. On the next lines print the changes themselves, each line should contain the new lane number and the time when the change is started. The changes should be printed in chronological order. If there're many possible schedules, output any.

Output all the floating-point numbers with maximal precision possible. Your solution will be considered correct if verifying your schedule doesn't lead to discrepancies of more than 10^{-6} (in checking the total distance traveled, in checking that lane changes are non-overlapping, etc), so it's better for you to output at least - digits after the decimal point in each floating-point number.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading