Cows on a Leash

Given N intervals, find the fewest half-integer cut points so that every interval contains at least one chosen point.

Medium6GreedyIntervalsSortingInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Farmer John keeps NN cows on leashes. Every leash is tied to a stake driven in at an integer position beside a straight fence that runs east to west and is at most 5,300,000 meters long. Each cow pulls her leash as far east as it goes, but never past the end of the fence. A leash whose stake sits at position ss and whose length is ll covers the stretch from ss to s+ls+l.

Farmer John's wife thinks leashes are barbaric, so she came to the fence with her dull butcher knife. The knife is good for only a few cuts, so she wants to make as few as she can. For one cut she stands halfway between two neighboring integer positions, at x+0.5x+0.5, and severs every leash that passes in front of her. The leash with stake ss and length ll is severed at x+0.5x+0.5 when sxs \le x and x+1s+lx+1 \le s+l.

You are given the stake position and the length of every leash. Find the smallest number of cuts that frees all of the cows.

Input

The first line contains the number of cows NN (1N320001 \le N \le 32000).

Each of the next NN lines contains two space separated integers that describe one leash. The first is the position of its stake and the second is the length of the leash. Both values are positive, and the position plus the length is at most 5,300,000.

Output

Print, on one line, the minimum number of cuts needed to cut every leash at least once.

Hint

The picture below shows where seven leashes lie. The top two rows give the integer positions along the fence.

                  1 1 1 1
1 2 3 4 5 6 7 8 9 0 1 2 3
-------------------------
. 111111111 . . . . . . .
. . . 222222222222222 . .
. . 3333333 . . . . . . .
. . . . 4444444 . . . . .
. . . . . . . . 555555555
66666666666 . . . . . . .
. . . . . . 7777777 . . .

A cut at 5.55.5 severs leashes 1, 2, 3, 4, and 6. A second cut at 9.59.5 severs leashes 5 and 7. Other positions work too, but no single cut reaches both leash 5 and leash 6, so at least two cuts are needed.