#K94632. 90-Degree Clockwise Matrix Rotation

    ID: 38685 Type: Default 1000ms 256MiB

90-Degree Clockwise Matrix Rotation

90-Degree Clockwise Matrix Rotation

Given an N x N matrix A, your task is to rotate the matrix by 90 degrees clockwise.

The rotated matrix B can be defined by the formula:

$$B[i][j] = A[n-1-j][i]$$

where n is the number of rows (or columns) in the matrix. This operation should be performed in-place if possible.

Implement a program that reads the matrix from standard input and outputs the rotated matrix to standard output.

inputFormat

The first line of input contains a single integer n (1 ≤ n ≤ 1000), representing the size of the matrix.

The next n lines each contain n space-separated integers, representing the rows of the matrix.

For example:

3
1 2 3
4 5 6
7 8 9

outputFormat

Output the rotated matrix in the same format: n lines where each line contains n space-separated integers, representing the rows of the 90-degree clockwise rotated matrix.

For example, the output for the sample input above should be:

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

8 5 2 9 6 3

</p>