Competitions
Week 12: February 8 - 14
Print the chessboard
You are given a chessboard of size n * n. It is filled with numbers from 1 to n2
in the following way: the first ceil(n2
/ 2) numbers from 1 to ceil(n2
/ 2) are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n2
- ceil(n2
/ 2) numbers from ceil(n2
/ 2) + 1 to n2
are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ceil(x / y) means division x by y rounded up.
Input
One integer n (1 ≤ n ≤ 9).
Output
Print the matrix - the chessboard in the given manner. Watch for allignment!
Input example #1
5
Output example #1
1 14 2 15 3 16 4 17 5 18 6 19 7 20 8 21 9 22 10 23 11 24 12 25 13
Input example #2
6
Output example #2
1 19 2 20 3 21 22 4 23 5 24 6 7 25 8 26 9 27 28 10 29 11 30 12 13 31 14 32 15 33 34 16 35 17 36 18