#C9699. Snake's Possible Moves

    ID: 53820 Type: Default 1000ms 256MiB

Snake's Possible Moves

Snake's Possible Moves

In this problem, you are given a board represented by a list of strings, where each string corresponds to a row. The board contains only the characters '.' (an empty cell) and 'S' (the snake's head). Your task is to determine which moves the snake can make without going off the board. The allowed moves are:

  • UP: Move one cell up.
  • DOWN: Move one cell down.
  • LEFT: Move one cell to the left.
  • RIGHT: Move one cell to the right.

For a move to be valid, the adjacent cell in that direction must be within the bounds of the board and must contain a '.'. The moves must be considered in the order: UP, DOWN, LEFT, RIGHT.

You may assume that there is exactly one snake head on the board. The checking conditions can be formally expressed as follows:

\(\text{If } S_{i,j} \text{ is the position of the snake, then for each move } d,\newline \text{the move is valid if } \text{cell}(i + \Delta_i, j + \Delta_j) = '.' \text{ and } 0 \leq i + \Delta_i < n, \; 0 \leq j + \Delta_j < m.\)

inputFormat

The input is given through STDIN:

  1. The first line contains an integer n, the number of rows in the board.
  2. The next n lines each contain a string. All strings have equal length and represent a row of the board. The board uses only the characters '.' and 'S'.

outputFormat

Output the list of possible moves that the snake can make. Each valid move should be printed on a separate line. The moves must be printed in the following order if they are valid: UP, DOWN, LEFT, RIGHT.

## sample
3
.......
.S.....
.......
UP

DOWN LEFT RIGHT

</p>