Under construction

Still being built. Things may change

Chairs

Interview

Time limit1sMemory limit1024 MB

Summary
Find the lexicographically smallest shortest R/D path from the top-left to the bottom-right cell that visits every chair, or report Impossible.
Level

Medium5 of 10

Topics
Sorting, Dynamic programming, Greedy
Solved
No attempts yet

Problem

Ostap and Kisa are at a chair sale. They have two problems. First, they must leave the sale as soon as possible, because their rival company, represented by father Theodore, is closing in on them. Second, they must collect all the chairs at the sale.

The sale site is a rectangular table with NN rows and MM columns. Some cells contain chairs that need to be collected. Ostap and Kisa start at the top-left cell (1,1)(1, 1), and the exit is at the bottom-right cell (N,M)(N, M). A single move takes them from their current cell to any cell that shares a side with it. When they pass through a cell with a chair, they take that chair with them. Find a shortest path from the start cell to the exit cell. Among all such paths, find one that passes through every cell with a chair, or determine that no such path exists.

Input

The first line contains three integers NN, MM, and KK, the size of the table and the number of chairs (2≤N,M≤1002 \le N, M \le 100, 0≤K≤10000 \le K \le 1000). Each of the following KK lines contains two integers XiX_i and YiY_i, the row and the column of the ii-th chair (1≤Xi≤N1 \le X_i \le N, 1≤Yi≤M1 \le Y_i \le M). No cell contains more than one chair.

Output

If no shortest path passes through all the chairs, print Impossible on a single line.

Otherwise, print the sequence of moves on a single line. Each move is one symbol: R for moving right, and D for moving down. If several solutions exist, print the lexicographically smallest one.

Examples2

  1. Example 1

    Input
    3 3 2
    1 2
    3 3
    
    Expected output
    RDDR
    
  2. Example 2

    Input
    3 3 2
    1 2
    2 1
    
    Expected output
    Impossible