QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 128 MB مجموع النقاط: 100

#15857. Danchi Blocks

الإحصائيات

Jiajia has recently become fascinated by a game called "Denki Blocks," but he has been unable to clear it because it is too difficult. The game is played on an unbounded board with a black obstacle at the center $(0,0)$. There are $N$ distinct gray blocks located at coordinates where both values are odd. The goal of the game is to move all the gray blocks so that they stick together to form a given shape, as shown in Figure 1. This shape can appear anywhere on the board, but it cannot be rotated or reflected. Figure 2 describes a valid initial state, where there is a gray block at each of the coordinates $(-1,-1)$, $(1,-1)$, and $(1,1)$.

Figure 1

Figure 2

In each turn, the player can use one of four movement commands—Up (U), Down (D), Left (L), or Right (R)—to move all gray blocks one unit in the specified direction simultaneously. If a block is blocked by an obstacle in the direction of movement, that specific block cannot move, while the other blocks continue to move as usual. For example, applying the commands LLUR to the state in Figure 2 results in the layout shown in Figure 3.

Figure 3

Once two or more blocks become adjacent, as in Figure 3, they immediately stick together to form an inseparable unit. In subsequent moves, if any block within this unit is blocked by an obstacle, the entire unit cannot move, even if the other blocks in the unit are not blocked. Thus, applying the commands URD to the state in Figure 3 results in Figure 4. Since the gray blocks in Figure 4 form the target shape, the game is won.

Figure 4

This game may look simple, but when there are many blocks and the target shape is complex, players often need many steps to complete it. Jiajia hopes to find a solution in no more than 2000 steps. Can you help him?

Input

The first line contains an integer $N$ ($3 \le N \le 20$), the number of blocks. The second line contains $N$ pairs of integers $x_i, y_i$ ($-9 \le x_i, y_i \le 9$, where $x_i, y_i$ are odd), where the $i$-th pair represents the initial position of the $i$-th block. The positions are ordered from top to bottom (i.e., increasing $x$) and from left to right (i.e., increasing $y$). The third line contains $N$ pairs of integers $Px_i, Py_i$ ($1 \le Px_i, Py_i \le N$), representing the relative positions of the small blocks in the target shape. It is guaranteed that the target shape is a connected whole and that a solution always exists.

Output

The first line should contain the number of steps $S$, and the second line should contain the sequence of moves.

Examples

Input 1

3
-1 -1 1 -1 1 1
1 1 2 1 2 2

Output 1

7
LLURURD

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.