Under construction

Still being built. Things may change

Stampede

Time limit1sMemory limit256 MB

Summary
Count how many moving segments are ever the closest to the origin while crossing the positive y-axis.
Level

Medium5 of 10

Topics
Intervals, Sorting, Greedy
Solved
No attempts yet

Problem

Farmer John's NN cows (1≤N≤500001 \le N \le 50000) look like they are stampeding along the road in front of the farm, but they are really running a foot race to settle which cow is the fastest.

Seen from above, each cow is a horizontal segment of length 1, given by the coordinates of its left corner at time t=0t=0. For example, (−3,6)(-3, 6) describes a cow that at t=0t=0 is the segment from (−3,6)(-3, 6) to (−2,6)(-2, 6). Every cow moves to the right (the +x+x direction) at a fixed rate, given as the integer amount of time she needs to move 1 unit to the right.

John is not happy that his cows are outside running instead of in the barn producing milk, and he plans to give them a stern lecture once the race ends. To work out which cows are taking part, John stands at (0,0)(0, 0) and looks along the ray that extends in the +y+y direction. If a cow is ever the first cow visible along that ray, John sees her. A cow stays invisible if some other cow is in front of her during the whole time she crosses John's line of sight.

Compute how many cows John sees during the race.

Input

The first line contains NN.

Each of the next NN lines describes one cow with three integers xx, yy, rr. The cow's left endpoint is at (x,y)(x, y) at time t=0t=0, and she moves right at a constant speed of 1 unit of distance every rr units of time. The bounds are −1000≤x≤−1-1000 \le x \le -1 and 1≤y≤10000001 \le y \le 1000000, with yy distinct for every cow so that no collision is possible, and 1≤r≤10000001 \le r \le 1000000.

Output

Print one integer, the number of cows John sees during the entire race, counting from t=0t=0 onward.

Hint

Time runs continuously from t=0t=0. John sees a cow if at some instant while she lies over the ray x=0x=0 no cow with a smaller yy lies over that ray at the same instant.

A cow's segment includes both of its endpoints. She is therefore over the line of sight from the moment her right endpoint touches x=0x=0 until the moment her left endpoint passes x=0x=0.

Examples2

  1. Example 1

    Input
    3
    -2 1 3
    -3 2 3
    -5 100 1
    
    Expected output
    2
    
  2. Example 2

    Input
    1
    -1 1 1
    
    Expected output
    1