563. Matrix Rotation

0

Medium

Given a 2D matrix of size n x n, rotate the matrix 90 degrees clockwise. The rotation must be done in-place, meaning the original matrix should be modified directly. Another 2D matrix should not be allocated for the rotation.

Input Format

The first line contains the number of rows in the matrix. The second line contains the number of columns in the matrix. The third line contains the elements of the matrix.

Output Format

Print the modified matrix.

Example

Input

3
3
1 2 3
4 5 6
7 8 9

Output

7 4 1
8 5 2
9 6 3

Constraints

n is equal to the length of the matrix and the length of each row in the matrix. The value of n must be between 1 and 20, inclusive. The values in the matrix must be between -1000 and 1000, inclusive.

Loading...

View Submissions

Console