Little Fabian got a one-dimensional jigsaw puzzle that consists of
Additionally, it is known that among those
Fabian wishes to arrange all of the pieces into a single row such that the first (leftmost) piece is of type
Simply solving the puzzle would be too easy for Fabian so he decided to write a unique positive integer on
each of the pieces. Now he is interested in finding the lexicographically smallest solution to the jigsaw
puzzle. The solution
Note: the pieces cannot be rotated.
Input
The first line contains an integer
The next
Output
If Fabian cannot solve the jigsaw puzzle, you should output -1
in a single line.
Otherwise, you should output the numbers that are written on the pieces in the lexicographically smallest solution to the puzzle.
Scoring
In test cases worth a total of
In test cases worth additional
In test cases worth additional
In test cases worth additional
If for some test case in which the solution to the puzzle exists, you output the correctly solved puzzle but
your solution is not lexicographically smallest, you will get
Sample Input 1
5
1 5
2 7
2 3
8 4
6 1
Sample Output 1
1 3 7 5 4
Explanation For Sample 1
There are only two possible solutions to the puzzle:
We can see that the second depicted solution has a smaller number written on the second piece. Therefore, that is the lexicographically smallest solution.
Sample Input 2
3
5 1
7 2
4 3
Sample Output 2
1 3 2
Sample Input 3
5
2 5
2 7
2 3
8 4
6 1
Sample Output 3
-1
Comments