Bypass matrix with "snake"
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
For a given number n fill the square matrix of size n * n with integers from 1 to n^2
as follows:
The number 1 is in the upper left corner;
Then numbers go like a "snake", i.e. in ascending order from left to right in the odd lines and from right to left in the even;
Input
One integer n (1 ≤ n ≤ 100).
Output
Print the filled matrix in the form of n rows by n integers each.
Examples
Input #1
Answer #1
Submissions 8K
Acceptance rate 58%