As a thank you gift for an amazing year of teaching, you bought your ICS teacher a coffee. But when they drank the coffee, they started to feel funny.
When your teacher got home, they turned on the TV, and started to watch the news. The news was running a story on a coffee recall! Due to horrible quality control, coffee from Celestial Dollars is turning people sick. But not just a normal kind of sick. It is turning them into mice! Suddenly, your teacher found themself being transformed into a mouse!
The news wrapped up the story by mentioning that the company Hip Hip Array is testing an antidote. As an apology for poisoning your teacher, you are going to help them break into the lab and steal the antidote. Unfortunately for you, the lab has a high-tech security system of Boolean algebra mazes, meaning that you have to avoid getting electrocuted while travelling through the lab.
You will be given a grid that is \(N\) characters tall and \(M\) characters long. This grid represents the maze. You will next be given the contents of the maze.
Various characters mark different objects in the maze:
.Marks a blank space.
BMarks a block, which neither your teacher nor electricity can pass.
GMarks a wire that is on. This is guaranteed to be an input to a single gate.
RMarks a wire that is off. This is guaranteed to be an input to a single gate.
|Marks a wire with an unknown state, which you may need to figure out.
AMarks an AND gate. Your teacher cannot pass through an AND gate.
aMarks a NAND gate. Your teacher cannot pass through a NAND gate.
OMarks an OR gate. Your teacher cannot pass through an OR gate.
oMarks a NOR gate. Your teacher cannot pass through a NOR gate.
XMarks an XOR gate. Your teacher cannot pass through an XOR gate.
The second rows from the top and bottom will always be entirely made of blocks (
B) and unknown wires (
The maze is designed as a series of Boolean puzzles.
Each puzzle consists of two gates: one at the top row, and one at the bottom row. Each gate has two inputs, one from the left, and one from the right. The output of a gate points towards the other gate in the puzzle. The two gates of a single puzzle are always in the same column. The output of a gate will be a series of unknown wires (
|) all in the same column as the gate. This will extend until it reaches a block (
There is up to one block per column. An entire puzzle is \(3\) columns wide. There is at least \(1\) column separating two puzzles. Neither the first nor last columns will be part of a puzzle.
The first line contains \(N\ (7 \le N \le 500)\) and \(M\ (5 \le M \le 1000)\), separated by a space. \(N\) lines follow, each of which contain \(M\) characters.
Each of the next \(N\) lines contains the data for what is in each row. The rows are given in the order from top to bottom.
For each Boolean puzzle you encounter, output
Down, depending on which path is safe. The output for each puzzle should be on its own line. It is guaranteed that there is a unique solution.
7 10 .RAG..GAG. BB|BBBB|BB ..|....|.. ..B....B.. ..|....|.. BB|BBBB|BB .RoR..GXG.