cswork / OAOpen practice workspace

TradeDeskOA #2

Light Sources

Estimated MediumJudge-ready

Topics (AI-labelled)Prefix & Ranges

There are n lamps on a number line. Lamp i is at integer coordinate x_i and has a positive integer radius r_i; it lights the whole range from x_i−r_i to x_i+r_i (both ends included).

Find the number of integer coordinates lit by exactly 1 lamp.

Input

The first line contains an integer n. Each of the next n lines contains two integers x_i and r_i. 1≤n≤100000, −10^9≤x_i≤10^9, 1≤r_i≤10^9.

Output

Output one integer: the number of integer coordinates lit by exactly one lamp.

Example 1

Input:

3
-2 3
2 3
2 1

Output:

6

Example 2

Input:

2
0 1
4 1

Output:

6

Example 3

Input:

2
0 3
1 1

Output:

4

Example notes

Example 1: the three lamps light [−5,1], [−1,5], and [1,3]. The numbers of lamps lighting the points of −6..6 are, in order, 0,1,1,1,1,2,2,3,2,2,1,1,0, and the coordinates lit exactly once are −5,−4,−3,−2,4,5, 6 in total. Example 2: [−1,1] and [3,5] do not intersect, giving 6 coordinates in total. Example 3: [−3,3] contains [0,2], so only −3,−2,−1,3 are lit by exactly one lamp, and the answer is 4.

Editorial

Loading solution…