#C7638. Zigzag Matrix Traversal

    ID: 51531 Type: Default 1000ms 256MiB

Zigzag Matrix Traversal

Zigzag Matrix Traversal

You are given an n x n matrix of integers. Your task is to traverse the matrix in a zigzag manner and print the elements in a single line, separated by a space.

The zigzag traversal means that for even-indexed rows (0-based indexing) you print the elements from left to right, and for odd-indexed rows you print the elements from right to left.

Formally, for a matrix \( A \) of size \( n \times n \), the traversal order is defined as follows:

[ \text{result} = \begin{cases} A[i][0], A[i][1], \ldots, A[i][n-1] & \text{if } i \text{ is even},\ A[i][n-1], A[i][n-2], \ldots, A[i][0] & \text{if } i \text{ is odd}.\ \end{cases} ]

The output should be printed to standard output.

inputFormat

The first line contains a single integer n, representing the size of the matrix. The following n lines each contain n space-separated integers representing the rows of the matrix.

outputFormat

Print a single line containing the elements of the matrix in zigzag order, separated by a single space.

## sample
3
1 2 3
4 5 6
7 8 9
1 2 3 6 5 4 7 8 9