Problem1011--Prime Number cycle

1011: Prime Number cycle

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MiB

Description

Given integer N ( 1 <= N <= 17 ) , arrange numbers from 1 to N in a cycle so that the sum of any two adjacent numbers is a prime number.
please output all the solutions (one solution one line and always starting with 1); clockwise and anti-clockwise direction are two different solutions.
The solutions should be in ascending order by lexicographical order. If no solution, output "NO SOLUTION"

Input

One integer N

Output

Please output all the solutions (one solution one line and always starting with 1); clockwise and anti-clockwise direction are two different solutions.
The solutions should be in ascending order by lexicographical order. If no solution, output "NO SOLUTION"!

Sample Input Copy

8

Sample Output Copy

1 2 3 8 5 6 7 4 
1 2 5 8 3 4 7 6 
1 4 7 6 5 8 3 2 
1 6 7 4 3 8 5 2

Source/Category