#K82542. Matrix Rotation

    ID: 35998 Type: Default 1000ms 256MiB

Matrix Rotation

Matrix Rotation

You are given a matrix with n rows and m columns. Your task is to rotate the matrix by 90° in the clockwise direction. Formally, if the original matrix is \(A\) of size \(n \times m\), then the rotated matrix \(B\) will be of size \(m \times n\) and each element is defined by:

\[ B[j][n-1-i] = A[i][j] \quad \text{for } 0 \leq i < n \text{ and } 0 \leq j < m. \]

After rotation, print the resulting matrix where each row's elements are separated by a single space and rows are separated by a newline.

inputFormat

The first line of input contains two space-separated integers \(n\) and \(m\), representing the number of rows and columns of the matrix, respectively.

This is followed by \(n\) lines, each containing \(m\) space-separated integers representing the matrix elements.

outputFormat

Output the rotated matrix in \(m\) lines. Each line should contain \(n\) space-separated integers, which are the elements of the rotated matrix.

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

8 5 2 9 6 3

</p>