286 传统题

[ABC337C] 排队还原 (Lining Up 2)

时间限制
2000ms
内存限制
512MiB
登顶 / 尝试
0/ 0
难度
2

[ABC337C] 排队还原 (Lining Up 2)

Problem Statement

There are NN people standing in a line: person 11, person 22, …\ldots, person NN.

You are given the arrangement of the people as a sequence A=(A1,A2,…,AN)A=(A _ 1,A _ 2,\ldots,A _ N) of length NN.

Ai (1≤i≤N)A _ i\ (1\leq i\leq N) represents the following information:

  • if Ai=−1A _ i=-1, person ii is at the front of the line;

  • if Ai≠−1A _ i\neq -1, person ii is right behind person AiA _ i.

Print the people's numbers in the line from front to back.

Input

The input is given from Standard Input in the following format:

$N$
$A _ 1$ $A _ 2$ $\ldots$ $A _ N$

Output

If person s1s _ 1, person s2s _ 2, …\ldots, person sNs _ N are standing in the line in this order, print s1s _ 1, s2s _ 2, …\ldots, and sNs _ N in this order, separated by spaces.

Example

6
4 1 -1 5 3 2
3 5 4 1 2 6

Note

  • Constraints:

  • 1≤N≤3×1051\leq N\leq3\times10 ^ 5

  • Ai=−1A _ i=-1 or 1≤Ai≤N (1≤i≤N)1\leq A _ i\leq N\ (1\leq i\leq N)

  • There is exactly one way to arrange the NN people consistent with the information given.

  • All input values are integers.

  • Source: ABC337C