#C9867. Robots’ Meeting Point

    ID: 54007 Type: Default 1000ms 256MiB

Robots’ Meeting Point

Robots’ Meeting Point

Two robots are positioned on a grid at coordinates \( (x_1,y_1) \) and \( (x_2,y_2) \). They want to meet by moving simultaneously. In each move a robot can move exactly one unit in one of the four directions:

  • D: increases the x-coordinate by 1
  • U: decreases the x-coordinate by 1
  • R: increases the y-coordinate by 1
  • L: decreases the y-coordinate by 1

The robots plan their moves in advance and then execute them concurrently.

The meeting is defined as follows: either the robots are already in the same row (i.e. \( x_1 = x_2 \)) or the same column (i.e. \( y_1 = y_2 \)), or they are diagonally adjacent, meaning \( |x_2 - x_1| = 1 \) and \( |y_2 - y_1| = 1 \). In these cases, they can choose appropriate one‐step moves so that after one round (or after a number of rounds equal to the nonzero coordinate difference) their paths cause them to “meet”. Otherwise, meeting is impossible.

If the two robots are in the same row, the robot on the left/right will move horizontally to meet the other; if in the same column, the top/bottom robot will move vertically. In the diagonal adjacent case, one robot moves vertically and the other moves in the opposite vertical direction.

Your task is to compute the minimum number of moves required for the robots to meet and determine a valid sequence of moves for each robot. Each move is represented by a character. If meeting is impossible, output Impossible.

Note: The move sequences are determined as follows:

  • If \( x_1 = x_2 \):
    • If \( y_2 > y_1 \), robot1 moves right (\(R\)) and robot2 moves left (\(L\)).
    • If \( y_2 < y_1 \), robot1 moves left (\(L\)) and robot2 moves right (\(R\)).
  • If \( y_1 = y_2 \):
    • If \( x_2 > x_1 \), robot1 moves down (\(D\)) and robot2 moves up (\(U\)).
    • If \( x_2 < x_1 \), robot1 moves up (\(U\)) and robot2 moves down (\(D\)).
  • If \( |x_2-x_1| = 1 \) and \( |y_2-y_1| = 1 \):
    • If \( x_2 > x_1 \), robot1 uses \(D\) and robot2 uses \(U\); otherwise, robot1 uses \(U\) and robot2 uses \(D\).

inputFormat

The input consists of a single line containing four space‐separated integers: \( x_1, y_1, x_2, y_2 \), representing the starting coordinates of the two robots.

outputFormat

If it is possible for the robots to meet, output the minimum number of moves on the first line. If the number of moves is greater than 0, then on the next two lines output the move sequence for robot1 and robot2 respectively (each sequence is represented as a string consisting of characters among {D, U, R, L}). If no moves are required, simply output 0. If meeting is impossible, output a single line containing Impossible.

Formatting: Input is read from standard input and output is written to standard output.

## sample
0 0 1 1
1

D U

</p>