Permutation Construction

시간 제한1초메모리 제한2048 MB

문제

Adrian challenges you to construct a permutation of $1$ to $N$ (inclusive) that satisfies his requirements. Suppose that your permutation is denoted as $P$. There are $N$ requirements, numbered from $1$ to $N$. Requirement $i$ is represented by $A_i$, which can be one of the followings:

  • if $A_i = -1$, then there is no $x$ that satisfy $x > i$ and $P_x > P_i$; or
  • if $i < A_i ≤ N$, then $A_i$ is the smallest index larger than $i$ that satisfy $P_{A_i} > P_i$.

Construct any permutation that satisfies all of the requirements, or tell Adrian if it is impossible to construct such a permutation.

Note that a permutation of $1$ to $N$ (inclusive) is a sequence where each integer from $1$ to $N$ appears in the sequence exactly once.

입력

Input begins with an integer $N$ ($1 ≤ N ≤ 100\, 000$). The next line contains $N$ integers $A_i$ ($A_i = -1$ or $i < A_i ≤ N$) representing the given requirements.

출력

If at least one permutation that satisfies all the requirements can be found, output $N$ space-separated integers in a single line representing the permutation. If there are several permutations that satisfy all of the requirements, output any of them.

If there is no permutation that satisfies all the requirements, output -1 in a single line.