The last one(approximation)

2.5

2 votes
Medium
Problem

You must be bored of this Algo Cup and thats why you have opened this challenge problem. So, I wouldn't bore you more.

You need to make a magical square of side n which have digits 1m. All digits i which are 1im must appear once in the magical square.

A magic square is a square which has equal sum value of all rows and columns i.e if we add all the integers in a row/column it must be equal to sum of integers in any other row/column.

For a given m, you need to construct a magic square such that 1n103.

For a correct magic square you will get a total score = n4SumValueOfARow.

INPUT CONSTRAINTS

1m1000

INPUT FORMAT

Input contains a single integer m.

OUTPUT

Print a single integer n on the first line of output.After that print n lines each containing n space separated integers, denoting your magic square.

Sample Input
2
Sample Output
2
1 2 
2 1
Time Limit: 1
Memory Limit: 1023
Source Limit:
Explanation

This is a magic square with n=2, for m=2 maybe there exist some better magic square. This sqaure will get a score of 22223

Editor Image

?