#C481. Rotate Matrix Clockwise

    ID: 48389 Type: Default 1000ms 256MiB

Rotate Matrix Clockwise

Rotate Matrix Clockwise

You are given a matrix of dimensions \(m \times n\). Your task is to rotate the boundary elements (i.e. the outer layer or layers) of the matrix in a clockwise direction by one step. The rotation must be applied layer by layer, starting from the outermost layer and moving inwards. For matrices with either dimension equal to 0 or for layers that do not form a complete ring, the matrix remains unchanged.

Note: Each rotation moves every element of the boundary one position in the clockwise direction. The operation is performed separately for each concentric layer.

inputFormat

The first line contains two integers (m) and (n), representing the number of rows and columns respectively. This is followed by (m) lines, each containing (n) space-separated integers representing the matrix elements.

outputFormat

Output the rotated matrix. Each row should be printed on a new line with its elements separated by a single space.## sample

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

7 5 3 8 9 6

</p>