Matrix TransposeEasy

Matrix Transpose

EasyPractice library · +10 XPmatrix

Given a matrix A of size N x M, compute and print its transpose, A^T. The transpose of a matrix is obtained by flipping the matrix over its main diagonal, switching the row and column indices of the matrix. That is, the element at A[i][j] will be at A^T[j][i].

Input

The first line contains two integers N and M (1 <= N, M <= 1000), the dimensions of the matrix. The next N lines each contain M integers, representing the elements of the matrix.

Output

Print N lines, each containing M integers, representing the transpose of the input matrix. The elements in each row should be separated by spaces.

Constraints

1 <= N, M <= 1000. The values of matrix elements are integers between -1000 and 1000.

Time limit 1 s (native code; slower languages get more)Memory 256 MB12 hidden tests

Example 1

Input
2 3
1 2 3
4 5 6
Output
1 4
2 5
3 6

A 2x3 matrix transposed becomes a 3x2 matrix.

Example 2

Input
3 2
10 20
30 40
50 60
Output
10 30 50
20 40 60

A 3x2 matrix transposed becomes a 2x3 matrix.

Hints