PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000215. Thu thập đồng xu (Gather Coins)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Thu thập đồng xu (Gather Coins)

Gather Coins

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A grid contains HH rows and WW columns. Cell (r,c)(r,c) lies in row rr from the top and column cc from the left. There are NN coins at distinct cells (Ri,Ci)(R_i,C_i); neither (1,1)(1,1) nor (H,W)(H,W) contains a coin.

Starting at (1,1)(1,1), you may move one cell down or right at each step, staying in the grid. Collect the coin whenever you visit its cell. Reach (H,W)(H,W) while collecting as many coins as possible, and provide one route achieving that maximum.

Input

The first line contains three integers H,W,NH,W,N. The ii-th of the next NN lines contains two integers Ri,CiR_i,C_i, the coordinates of coin ii.

Output

Print two lines. The first contains the maximum number of coins. The second contains a string of exactly H+W−2H+W-2 characters describing a route, using D for down and R for right. Any optimal route is accepted.

Subtasks

  • Subtask 1 (20 points): 2≤H,W≤302\le H,W\le 30; 1≤N≤min⁡(HW−2,30)1\le N\le \min(HW-2,30); 1≤Ri≤H1\le R_i\le H, 1≤Ci≤W1\le C_i\le W for every 1≤i≤N1\le i\le N; coin cells are distinct and neither endpoint contains a coin.
  • Subtask 2 (30 points): 2≤H,W≤20002\le H,W\le 2000; 1≤N≤min⁡(HW−2,2000)1\le N\le \min(HW-2,2000); 1≤Ri≤H1\le R_i\le H, 1≤Ci≤W1\le C_i\le W for every 1≤i≤N1\le i\le N; coin cells are distinct and neither endpoint contains a coin.
  • Subtask 3 (50 points): 2≤H,W≤2000002\le H,W\le 200000; 1≤N≤min⁡(HW−2,200000)1\le N\le \min(HW-2,200000); 1≤Ri≤H1\le R_i\le H, 1≤Ci≤W1\le C_i\le W for every 1≤i≤N1\le i\le N; coin cells are distinct and neither endpoint contains a coin.

Examples

Input

3 4 4
3 3
2 1
2 3
1 4

Output

3
DRRDR

Explanation

Route DRRDR visits (2,1),(2,2),(2,3),(3,3),(3,4)(2,1),(2,2),(2,3),(3,3),(3,4) and collects coins at (2,1),(2,3),(3,3)(2,1),(2,3),(3,3). Coin (1,4)(1,4) cannot be combined with those three without moving up or left. Thus three is optimal.

Route

Input

2 2 2
2 1
1 2

Output

1
DR

Explanation

Route DR collects the coin at (2,1)(2,1), while RD collects the coin at (1,2)(1,2). A down/right route cannot visit both, so both routes are optimal.