eolymp
bolt
Try our new interface for solving problems
Problems

Magic Square

Magic Square

Numbers from \textbf{1} to \textbf{9} are written in \textbf{3}x\textbf{3} square at arbitrary positions. You can make cyclic shift by one element of some row (to the left or to the right) or column (to the up or to the down). The task is to implement a program, that could find a minimal number of shifts required to transform given square to the magic square. There is example of such transformation on the picture: \includegraphics{https://static.e-olymp.com/content/28/28ee2c52fa0c0f74172d4d70363c2f3a7e7324c7.jpg} \InputFile There are three lines in the input file. Each line represents row of the square and consists of three numbers separated by spaces. Note that any square could be transformed to the magic square with some number of cyclic shifts. \OutputFile The first line of output file should contain integer \textbf{n} -- the minimal number of shift operations required to transform given square to the magic one. First line is followed by \textbf{n} lines, each of them describe single shift. Shifts are encoded in such a way: \begin{itemize} \item \textbf{Dx} -- shift down the column \textbf{x}; \item \textbf{Ux} -- shift up the column \textbf{x}; \item \textbf{Lx} -- shift left the row \textbf{x}; \item \textbf{Rx} -- shift right the row \textbf{x}. \end{itemize} Row (column) number \textbf{x} is written after symbols "\textbf{D}", "\textbf{U}", "\textbf{L}" and "\textbf{R}" without space, \textbf{1} ≤ \textbf{x} ≤ \textbf{3}. Rows of the square are numbered from up to down, columns -- from left to right.
Time limit 3 seconds
Memory limit 64 MiB
Input example #1
1 2 3
4 5 6
7 8 9
Output example #1
4
L1
R3
U1
D3