#B3917. Jumping Frog Simulation

    ID: 11574 Type: Default 1000ms 256MiB

Jumping Frog Simulation

Jumping Frog Simulation

There are \( n-1 \) jumping frogs in a pond. They are numbered \( 1, 2, \ldots, n-1 \). The pond has \( n \) positions, and each position \( i \) holds a number \( a_i \). If \( a_i = 0 \), then the position is empty; otherwise, it contains the frog with number \( a_i \).

Over the next \( n-1 \) minutes, the frogs will move. In the \( i\)-th minute, the frog numbered \( i \) will jump into the currently empty position. After the jump, the frog's previous position becomes empty.

Your task is to output the numbers at all \( n \) positions in the pond after \( n-1 \) minutes, indicating whether the position is empty (0) or which frog occupies the position.

inputFormat

The first line contains an integer \( n \), representing the number of positions.

The second line contains \( n \) integers \( a_1, a_2, \ldots, a_n \) separated by spaces. It is guaranteed that exactly one of these numbers is 0, and the remaining numbers are a permutation of \( 1,2,\ldots,n-1 \).

outputFormat

Output \( n \) integers separated by spaces representing the numbers at each position after all the jumps.

sample

4
0 2 3 1
1 3 0 2