eolymp
bolt
Try our new interface for solving problems

Snake

Rummaging through one of the chests at home, Karych found an old push-button telephone. There is only one game on this phone, but what a game! Snake! Karych used to play it a lot while, for example, riding a train or standing in a line.

The game takes place on the checkered field n * m. The field is not looped either vertically or horizontally. That is, if the snake crashes into the field boundary, the game will end with a loss. Field rows are numbered from 1 to n from top to bottom, and columns from 1 to m from left to right.

At any given time, a snake is a sequence of cells where every two consecutive cells are side-adjacent. Each cell occurs in the sequence at most once. The first cell in the sequence is called the head of the snake, and the last cell is called the tail. Also, one of the cells of the field that does not belong to the snake contains an apple.

On each turn, the player must choose one of the four directions of movement: "up", "down", "left" or "right". After that, the game finds a cell adjacent to the head of the snake in the direction chosen by the player. Let's call it q.

  • If there is no cell in the chosen direction, that is, the player went beyond the boundary of the field, the game ends.
  • Otherwise, if there is an apple in q, the snake eats it, its length increases by 1, and the cell q is added to the beginning of the sequence of cells representing the snake.
  • Otherwise, the last one (the tail) is removed from the sequence of cells first. Then, if the q cell still occurs in the sequence, then the snake has crashed into itself, so the game is over. Otherwise, cell q is appended to the start of the sequence.

Please note that due to the fact that the old tail cell is removed from the sequence first, and only then the new head cell is added, after the move, the head cell can occupy the cell in which the tail was before this move.

At the beginning of the game, the snake has a length of 1.

Karych heard that if you win this game, that is, fill all the cells of the field with a snake, then the game will show a cartoon. But he never managed to achieve this. Help him! You must make no more than 100000 moves.

Interaction Protocol

In the first line you will be given two integers n and m (2n, m10) - the size of the field.

The second line contains two integers xs and ys (1xsn, 1ysm) - the number of the row and column where the snake is located at the start of the game.

The third line contains two integers xa and ya (1xan, 1yam) - coordinates of the cell where the apple is located at the start of the game.

Next, you must interact with the testing program. On each turn, you must print one of the symbols indicating the direction of movement: "U" (up), "D" (down), "L" (left) or " R" (right).

Then, the program will print one of several possible answers:

  • "fail" - означает, что змейка врезалась в стену, съела себя, или у вас закончились ходы, но вы не выиграли. В этом случае, вы должны немедленно завершить исполнение программы, чтобы получить вердикт WA. Иначе, вы можете получить произвольный вердикт (отличный от AC).
  • "win" - длина змейки стала равна n * m, вы выиграли. Нужно, не выводя больше ничего, завершить исполнение программы.
  • "ok" - вы сделали корректный ход. В результате хода, голова змейки сдвинулась в выбранном вами направлении, длина змейки не изменилась.
  • "new" - вы сделали корректный ход и змейка съела яблоко. Голова змейки сдвинулась в выбранном направлении, длина змейки увеличилась на 1. В следующей строке даны два целых числа xa и ya (1xan, 1yam) - координаты новой позиции яблока.

Гарантируется, что в любой момент времени яблоко будет находиться в клетке, не принадлежащей змейке. Не забывайте после каждого вывода переводить строку и сбрасывать буфер вывода.

Time limit 1 second
Memory limit 128 MiB
Source 2020 Cycle of Internet Olympiads for schoolchildren, First team contest, October 18, Problem E