A solar farm's panels are arranged in a rectangular grid of m rows and n columns, and each panel holds an integer efficiency rating. Once every maintenance cycle, every panel's rating physically moves to the next panel when the grid is read in row-major order (left to right across a row, then down to the first column of the next row); the rating that falls off the very last panel of the last row wraps around and lands on the first panel of the first row. Given the starting grid and the number of cycles k, determine the grid after all k cycles have been applied.
Line 1: three integers m, n, k. Lines 2..m+1: each line contains n integers, the initial ratings of row i.
Print m lines, each containing n space-separated integers: the ratings after k cycles.
1 <= m, n <= 100 1 <= m * n <= 10000 -1000 <= rating <= 1000 0 <= k <= 10^9
Example 1
Input
2 3 1 5 8 13 21 34 55
Expected
55 5 8 13 21 34
Explanation
The farm has 2 rows and 3 columns holding ratings 5, 8, 13, 21, 34, 55 in row-major order. After one maintenance cycle every rating moves to the next panel in reading order, and the rating on the very last panel (55) wraps around to the first panel. The new row-major order becomes 55, 5, 8, 13, 21, 34, which reshapes into rows [55, 5, 8] and [13, 21, 34].
Example 2
Input
3 2 4 1 2 3 4 5 6
Expected
3 4 5 6 1 2
Explanation
There are 3 rows and 2 columns (6 panels total), so applying 4 cycles is the same as shifting forward by 4 mod 6 = 4 positions. Starting row-major order 1, 2, 3, 4, 5, 6 shifted forward by 4 becomes 3, 4, 5, 6, 1, 2, which reshapes into rows [3, 4], [5, 6], [1, 2].
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →