Amidakuji

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

You are given a positive integer NN. Construct a sequence of permutations of (1,2,,N)(1,2,\cdots,N), p_1,p_2,,p_Kp\_1,p\_2,\ldots,p\_K, that satisfy following conditions, or report that it's impossible.

  • 0Klog_2N+10 \leq K \leq \lceil \log\_2 N \rceil + 1, where KK is the length of the sequence.
  • p_1,p_2,,p_Kp\_1,p\_2,\ldots,p\_K are permutations of (1,2,,N)(1,2,\ldots,N).

In other words, they are bijections from 1,2,,N\\{1,2,\ldots,N\\} to 1,2,,N\\{1,2,\ldots,N\\}.

  • For all xx and yy (1x,yN1 \leq x,y \leq N), there is a sequence of bijections q_1,q_2,,q_Kq\_1,q\_2,\ldots,q\_K such that (q_Kq_K1q_1)(x)=y(q\_K \circ q\_{K-1} \circ \cdots \circ q\_1)(x) = y and q_i=p_iq\_i=p\_i or p_i1p\_i^{-1} for all ii.

Here, \circ denotes function composition, and when K=0K=0, q_Kq_K1q_1q\_K \circ q\_{K-1} \circ \cdots \circ q\_1 is defined as an identity function.

입력

Input is given from Standard Input in the following format:

NN

출력

If there is no solution, print 1-1. Otherwise, print the answer in the following format:

KK

p_1,1p\_{1,1} p_1,2p\_{1,2} \cdots p_1,Np\_{1,N}

\vdots

p_K,1p\_{K,1} p_K,2p\_{K,2} \cdots p_K,Np\_{K,N}

Here, p_i,jp\_{i,j} must be a value of p_i(j)p\_i(j).

If there are multiple solutions, you can print any of them.

제한

  • 1N10001 \leq N \leq 1000

힌트

In Sample 1 for x=2,y=1x=2,y=1, we can set q_1=p_1,q_2=p_21,q_3=p_3q\_1 = p\_1, q\_2 = p\_2^{-1}, q\_3 = p\_3 and get q_3(q_2(q_1(2)))=1q\_3(q\_2(q\_1(2)))=1.