eolymp
bolt
Try our new interface for solving problems
Problems

Bypass matrix with "snake"

Bypass matrix with "snake"

For a given number n fill the square matrix of size n * n with integers from 1 to n2 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 (1n100).

Output

Print the filled matrix in the form of n rows by n integers each.

Time limit 1 second
Memory limit 128 MiB
Input example #1
3
Output example #1
1 2 3
6 5 4
7 8 9