eolymp
bolt
Try our new interface for solving problems

Quiz

Almost everyone of you knows children's game "barley-break". At this problem you have to find a solution for some position. The game includes square fi eld \textbf{N}×\textbf{N}, divided into cells \textbf{1}×\textbf{1}. There are checks in each cells except of one. Number from \textbf{1} to \textbf{N^2-1}. is written on each cell. Each number occurs only once. At one turn you may move one of the chiecks next to the empty cell to it. Cell, where the check was, becomes empty. Checks cannot leave field. Solving puzzle means placing checks in the speci c order: \includegraphics{https://static.e-olymp.com/content/f3/f34b01abfa28ea3d6f3b758c85952d165aa7ca6f.jpg} Empty place must be in the last cell of the last line. For usual barley-break it looks so: \includegraphics{https://static.e-olymp.com/content/3b/3b729aefe960b0cea16eb96b711b56ffd3cf76c7.jpg} Position is given, nd sequence of turns (not necessarily shortest, probably empty) which solves it. Or output, that position has no solution. \InputFile The first line contains number \textbf{N, that is size of the field. It is followed by} \textbf{N} lines with \textbf{N} numbers in each. Numbers from \textbf{1} to \textbf{N^2-1} correspond to checks, \textbf{0} corresponds to empty place. Each number from \textbf{0} to \textbf{N^2-1} occurs only once. \OutputFile If position has no solution, write "\textbf{No}". Else write "\textbf{Yes}", in the fi rst line and appropriate sequence of turns, written in second line without spaces. Turns are encoded by next way: \begin{itemize} \item '\textbf{L}' - means, that check to the left of the empty place must be moved to it. \item '\textbf{R}' - means, that check to the right of the empty place must be moved to it. \item '\textbf{U}' - means, that check above the empty place must be moved to it. \item '\textbf{D}' - means, that check below the empty place must be moved to it. \end{itemize} Turns number must not exceed \textbf{2500000}. You may display any solutions if there are multiple ones. \textbf{Limits} \textbf{2} ≤ \textbf{N} ≤ \textbf{50} \textbf{0} ≤ \textbf{a_ij} ≤ \textbf{N^2-1}
Time limit 1 second
Memory limit 256 MiB
Input example #1
2
0 3
2 1
Output example #1
Yes
DRULDR