Game with coins

시간 제한12초메모리 제한1024 MB

문제

This problem is interactive.

Taja can easily win this game, but all of her friends couldn't. Now she offers you to play this game.

Game equipment consists of field $n \times n$ ($5 \leq n \leq 40$), the piece, two coins (COIN1, COIN2), two dices with cardinal directions (DICE1, DICE2), and a lot of one cell size blocks.

NameNumber of facesFaces
COIN1. Move coin2SLIDE, RAM
COIN2. Modification coin2PLACE, REMOVE
DICE1. First dice with directions4N (North), S (South), W (West), E (East)
DICE2. Second dice with directions8N (North), S (South), W (West), E (East), NW (Northwest), NE (Northeast), SW (Southwest), SE (Southeast)

Before the beginning of the game the piece and some blocks are placed on the field. Then the player makes moves such kind. At first, the player chooses a coin and tosses it for determine an action. Then he chooses one of the dices and rolls it for determine direction $dir$. After that one of the four action happens:

Coin stringAction
SLIDEMove the piece along empty cells in the direction of $dir$, until the piece collides a block or maze border
RAMMove the piece along empty cells in the direction of $dir$, until it collides a first block. Then move the piece and the block in the same direction, until moving block collides another block or field border
PLACEIf adjacent cell in the direction $dir$ next to the piece is empty and is in the field, place a block on this cell
REMOVEIf adjacent cell in the direction $dir$ next to the piece contains a block and is in the field, remove the block from this cell

The goal is to put the piece on the finish cell.

One query for this problem is one coin toss and one dice roll.

입력

First line of the standard input contains one integer number $n$ --- the size of the maze. Next $n$ lines contains $n$ characters "." (ASCII $46$) or <<\#>> (ASCII $35$), denoting empty cell and cell with block respectively.

Next line contains two integer numbers $r_f$ and $c_f$ --- row number and column number of the finish cell. The upper-left corner is $(1, 1)$, the bottom-right is $(n, n)$. Finish cell and initial cell are empty.

Next groups describes each move:

  • The first line of an group contains two integer numbers $r$, $c$ --- row number and column number of the piece, or $(-1, -1)$, if the peace reaches the finish cell.
  • Next line contains action name shown on the coin.
  • Next line contains direction name shown on the dice.
  • If the current action is "RAM", next two strings contains two integer numbers $r_1$, $c_1$ and $r_2$, $c_2$, denotes then the piece collides a block with coordinates $(r_1, c_1)$ and moves that block to the cell $(r_2, c_2)$.

The north direction corresponds to decreasing row number. The south to increasing row number. The west direction to decreasing column number. The east direction to increasing column number.

Each side of any coin or dice is shown with the same probability.

출력

The standard output should consist of pair of lines: coin name and dice name. Coin name is the string "COIN1" or "COIN2". Dice name is the string "DICE1" or "DICE2".

힌트

The initial state of the maze for the sample is

And the representation of the path is shown below:

COIN2 $\rightarrow$ PLACE``DICE1 $\rightarrow$ WCOIN1 $\rightarrow$ RAM``DICE1 $\rightarrow$ S
COIN1 $\rightarrow$ RAM``DICE1 $\rightarrow$ WCOIN2 $\rightarrow$ PLACE``DICE2 $\rightarrow$ NE
COIN1 $\rightarrow$ RAM``DICE2 $\rightarrow$ NECOIN2 $\rightarrow$ REMOVE``DICE2 $\rightarrow$ NE
COIN2 $\rightarrow$ PLACE``DICE1 $\rightarrow$ SCOIN1 $\rightarrow$ SLIDE``DICE1 $\rightarrow$ W
COIN1 $\rightarrow$ RAM``DICE1 $\rightarrow$ SCOIN1 $\rightarrow$ SLIDE``DICE1 $\rightarrow$ E