Hyperloop

For odd N, print (N-1)/2 Hamiltonian cycles on the complete graph of N cities that partition all edges, using the given seat-walk construction.

Medium4GreedyMathImplementationCombinatoricsNo attempts yetTime limit1sMemory limit128 MB

Problem

In August 2013 a design appeared for a new means of transport called Hyperloop, in which capsules travel through a tube at a thousand kilometres per hour. One thing nobody knows yet: the first line will not connect two big cities, it will connect two small provincial towns. Following that example, every two of the country's NN cities will be joined directly by one two-way Hyperloop tube.

Once the tubes open, you have to organize several sightseeing routes. One route visits all NN cities, each exactly once, and returns to the city it started from, so it uses exactly NN tubes. To keep the traffic down, two different routes may not share a tube, no matter which way they run through it.

Because NN is odd, you can organize (N1)/2(N-1)/2 routes and leave no tube unused. Construct those routes.

Input

The first line contains the number of cities NN. NN is odd and 3N<20003 \le N < 2000. The cities are numbered from 1 to NN.

Output

Print (N1)/2(N-1)/2 routes, one per line. On each line print the NN city numbers the route visits, in order from the starting city, separated by single spaces. Do not repeat the starting city at the end.

Many sets of routes satisfy the conditions, so only the one built by the following rule is accepted.

Let M=(N1)/2M = (N-1)/2. Put city 1 in the centre and place the other N1N-1 cities around a circle. The seats are numbered 00 to N2N-2, and seat pp holds city p+2p+2.

For k=0,1,,M1k = 0, 1, \dots, M-1, route kk starts at city 1, visits the cities in seats c0,c1,,cN2c_0, c_1, \dots, c_{N-2} in that order, and returns to city 1, where

ci={ki/2(i even)k+(i+1)/2(i odd)c_i = \begin{cases} k - i/2 & (i \text{ even}) \\ k + (i+1)/2 & (i \text{ odd}) \end{cases}

and every seat number is taken modulo N1N-1. In other words the seats run k,  k+1,  k1,  k+2,  k2,  ,  k+(M1),  k(M1),  k+Mk,\; k+1,\; k-1,\; k+2,\; k-2,\; \dots,\; k+(M-1),\; k-(M-1),\; k+M stepping alternately forward and backward with a growing gap, which covers all N1N-1 seats. Print the routes in increasing order of kk.