All tasks
Mediumarraysloops

Transpose a Matrix

Time limit 2 s · Memory 64 MBAcceptance: —Solved by: 0

Statement

The first line contains n and m. Each of the next n lines contains m integers — an n×m matrix. Print the transposed matrix: m lines of n numbers, where line j of the new matrix is column j of the original.

Examples

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

Constraints

  • 1 ≤ n, m ≤ 300
  • -10^9 ≤ element ≤ 10^9
Solve this task to unlock the editorial.

AI tutor

Stuck? Get a nudge — the tutor explains the idea, it never hands you the solution.