Wężyk
InterviewTime limit1sMemory limit128 MB
Print the numbers 1 to n squared in n rows that alternate between left-to-right and right-to-left order.
- Level
Easy1 of 10
- Topics
- Simulation, Matrix
- Solved
- No attempts yet
Problem
Staś's favorite game is called wężyk (a little snake). First he chooses one integer , then he starts writing consecutive natural numbers on a sheet of paper. In total he writes rows, each containing numbers.
In the first row Staś writes the numbers from to from left to right. The second row, however, he fills from right to left with the numbers from to . And so on: odd-numbered rows are filled from left to right, and even-numbered rows from right to left.
Your task is to write a program that plays wężyk automatically.
Input
The first and only line of input contains one natural number ().
Output
Print rows, each containing natural numbers. In total numbers must be printed: all natural numbers from to . Within each row the numbers must be separated by single spaces.