All problems

Matrix Transpose

mediumPythonMatrices

Riverbend Bakery exports its sales grid with one line per day of the week and one column per branch. Head office reads it the other way round: they want one line per branch, showing that branch's week across the page. Nobody is retyping it, so the tool has to turn the export on its side.

Task: Print the grid flipped so that what was a column becomes a line.

Input

The first line holds two integers separated by a space: the number of lines in the grid and the number of values on each of those lines, each between 1 and 100. Then come that many lines, each holding that many integers separated by single spaces.

Output

One line per column of the input grid, each holding that column's values separated by single spaces, top to bottom. The value that sat on input line r at position c must end up on output line c at position r.

Example:

Input:
2 3
1 2 3
4 5 6

Output:
1 4
2 5
3 6

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…