#C6163. Matrix Rotation (90° Clockwise)

    ID: 49893 Type: Default 1000ms 256MiB

Matrix Rotation (90° Clockwise)

Matrix Rotation (90° Clockwise)

You are given a matrix with n rows and m columns. Your task is to rotate the matrix by 90° clockwise. In the rotated matrix, the element originally at the ith row and jth column will move to the position (j, n-1-i). Mathematically, if the original matrix is \(A\) with dimensions \(n \times m\), then the rotated matrix \(B\) with dimensions \(m \times n\) is given by:

[ B_{i,j} = A_{n-1-j,i} ]

The input will be provided via standard input and the output should be printed to standard output.

inputFormat

The first line 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 rows of the matrix.

outputFormat

Output the rotated matrix in the following format: each row on a new line, with the elements separated by a single space.

## sample
2 2
1 2
3 4
3 1

4 2

</p>