10877 - EEDS D-ary min heap   

Description

We want to build a ternary min heap given a sequence of push and pop.  In a d-ary heap, each node can have up to d children.  In a min heap, each parent node has a key no greater than that of its children.

Input

The first line contains the degree of the heap (d), the max. number of children a node can have.

The second line contains the number of operations (push and pop) made to the ternary min heap.

Then, each line is a push (with an int key value) or pop operation.

There's no duplicate keys and no underflow cases (i.e., requesting an empty heap to perform pop).

 

Output

Print out the level-order sequence of the ternary min heap after all operations are made.

Sample Input  Download

Sample Output  Download

Tags




Discuss