Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/matritsa-90-gradusga-burish

Rotate by 90 degrees

Medium 1000 ms 128 MB 48%
Share

An integer matrix of size $n \times m$ is given. Rotate it $90^{\circ}$ clockwise and print the resulting $m \times n$ matrix: the first row of the original becomes the last column of the result.

Rotating the matrix clockwise

Input

The first line contains two positive integers $n$ and $m$. Each of the next $n$ lines contains $m$ integers.

Output

$m$ lines with $n$ space-separated integers each.

Note

$1 \le n, m \le 200$
$-1000 \le a_{i,j} \le 1000$

Examples

Input #1
2 3
1 2 3
4 5 6
Output #1
4 1
5 2
6 3
Input #2
1 3
7 8 9
Output #2
7
8
9

Sign in to submit a solution

Signing up is free and takes a minute.