Under construction

Still being built. Things may change

Fill the Circle

Time limit2sMemory limit512 MB

Summary
Each number from 2 to N goes into the x-th empty slot clockwise from a reference number's slot on a circle, and the task is to print the circle starting at 1.
Level

Medium7 of 10

Topics
Segment tree, Binary search, Array
Solved
No attempts yet

Problem

Sumin, who likes sequences, wants to build a sequence of the integers from 11 to NN.

The sequence is built with the following rules.

  1. Place NN slots in a circle, and write 11 in one slot in advance.
  2. For each number from 22 to NN in order, repeat steps 3 and 4 to fill the slots.
  3. Choose one number already written and call it pip_i. Choose an integer xix_i between 11 and 10910^9, inclusive.
  4. Starting from the slot where pip_i is written and moving clockwise, find the xix_i-th empty slot you encounter, and write the number there.
  5. Starting from the slot where 11 is written and moving clockwise, read the NN numbers in the slots in order. These form the sequence.

Input

The first line contains the size of the sequence, NN. (2≤N≤300 0002 \leq N \leq 300\,000)

From the second line through line NN, line ii contains the reference integer pip_i and the number of steps xix_i. (1≤pi≤i−11 \leq p_i \leq i-1, 1≤xi≤1091 \leq x_i \leq 10^9)

In other words, starting from the slot where pip_i is written and moving clockwise, number ii goes into the xix_i-th empty slot.

Output

Print NN lines. Line ii contains the ii-th number of the sequence.

Examples1

  1. Example 1

    Input
    8
    1 3
    2 5
    2 2
    3 2
    1 3
    6 2
    1 1
    
    Expected output
    1
    3
    8
    2
    5
    4
    7
    6