atcoder#AGC032A. [AGC032A] Limited Insertion

[AGC032A] Limited Insertion

Score : 400400 points

Problem Statement

Snuke has an empty sequence aa.

He will perform NN operations on this sequence.

In the ii-th operation, he chooses an integer jj satisfying 1ji1 \leq j \leq i, and insert jj at position jj in aa (the beginning is position 11).

You are given a sequence bb of length NN. Determine if it is possible that aa is equal to bb after NN operations. If it is, show one possible sequence of operations that achieves it.

Constraints

  • All values in input are integers.
  • 1N1001 \leq N \leq 100
  • 1biN1 \leq b_i \leq N

Input

Input is given from Standard Input in the following format:

NN

b1b_1 \dots bNb_N

Output

If there is no sequence of NN operations after which aa would be equal to bb, print -1. If there is, print NN lines. In the ii-th line, the integer chosen in the ii-th operation should be printed. If there are multiple solutions, any of them is accepted.

3
1 2 1
1
1
2

In this sequence of operations, the sequence aa changes as follows:

  • After the first operation: (1)(1)
  • After the second operation: (1,1)(1,1)
  • After the third operation: (1,2,1)(1,2,1)
2
2 2
-1

22 cannot be inserted at the beginning of the sequence, so this is impossible.

9
1 1 1 2 2 1 2 3 2
1
2
2
3
1
2
2
1
1