405831: GYM102133 B A Masterpiece

Memory Limit:64 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. A Masterpiecetime limit per test1 secondmemory limit per test64 megabytesinputstandard inputoutputstandard output

Supercomputer Deep Thought had answered the question to life, the universe, and everything a long time back and now has nothing to do. Suddenly another question has come to him recently. One famous artist has always been looking for an approach to create an "ideal" masterpiece and has spent 42 years to find the solution. He simply has decided to ask Deep Thought about it.

This question was too simple for supercomputer and he has produced the solution right after 42 seconds since the artist came. The algorithm is designed as follows:

  1. Take any world famous painting shaped as a square. For example, you may take Leonardo da Vinci's Joconde.
  2. Make a copy of this painting. Cut it into n2 identical size square pieces. It would be even better if you have performed it on the genuine masterpiece.
  3. Assign the numbers from 1 to n2 to obtained squares.
  4. Reorder the squares in such a way to guarantee that every subset consisting n squares including indices of every row and column should have equal sum of numbers written on these squares.
  5. To complete a masterpiece it is very important to make sure that the difference of every two adjacent by side elements exceeds 1.

Deep Thought refused to provide a masterpiece generation program for a given dimension n. Therefore, you have to do it by yourself.

Input

A single line contains only one positive integer number n – number of rows and columns in the cut painting.

1 ≤ n ≤ 42
Output

In the first line output number n. In the following n lines containing n integers each should be printed matrix. The printed matrix should agree with given above constraints to form a masterpiece. If multiple solution exist, you may output any of them. If solution does not exist, you should output -1.

ExamplesInput
5
Output
5
12 14 11 13 15
22 24 21 23 25
7 9 6 8 10
17 19 16 18 20
2 4 1 3 5
Input
3
Output
-1

加入题单

算法标签: