A country contains n cities and m train lines. The ith train line works as follows:
A ticket of trains that run on this train line costs ci dollars. A train on this train line starts its journey from fi city and ends at ei city. The total running duration of the train is ti hours. It departures periodically at every hi hours. For example, the first train departure at 0 time, then another train departs at hi, another in 2hi, and so on.
Note: You can wait in cities for a train.
The total cost of a path, that takes H hours and costs C dollars, is defined as A×H+B×C. Initially, you are in city 1 and you must reach city n. Determine the minimum cost to complete this journey.
Input format
Note:
Output format
Print the path from city 1 to city n that allows you to complete the journey in the minimum cost. Also, print the train lines that you are using in the order. It is guaranteed that there exists a path from city 1 to city n. It is not allowed and inefficient to use the same train line twice.
Constraints
1≤n,m≤1060≤A,B≤1001≤fi,ei≤n1≤ti,ci,hi≤106IfA=0, then B≠0
Test generation and scoring
It takes 2 hours to reach the city 2 and its cost is 3 (using the first train line). Then we should wait for 1 hour in the city 2. Using the second train line we can reach the destination (city 3), in 5 hours with cost 2. So the total cost of this path is 1 * (2 + 1 + 5) + 4 * (3 + 2) = 28.
Another way to reach city 3 is to use the third train line which directly connects us to the destination. But it costs 1 * 1 + 4 * 10 = 41 which is worse.