#P9840. Kangaroo Gathering

    ID: 22985 Type: Default 1000ms 256MiB

Kangaroo Gathering

Kangaroo Gathering

After several memorable contests, this year you are given a n×n grid (with 2 ≤ n ≤ 500) where each cell initially has one kangaroo. By pressing one of the four keys U, D, L, and R, you can move all kangaroos simultaneously. For any kangaroo currently at cell ((i,j)):

  • Pressing U moves it to ((i-1,j)) if (i>1), otherwise it stays in place.
  • Pressing D moves it to ((i+1,j)) if (i<n), otherwise it stays in place.
  • Pressing L moves it to ((i,j-1)) if (j>1), otherwise it stays in place.
  • Pressing R moves it to ((i,j+1)) if (j<n), otherwise it stays in place.

Your task is to construct a sequence of operations (a string consisting only of the characters U, D, L, R) so that after applying the sequence, every kangaroo is gathered at the cell ((a,b)) (with 1 ≤ a, b ≤ n). The length of the sequence must not exceed (3(n-1)).

A valid solution that always works is based on forcing the kangaroos into one corner and then shifting them to the target. However, by careful observation one may design a sequence depending on the relation between (a) and (b). You may use the following strategy:

If (a \le b), perform:

  1. Press U for (n-1) times to bring every kangaroo to row 1.
  2. Press D for (a-1) times to move them to row (a).
  3. Press R for (n-1) times to bring every kangaroo to column n.
  4. Press L for (n-b) times to shift them to column (b).

If (a > b), perform:

  1. Press D for (n-1) times to bring every kangaroo to row n.
  2. Press U for (n-a) times to move them to row (a).
  3. Press L for (n-1) times to bring every kangaroo to column 1.
  4. Press R for (b-1) times to shift them to column (b).

This strategy guarantees that every kangaroo, regardless of its starting position, will visit the target cell ((a,b)) after executing the sequence. Note that in the worst-case scenario the total number of moves is exactly (3(n-1)).

Your program will receive three integers: (n, a, b) and is expected to output a valid operation sequence under the allowed length limit.

inputFormat

The input consists of a single line containing three integers separated by spaces: (n) (the size of the grid), (a) (the target row), and (b) (the target column), where 2 ≤ (n) ≤ 500 and 1 ≤ (a, b) ≤ (n).

outputFormat

Output a single line containing a string of characters (each being U, D, L, or R) that represents the sequence of operations. The length of the sequence must not exceed (3(n-1)) and it should guarantee that every kangaroo always ends up at cell ((a,b)).

sample

3 2 3
UUDRR