Write a program that prints all the permutations of with exactly one cycle, for a given . Assume that the content of the position of a permutation indicates “the next position to visit”.
For instance, consider the permutation . The position 1 has a 4, the position 4 has a 5, and the position 5 has a 1. Therefore, one of the cycles of this permutation is . The other two cycles are and . The permutation has the two cycles and . The permutation has only the cycle .
Input consists of a natural number .
Print all the permutations of with only one cycle.
You can print the solutions to this exercise in any order.
The judge may accept a program that generates all the permutations and, for each one, checks if it only has one cycle. However, this is not the right solution for this problem.
Input
3
Output
(2,3,1) (3,1,2)
Input
4
Output
(2,3,4,1) (2,4,1,3) (3,4,2,1) (3,1,4,2) (4,3,1,2) (4,1,2,3)