P15413 [CCC 2019 J4/S1] Flipper Flip
Description
While waiting at the optometrist, you try to pass the time. You notice a grid containing four numbers:
|$1$ |$2$ |
|:-:|:-:|
|$3$ |$4$ |
You see many mirrors and lenses, so you wonder what happens if you flip this grid horizontally or vertically.
* One “horizontal flip” (flip along the horizontal center line) becomes:
|$3$|$4$|
|:-:|:-:|
|$1$|$2$|
* One “vertical flip” (flip along the vertical center line) becomes:
|$2$|$1$|
|:-:|:-:|
|$4$|$3$|
Your task is: after performing a sequence of horizontal and vertical flips, determine the final arrangement of the grid.
Input Format
The input is a single string, with length at least $1$ character and at most $1,000,000$ characters.
Each character is:
* `H` — represents one horizontal flip.
* `V` — represents one vertical flip.
For $8$ out of $15$ points, the input length is at most $1000$ characters.
Output Format
Output the final arrangement of the grid.
Print two lines, each with two integers, separated by one space.
Explanation/Hint
Translation source: GPT 5.2.
Translated by ChatGPT 5