#P6391. Magnet T Formation

    ID: 19607 Type: Default 1000ms 256MiB

Magnet T Formation

Magnet T Formation

In a 2D Cartesian plane, there is a robot initially located at the coordinate \((0,0)\). There are 5 magnets placed at distinct positions. The robot can move one unit at a time in one of the four cardinal directions (up, down, left, or right). Whenever the robot moves, if there is a magnet (or a cluster of magnets) in the destination cell, that magnet (or the entire cluster) is pushed one grid in the same direction.

Whenever two magnets become adjacent (i.e. they share a common edge), they stick together forming a connected cluster. When the robot pushes any magnet of this cluster, the whole cluster moves together.

Your task is to provide a valid movement scheme for the robot so that after executing the moves the 5 magnets form a T-shape in the plane. The target T-shape is defined (in its unique orientation) by the set of coordinates $$\{(x,y),\,(x+1,y),\,(x+2,y),\,(x+1,y+1),\,(x+1,y+2)\}$$ for some integers \(x\) and \(y\). Note that the T-shape cannot be rotated; it must appear exactly as specified above.

inputFormat

The input consists of 5 lines. Each line contains two space‐separated integers representing the (x) and (y) coordinates of a magnet. It is guaranteed that the magnets are located at distinct positions.

outputFormat

Output your solution in two parts. The first line should contain a single integer (N), denoting the number of moves in your plan. The second line should be a string of length (N) consisting solely of the characters 'U', 'D', 'L', 'R', which respectively denote a move up, down, left, and right by one grid unit. The sequence of moves, when applied (with magnet pushing and cluster formation taken into account), must result in the magnets forming the specified T-shape.

sample

0 0
1 0
2 0
1 1
1 2
0

</p>