Tetris Tiling

Time limit: 0.3s Memory limit: 256MB Input: Output:

You are given an integer NN. You also have an empty N×NN \times N grid of cells, on top of which you can add tetris pieces in the following way:

  1. Select 44 cells from the grid which correspond to one of the following 88 shapes:

  1. If all 44 selected cells are empty, then a new tetris piece is placed on top of them.

Any grid obtained through these operations starting from an empty grid is called a tetris tiling.

Task

Find any N×NN \times N tetris tiling which uses the maximum possible number of pieces.

Input data

The first and only line of input contains a single integer NN, the size of the grid.

Output data

First, output one line containing one integer indicating the maximum number of tetris pieces that can placed on an N×NN \times N grid.

Then, output NN lines, each containing NN space-separated integers. The jj-th integer of the ii-th line is denoted by Ai,jA_{i,j}.

If Ai,j>0A_{i,j} > 0 then the cell in row ii and column jj belongs to piece Ai,jA_{i,j}. Otherwise, if Ai,jA_{i,j} is 00, the corresponding cell is empty and does not belong to any piece.

If there are multiple solutions which maximizes the number of pieces in the tiling, output any of them.

Constraints and clarifications

  • 1N1 0001 \le N \le 1 \ 000
# Points Constraints
1 25 N10N \le 10
2 25 10<N2010 \lt N \le 20
3 50 20<N20 \lt N

Example 1

stdin

2

stdout

0
0 0 
0 0

Example 2

stdin

3

stdout

1
0 1 0
0 1 1
0 0 1

Example 3

stdin

5

stdout

6
1 2 2 2 3
1 1 2 3 3
1 6 0 3 4
6 6 5 4 4
6 5 5 5 4

Explanation

It can be proven that for these values of NN, there are no tetris tilings that use more pieces than the ones depicted below.

Log in or sign up to be able to send submissions!