This page is still under construction.

Parts of this page are still being built. What you see may change.

Can of Worms

Time limit3sMemory limit128 MB

Summary
For each can, count how many cans explode when it is shot, following the chain reaction where each blast hits cans within its radius.
Level

Hard8 of 10

Topics
Sorting, Binary search, Graph, DFS
Solved
No attempts yet

Problem

There is an old saying about "opening a can of worms." A lesser-known one is about shooting a can of exploding worms with a BB gun.

Imagine we line up several cans of exploding worms along a long, straight fence. When a can is shot, every worm inside it explodes. Different kinds of worms have different blast radii, and each can holds only one kind of worm.

The ii-th can sits at position xix_i on the fence and has blast radius rir_i. When a can at position xx with radius rr explodes, every other can whose position lies within distance rr of it, that is, every can located in the interval [x−r, x+r][x - r,\ x + r], also explodes. This can set off a chain reaction. Each can explodes at most once, and the process continues until no more cans explode.

Suppose exactly one can is shot and it is the only can shot. Determine how many cans explode in total.

Input

The input contains several test cases. Each test case begins with a line containing a single integer nn (1≤n≤100,0001 \le n \le 100{,}000), the number of cans on the fence. Each of the next nn lines contains two integers xx (−109≤x≤109-10^9 \le x \le 10^9) and rr (1≤r≤1091 \le r \le 10^9): the position of the can on the fence and its blast radius. No two cans share the same position.

The input ends with a line containing a single 00.

Output

For each test case, print nn integers on a single line, separated by single spaces. The ii-th integer is the number of cans that explode when the ii-th can (in input order) is the one that is shot. Do not print any extra spaces, and do not print blank lines between test cases.

Examples3

  1. Example 1

    Input
    3
    4 3
    -10 9
    -2 3
    12
    2 2
    7 7
    10 1
    19 3
    23 12
    29 8
    33 1
    35 17
    39 2
    40 1
    46 11
    52 3
    0
    
    Expected output
    1 2 1
    1 3 1 1 9 9 1 9 2 2 9 1
    
  2. Example 2

    Input
    5
    0 1
    1 1
    2 1
    3 1
    4 1
    0
    
    Expected output
    5 5 5 5 5
    
  3. Example 3

    Input
    3
    0 5
    5 1
    -5 1
    0
    
    Expected output
    3 1 1