Display the hamsters
One day, a group of hamsters appeared at Losyash's door, sniffling quietly and wiping their tearful eyes. "What happened?" Losyash asked, and they delivered a troubling message: two hamsters had gotten lost in the ventilation system designed by Pin to cool his supercomputer. Losyash decided to help the hamsters rescue their friends. The challenge is that the only way to assist them is by sending commands via radio. Help Losyash write a program to save the hamsters.
The ventilation maze is a flat rectangular grid with cut-out sections. There is only one exit in the maze. The hamsters are not very clever and cannot find their way out on their own. However, they can follow sets of commands. Commands are issued to both hamsters simultaneously, and they move at the same speed. The commands are as follows:
Move right -
R
Move left -
L
Move up -
U
Move down -
D
For simplicity, assume the maze is made up of cells. Each cell can be a passage, a wall, or an exit. The hamsters can occupy the same cell at the same time. They cannot pass through walls. Additionally, they have become so confused from wandering in the maze that they can only exit together. If only one hamster reaches the exit cell, it will not leave the maze and will continue to follow commands.
Input
The first line contains two integers H
and W
, representing the vertical and horizontal dimensions of the maze, respectively. The next H
lines contain W
characters, each of which can be: * - exit, 1 - the first hamster located in the passage, 2 - the second hamster located in the passage, .
- free cell, # - wall. H
, W
<= 100.
Output
On the first line, output the length of the program. On the second line, output the program for the hamsters. If there is no solution, output -1
.