#K36732. Rotate Matrix 90 Degrees

    ID: 25820 Type: Default 1000ms 256MiB

Rotate Matrix 90 Degrees

Rotate Matrix 90 Degrees

Given an (M \times M) matrix, your task is to rotate it (90^{\circ}) clockwise.

You must read the matrix from standard input, perform the rotation, and print the rotated matrix to standard output. The rotation can be performed by first transposing the matrix and then reversing each row.

Note: The matrix consists of (M) rows and (M) columns. Ensure your solution is efficient, especially for larger values of (M).

inputFormat

Input is read from standard input. The first line contains an integer (M), the dimension of the matrix. Each of the following (M) lines contains (M) space-separated integers representing the matrix rows.

outputFormat

Output the rotated matrix to standard output. Print (M) lines with (M) space-separated integers on each line corresponding to the rotated matrix.## sample

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

8 5 2 9 6 3

</p>