atcoder#ARC153B. [ARC153B] Grid Rotations
[ARC153B] Grid Rotations
Score : points
Problem Statement
We have a grid with rows from top to bottom and columns from left and right. Initially, the square at the -th row from the top and -th column from the left has a lowercase English letter .
Let us perform operations on this grid. In the -th operation, we are given integers and such that and , and do the following.
- Let , , , and be rectangular regions within the grid defined as follows:- is the intersection of the top rows and leftmost columns;
- is the intersection of the top rows and rightmost columns;
- is the intersection of the bottom rows and leftmost columns;
- is the intersection of the bottom rows and rightmost columns.
- is the intersection of the top rows and leftmost columns;
- is the intersection of the top rows and rightmost columns;
- is the intersection of the bottom rows and leftmost columns;
- is the intersection of the bottom rows and rightmost columns.
- Rotate degrees each of , , , and .
Here, a -degree rotation of a rectangular region within the grid moves the character on the square at the -th from the top and -th column from the left in to the square at the -th from the bottom and -th column from the right in . See also the figures for the samples.
Print the grid after all operations.
Constraints
- , and .
- is a lowercase English letter.
Input
The input is given from Standard Input in the following format:
Output
Print the grid after the operations in the following format, where is the character on the square on the final grid.
4 5
abcde
fghij
klmno
pqrst
1
3 3
mlkon
hgfji
cbaed
rqpts
The grid will change as follows.
3 7
atcoder
regular
contest
2
1 1
2 5
testcon
oderatc
ularreg
The grid will change as follows.
2 2
ac
wa
3
1 1
1 1
1 1
ac
wa
The grid will change as follows.