#agc030c. [agc030_c]Coloring Torus

[agc030_c]Coloring Torus

Problem Statement

For an ntimesnn \\times n grid, let (r,c)(r, c) denote the square at the (r+1)(r+1)-th row from the top and the (c+1)(c+1)-th column from the left. A good coloring of this grid using KK colors is a coloring that satisfies the following:

  • Each square is painted in one of the KK colors.
  • Each of the KK colors is used for some squares.
  • Let us number the KK colors 1,2,...,K1, 2, ..., K. For any colors ii and jj (1leqileqK,1leqjleqK1 \\leq i \\leq K, 1 \\leq j \\leq K), every square in Color ii has the same number of adjacent squares in Color jj. Here, the squares adjacent to square (r,c)(r, c) are $((r-1)\\; mod\\; n, c), ((r+1)\\; mod\\; n, c), (r, (c-1)\\; mod\\; n)$ and (r,(c+1);mod;n)(r, (c+1)\\; mod\\; n) (if the same square appears multiple times among these four, the square is counted that number of times).

Given KK, choose nn between 11 and 500500 (inclusive) freely and construct a good coloring of an ntimesnn \\times n grid using KK colors. It can be proved that this is always possible under the constraints of this problem,

Constraints

  • 1leqKleq10001 \\leq K \\leq 1000

Input

Input is given from Standard Input in the following format:

KK

Output

Output should be in the following format:

nn c0,0c_{0,0} c0,1c_{0,1} ...... c0,n1c_{0,n-1} c1,0c_{1,0} c1,1c_{1,1} ...... c1,n1c_{1,n-1} :: cn1,0c_{n-1,0} cn1,1c_{n-1,1} ...... cn1,n1c_{n-1,n-1}

nn should represent the size of the grid, and 1leqnleq5001 \\leq n \\leq 500 must hold. cr,cc_{r,c} should be an integer such that 1leqcr,cleqK1 \\leq c_{r,c} \\leq K and represent the color for the square (r,c)(r, c).


Sample Input 1

2

Sample Output 1

3
1 1 1
1 1 1
2 2 2
  • Every square in Color 11 has three adjacent squares in Color 11 and one adjacent square in Color 22.
  • Every square in Color 22 has two adjacent squares in Color 11 and two adjacent squares in Color 22.

Output such as the following will be judged incorrect:

2
1 2
2 2
``````plain
3
1 1 1
1 1 1
1 1 1

Sample Input 2

9

Sample Output 2

3
1 2 3
4 5 6
7 8 9