Persistent priority queue#7252

Persistent priority queue

1 second
64 megabytes
Easy

Implement a persistent priority queue.

Input

The first line contains the number of operations, (1 \le n \le 200000). Each of the following lines describes an operation :

  • - Add the number (0 < m \le 100000) to the structure identified by number (0 \le x < i).

  • - Remove the maximum element from the structure identified by number (0 \le x < i). It is guaranteed that the priority queue is not empty.

Each operation , described on line i + 1, results in the creation of a new structure numbered . Initially, there is an empty structure numbered zero.

Output

For each removal operation, output the removed element on a separate line.

Examples

Example 1

Loading
Loading