#C1818. Rotate Matrix

    ID: 45065 Type: Default 1000ms 256MiB

Rotate Matrix

Rotate Matrix

Given an \(n \times n\) matrix, your task is to rotate the matrix by 90 degrees clockwise. The rotation must be done in-place, i.e. you should not allocate another matrix for the rotation.

The rotation can be achieved in two steps:

  1. Transpose the matrix.
  2. Reverse each row.

Mathematically, if the input matrix is \(A\) and the rotated matrix is \(B\), then for each \(0 \le i,j < n\), the relation is:

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

inputFormat

The first line of input contains an integer \(n\), the number of rows (and columns) of the matrix. Each of the following \(n\) lines contains \(n\) space-separated integers representing a row of the matrix.

outputFormat

Output the rotated matrix. Each of the \(n\) lines should contain \(n\) space-separated integers representing a row of the rotated matrix.

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

8 5 2 9 6 3

</p>