CSES - Datatähti Open 2019 - Robot
  • Time limit: 1.00 s
  • Memory limit: 512 MB
Your task is to design an $n \times m$ grid for a robot, where each square is red, green or blue. Both numbers $n$ and $m$ are even.

The robot starts in the upper-left square and is directed to the right. On each step the robot acts as follows:
  1. Move one square forward.
  2. If the color of the current square differs from the color of the previous square, turn 90 degrees to the right.
  3. Change the color of the previous square: red becomes green, green becomes blue, and blue becomes red.
You have to choose the colors so that the robot visist every square and returns to the starting square. The robot may visit a square several times.

The robot may not move outside the grid, and it may use at most $10^6$ steps for its task.


The only input line has two even integers $n$ and $m$.


Print $n$ lines, each having $m$ characters: the coloring of the grid. The colors are red (R), green (G) and blue (B).

If there are no solutions, only print the text IMPOSSIBLE.


2 4


Subtask 1 (12 points)
  • $n = 2$
  • $2 \le m \le 100$
Subtask 2 (32 points)
  • $2 \le n,m \le 6$
Subtask 3 (56 points)
  • $2 \le n,m \le 100$