#C3540. Matrix Transposition

    ID: 46979 Type: Default 1000ms 256MiB

Matrix Transposition

Matrix Transposition

You are given a matrix of integers with dimensions M × N. Your task is to compute the transpose of the matrix.

The transpose of a matrix, denoted as \(A^T\), is formed by switching the rows and columns of the original matrix. That is, the element in the \(i^{th}\) row and \(j^{th}\) column of the original matrix becomes the element in the \(j^{th}\) row and \(i^{th}\) column in the transposed matrix.

Example:

Input:
1 2 3
4 5 6

Output: 1 4 2 5 3 6

</p>

Read the input from standard input and output the transposed matrix to standard output.

inputFormat

The input is read from standard input (stdin). The first line contains two integers M and N representing the number of rows and columns, respectively. Each of the next M lines contains N space-separated integers representing the rows of the matrix.

For example:

3 3
1 2 3
4 5 6
7 8 9

outputFormat

Output the transposed matrix to standard output (stdout) in the following format: Print N lines, each with M space-separated integers. There should be no extra spaces at the end of a line.

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

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

2 5 8 3 6 9

</p>