Under construction

Still being built. Things may change

Endless Road

Time limit5sMemory limit1024 MB

Summary
Given N segments on a line of length 10^9, output the order in which members plant, always choosing the one with the least newly covered length (ties by index).
Level

Hard8 of 10

Topics
Segment tree, Greedy, Intervals
Solved
No attempts yet

Statement

Whenever KAIST students leave campus, they usually walk along a straight road called the Endless Road. Many students feel the road never ends, partly because the scenery along it is dull. We model the Endless Road as a straight line of length 10910^9. A position on the line is a real number x∈[0,109)x \in [0, 10^9).

The members of RUN@KAIST decided to plant flowers of different colors along the road to liven it up. There are NN members, numbered from 11 to NN. At the last regular meeting, each member ii was assigned a nonempty segment [Li,Ri)[L_i, R_i) on the line, which contains every position xx with Li≤x<RiL_i \le x < R_i.

A member with a higher index carries more responsibility in the club, so the segment length does not decrease as the index grows: Ri−Li≤Rj−LjR_i - L_i \le R_j - L_j for all 1≤i<j≤N1 \le i < j \le N.

Flower planting takes place in NN turns. In each turn, one member who has not been selected yet plants flowers. The selected member plants flowers over their segment [Li,Ri)[L_i, R_i), except at positions where other members have already planted flowers.

The next member is chosen as follows. The member who would plant the fewest flowers at that moment goes first. The amount planted is the length of the part of the segment where the member plants new flowers, and this length may be zero. If several members tie, the member with the smallest index goes first.

Jaeung must announce the planting schedule. Find the order in which all NN members plant flowers under these rules.

Input

The first line contains an integer NN. Each of the next NN lines contains two integers LiL_i and RiR_i.

Output

Print NN space-separated integers. The ii-th integer is the index of the member who plants flowers in the ii-th turn.

Constraints

1≤N≤250 0001 \leq N \leq 250\,000. 0≤Li<Ri≤1090 \le L_i < R_i \le 10^9. Ri−Li≤Rj−LjR_i - L_i \leq R_j - L_j for all 1≤i<j≤N1 \le i < j \le N. All intervals are distinct, that is, (Li,Ri)≠(Lj,Rj)(L_i, R_i) \neq (L_j, R_j) for all 1≤i<j≤N1 \le i < j \le N.

Examples2

  1. Example 1

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

    Input
    4
    3 7
    10 14
    1 6
    6 11
    
    Expected output
    1 3 2 4