#K74857. Grid Shifting

    ID: 34290 Type: Default 1000ms 256MiB

Grid Shifting

Grid Shifting

Given a 2D grid of integers with m rows and n columns, and an integer k, the task is to shift the grid k times. In one shift, each element moves one position to the right. Specifically, the element at \(grid[i][j]\) moves to \(grid[i][j+1]\); the element at \(grid[i][n-1]\) moves to \(grid[i+1][0]\); and the element at \(grid[m-1][n-1]\) moves to \(grid[0][0]\).

You are required to read the grid and the integer k from standard input, perform the shifting operations, and output the resulting grid to standard output.

Note: All formulas are rendered in \(\LaTeX\) format.

inputFormat

The input is given from standard input in the following format:

Line 1: Two space-separated integers, (m) and (n), representing the number of rows and columns of the grid respectively.

Next (m) lines: Each line contains (n) space-separated integers representing the grid elements.

Last line: An integer (k) representing the number of shifts to perform.

outputFormat

Output the shifted grid to standard output. Each of the (m) lines should contain (n) space-separated integers representing one row of the grid after all the shifts.## sample

3 3
1 2 3
4 5 6
7 8 9
1
9 1 2

3 4 5 6 7 8

</p>