There is a directed graph with vertices numbered .
Each vertex has a value . Directed edges exist according to the following rules.
Find a Hamiltonian path, a path that visits every vertex exactly once, in this graph.
For every two consecutive vertices of the path, there must be an edge in the direction of travel. The path does not need to return to its starting vertex.
For example, if and , then is a Hamiltonian path. It visits each vertex exactly once, and all three directed edges , , and exist.
The input is given from Standard Input in the following format:
For each test case, if no Hamiltonian path exists, print -1 on one line.
Otherwise, let be the vertices of a Hamiltonian path in visiting order. Print on one line, separated by spaces. The sequence must be a permutation of , and for every , there must be a directed edge from vertex to vertex .
In the first test case, the path is a Hamiltonian path.
In the second test case, no Hamiltonian path exists.
The remaining output lines are also examples of Hamiltonian paths satisfying the required conditions.
Each case is given in the following format:
If there are multiple solutions, print any of them.
| 3 | 22 | (). In other words, all s come before all s. Arrays consisting entirely of s or entirely of s are also included. |
| 4 | 47 | No additional constraints. |