#P1695E. Ambiguous Dominoes
Ambiguous Dominoes
Description
Polycarp and Monocarp are both solving the same puzzle with dominoes. They are given the same set of dominoes, the -th of which contains two numbers and . They are also both given the same by grid of values such that .
The puzzle asks them to place the dominoes on the grid in such a way that none of them overlap, and the values on each domino match the values that domino covers. Dominoes can be rotated arbitrarily before being placed on the grid, so the domino is equivalent to the domino .
They have both solved the puzzle, and compared their answers, but noticed that not only did their solutions not match, but none of the dominoes were in the same location in both solutions! Formally, if two squares were covered by the same domino in Polycarp's solution, they were covered by different dominoes in Monocarp's solution. The diagram below shows one potential grid, along with the two players' solutions.

Polycarp and Monocarp remember the set of dominoes they started with, but they have lost the grid . Help them reconstruct one possible grid , along with both of their solutions, or determine that no such grid exists.
The first line contains a single integer ().
The -th of the next lines contains two integers and ().
If there is no solution, print a single integer .
Otherwise, print and , the height and width of the puzzle grid, on the first line of output. These should satisfy .
The -th of the next lines should contain integers, the -th of which is .
The next lines describe Polycarp's solution. Print lines of characters each. For each square, if it is covered by the upper half of a domino in Polycarp's solution, it should contain a "U". Similarly, if it is covered by the bottom, left, or right half of a domino, it should contain "D", "L", or "R", respectively.
The next lines should describe Monocarp's solution, in the same format as Polycarp's solution.
If there are multiple answers, print any.
Input
The first line contains a single integer ().
The -th of the next lines contains two integers and ().
Output
If there is no solution, print a single integer .
Otherwise, print and , the height and width of the puzzle grid, on the first line of output. These should satisfy .
The -th of the next lines should contain integers, the -th of which is .
The next lines describe Polycarp's solution. Print lines of characters each. For each square, if it is covered by the upper half of a domino in Polycarp's solution, it should contain a "U". Similarly, if it is covered by the bottom, left, or right half of a domino, it should contain "D", "L", or "R", respectively.
The next lines should describe Monocarp's solution, in the same format as Polycarp's solution.
If there are multiple answers, print any.
Note
Extra blank lines are added to the output for clarity, but are not required.
The third sample case corresponds to the image from the statement.