atcoder#AGC032A. [AGC032A] Limited Insertion
[AGC032A] Limited Insertion
Score : points
Problem Statement
Snuke has an empty sequence .
He will perform operations on this sequence.
In the -th operation, he chooses an integer satisfying , and insert at position in (the beginning is position ).
You are given a sequence of length . Determine if it is possible that is equal to after operations. If it is, show one possible sequence of operations that achieves it.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If there is no sequence of operations after which would be equal to , print -1
.
If there is, print lines. In the -th line, the integer chosen in the -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 changes as follows:
- After the first operation:
- After the second operation:
- After the third operation:
2
2 2
-1
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