Recently, Jonathan is addicted to a game called InkBall FX.
The game goes on a plane coordinate system. On the first quadrant, there are some segments. The segments are all parallel to x-axis and they are pairwise disjoint. Two segments are disjoint if and only if they don’t have mutual point, including the end points. Therefore, we can use ($L_i,R_i,Y_i$) to note the $i^{th}$ segment, which means the segment starts from the position ($L_i,Y_i$) and ends in the position ($R_i,Y_i$).
There is an extremely small ball on the position (0,0). At the beginning, the speed of the ball in the horizontal direction is 1 per second, and that in the vertical direction is also 1 per second. If the ball is now at the position (x,y), then it will move to the position (x + t,y + t) after t seconds, if it does not touch the segment during this process.
When the ball hits any segment, a completely elastic collision occurs, which means the speed in vertical direction will be reversed and that in the horizontal direction will remain the same, since the segments are parallel to x-axis. After the collision, the segment will disappear, which means it cannot be collided twice.
If the ball hits the ends of the segment, the collision still occurs like what’s mentioned before.
Jonathan is curious about how many segments the ball could hit, but the ball moves too slow. Please write a program to help him to get the answer quickly.