A - Limited Insertion 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 400

問題文

すぬけ君は空の数列 a を持っています。

すぬけ君は a に対して N 回操作を行います。

i 回目の操作では 1 \leq j \leq i を満たす整数 j を選び、a の先頭から j 番目に j を挿入することができます。

長さ N の数列 b が与えられます。N 回の操作後に ab と一致することがあるかどうかを判定し、可能ならばそれを達成する操作手順の一例を示してください。

制約

  • 入力は全て整数である。
  • 1 \leq N \leq 100
  • 1 \leq b_i \leq N

入力

入力は以下の形式で標準入力から与えられる。

N
b_1 \dots b_N

出力

N 回の操作後に ab が一致するような操作手順が存在しないならば -1 を出力せよ。 存在するならば操作手順を N 行に出力せよ。i 行目では i 回目の操作で選んだ整数を出力せよ。考えられる操作手順が複数存在する場合は、そのうちのどれを出力してもよい。


入力例 1

3
1 2 1

出力例 1

1
1
2
  • 各操作後、a は以下のように変化します。
  • 1 回目の操作後:(1)
  • 2 回目の操作後:(1,1)
  • 3 回目の操作後:(1,2,1)

入力例 2

2
2 2

出力例 2

-1
  • 数列の先頭に 2 を挿入することはできないため、達成不可能です。

入力例 3

9
1 1 1 2 2 1 2 3 2

出力例 3

1
2
2
3
1
2
2
1
1

Score : 400 points

Problem Statement

Snuke has an empty sequence a.

He will perform N operations on this sequence.

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

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

Constraints

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

Input

Input is given from Standard Input in the following format:

N
b_1 \dots b_N

Output

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


Sample Input 1

3
1 2 1

Sample Output 1

1
1
2

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

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

Sample Input 2

2
2 2

Sample Output 2

-1

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


Sample Input 3

9
1 1 1 2 2 1 2 3 2

Sample Output 3

1
2
2
3
1
2
2
1
1