#K40187. Matrix Rotation

    ID: 26587 Type: Default 1000ms 256MiB

Matrix Rotation

Matrix Rotation

You are given a matrix with r rows and c columns. Your task is to rotate this matrix 90° clockwise.

The rotation is defined as follows: if the input matrix is \(A\) of size \(r\times c\), then the rotated matrix \(B\) will be of size \(c\times r\) where \[ B[i][j] = A[r - 1 - j][i] \quad for \quad 0 \leq i < c \quad and \quad 0 \leq j < r. \]

For example, rotating the following matrix:

1 2 3
4 5 6
7 8 9
will produce:
7 4 1
8 5 2
9 6 3

Please note that the input will be provided via standard input (stdin) and the output should be written to standard output (stdout).

inputFormat

The first line of input contains two integers r and c separated by a space, representing the number of rows and columns of the matrix, respectively.

This is followed by r lines, each containing c integers separated by spaces, which represent the rows of the matrix.

outputFormat

The output should be the rotated matrix. Each row of the rotated matrix should be printed on a new line, with the values separated by a single space.

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

8 5 2 9 6 3

</p>