cswork / OAOpen practice workspace

MetaOA #9

Robot Matrix Commands

Estimated EasyJudge-ready

Topics (AI-labelled)Simulation

Execute the commands swapRows r1 r2, swapColumns c1 c2, reverseRow r, reverseColumn c, and rotate90Clockwise. Indices are 0-based; a rotation turns the matrix 90 degrees clockwise and may change the number of rows and columns. Every command index is valid for the matrix at that moment. The original site's combined example had answers that did not match the commands, so this site recomputed them.

Input

This site's input: R C (1..100), followed by R lines each containing C integers in 0..10⁹, then q (1..100), followed by q lines of commands.

Output

On the first line, output the number of rows and columns of the final matrix; then output the matrix row by row, with the elements of each row separated by spaces.

Example 1

Input:

2 3
1 2 3
4 5 6
1
rotate90Clockwise

Output:

3 2
4 1
5 2
6 3

Example 2

Input:

2 2
1 2
3 4
2
swapRows 0 1
reverseColumn 1

Output:

2 2
3 2
1 4

Example 3

Input:

1 1
1
1
reverseRow 0

Output:

1 1
1

Example notes

Example 1: rotating the 2×3 matrix clockwise produces a 3×2 matrix whose three rows are 4 1, 5 2, 6 3; the new dimensions 3 2 are output first.

Editorial

Loading solution…