#K6076. Matrix Rotation: 90° Anti-Clockwise

    ID: 31158 Type: Default 1000ms 256MiB

Matrix Rotation: 90° Anti-Clockwise

Matrix Rotation: 90° Anti-Clockwise

You are given an M×N matrix of integers. Your task is to rotate the matrix by 90° in the anti-clockwise direction. The rotated matrix will have dimensions N×M.

Details:

  • The input matrix has M rows and N columns.
  • The rotation means that the element originally at position \(a_{ij}\) in the matrix will move to \(a'_{N-j-1, i}\).

You need to implement a solution that reads the matrix from standard input and writes the rotated matrix to standard output. Each row of the matrix should be printed on a separate line with the values separated by a single space.

Examples:

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

Output: 3 6 9 2 5 8 1 4 7

</p>

inputFormat

The first line contains two integers M and N separated by a space, representing the number of rows and columns of the matrix, respectively.

This is followed by M lines, each containing N integers separated by spaces representing the matrix elements.

Note: The input is read from standard input (stdin).

outputFormat

Output the rotated matrix. The rotated matrix will consist of N lines (rows), where each line contains M integers separated by a single space.

Note: The output must be sent to standard output (stdout).

## sample
1 1
1
1

</p>