Flowerbed Redecoration
Time limit3sMemory limit1024 MB
Given a grid and a sliding d by d window that rotates 90 degrees clockwise at each stop, output the grid after the full scan order is applied.
- Level
Hard8 of 10
- Topics
- Simulation, Matrix, Implementation
- Solved
- No attempts yet
Problem
Joon-Pyo decorated a flowerbed in front of his home. The flowerbed is an grid, and one flower is planted in each cell. There are 26 colors, one for each uppercase letter from A to Z. Suddenly, he wanted to redecorate the flowerbed.

The flowerbed is too large to adjust the flowers one by one. He rented equipment that can lift and rotate a square plot of land with side length . He planned the construction in the following order, expecting the flowerbed to be properly redecorated.
- Place the equipment so that exactly the flowers in the first rows and the first columns are inside.
- Rotate the square inside the equipment clockwise. If this square contains flowers from the last rows and the last columns, the construction is finished. Otherwise, if this square does not contain flowers in the last columns, move the equipment squares to the right. Otherwise, move the equipment down by squares and all the way to the left so it contains flowers from the first columns.
- Repeat step 2 until construction is finished.
The equipment never goes out of the flowerbed, since , , and are carefully determined before construction begins.
He cannot start construction without knowing the outcome. Write a program that outputs the result.
Input
The first line contains five integers , , , , and (, , , , , ). Each of the next lines contains exactly uppercase letters, which is the current flowerbed.
Output
Output lines, each containing exactly uppercase letters, the flowerbed after the planned construction.
Hint
In the first example, the flowerbed changes as follows:
