Under construction

Still being built. Things may change

Seats 2

Interview

Time limit2sMemory limit1024 MB

Summary
For each player, find the smallest seat distance to a player from a different country when N players sit on a line.
Level

Medium4 of 10

Topics
Sorting, Array
Solved
No attempts yet

Problem

The JOI country is holding a programming world competition this year. NN players are scheduled to attend, numbered from 1 to NN.

Each player's home country is an integer from 1 to 10910^9. Player ii (1≤i≤N1 \le i \le N) is from country CiC_i. Not all NN players are from the same country. Each player's seat lies on a straight line, and player ii (1≤i≤N1 \le i \le N) sits at position XiX_i. The seat distance between player ii and player jj (1≤j≤N1 \le j \le N) is ∣Xi−Xj∣|X_i - X_j|, where ∣x∣|x| is the absolute value of xx.

During the competition, each player wants to know the seat distance to the nearest player from a different country.

Given each player's country and seat position, print for each player ii (1≤i≤N1 \le i \le N) the smallest seat distance from player ii to a player from a different country.

Input

N
C1 X1
C2 X2
⋮
CN XN

Output

Print NN lines. On line ii (1≤i≤N1 \le i \le N), print the seat distance from player ii to the nearest player whose country differs from player ii's country.

Constraints

  • 2≤N≤3000002 \le N \le 300000.
  • 1≤Ci≤1091 \le C_i \le 10^9 (1≤i≤N1 \le i \le N).
  • 1≤Xi≤1091 \le X_i \le 10^9 (1≤i≤N1 \le i \le N).
  • Not all NN players are from the same country.
  • All input values are integers.

Examples3

  1. Example 1

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

    Input
    5
    1 1
    2 4
    2 14
    3 10
    2 2
    
    Expected output
    1
    3
    4
    4
    1
    
  3. Example 3

    Input
    3
    1 1
    2 1
    1 1
    
    Expected output
    0
    0
    0