407505: GYM102803 I InkBall FX

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

I. InkBall FXtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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.

Input

The first line contains one integer $$$n ~ (1 \leq n \leq 10^5)$$$, representing the number of segments.

Then $$$n$$$ lines follow. The $$$i$$$-th line contains three integers $$$L_i, R_i, Y_i ~ (1 \leq L_i, R_i, Y_i \leq 10^9, L_i < R_i)$$$, representing the $$$i$$$-th segment.

Output

Only one line with an integer $$$x$$$ – times that collision occurred.

ExamplesInput
3
4 6 1
2 4 3
5 6 3
Output
2
Input
2
3 4 1
1 2 2
Output
2

加入题单

算法标签: