#C6612. Snake Matrix Fill

    ID: 50392 Type: Default 1000ms 256MiB

Snake Matrix Fill

Snake Matrix Fill

You are given two integers \( n \) and \( m \) that represent the number of rows and columns respectively, followed by \( n \times m \) unique integers. Your task is to fill an \( n \times m \) matrix in a snake-like pattern.

Snake-like pattern: For rows with even index (0-indexed), fill the row from left to right. For rows with odd index, fill the row from right to left. More formally, if \( i \) is the row index and \( a_{ij} \) denotes the element in the \( i \)-th row and \( j \)-th column, then:

[ a_{i0}, a_{i1}, \ldots, a_{i(m-1)} \quad \text{if } i \text{ is even}, ] [ a_{i(m-1)}, a_{i(m-2)}, \ldots, a_{i0} \quad \text{if } i \text{ is odd}. ]

The input is provided via stdin and your output must be printed to stdout.

inputFormat

The first line of input contains two integers \( n \) and \( m \) separated by a space.

The second line contains \( n \times m \) integers separated by spaces, which are the elements to fill the matrix.

outputFormat

Output the filled matrix in snake-like order. Each row of the matrix should be printed on a new line with the elements separated by a single space.

## sample
3 4
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4

8 7 6 5 9 10 11 12

</p>