Under construction

Still being built. Things may change

Mice

Interview

Time limit1sMemory limit1024 MB

Summary
Given mice and cheese positions on a line, find the movement direction and the fewest hungry mice under two eating rules.
Level

Medium5 of 10

Topics
Greedy, Sorting, Binary search
Solved
No attempts yet

Statement

MM mice are placed in a row. Some pieces of cheese are placed somewhere among them. All mice move in the same direction, either only to the left or only to the right, and no mouse overtakes another.

Each mouse has two options.

Option (A): Each mouse eats only one piece of cheese, the first uneaten piece it meets.

Option (B): Each mouse eats all uneaten pieces of cheese it meets along its path.

A position holds at most one mouse, but there can be more pieces of cheese. A position can contain a mouse and cheese at the same time.

Write a program mice that, for each option, prints the direction of movement and the minimum number of mice that eat no cheese.

Input

The first line contains an integer MM, the number of mice. The second line contains MM positive integers m1,m2,…,mMm_1, m_2, \ldots, m_M, the position of each mouse. The third line contains an integer NN, the number of pieces of cheese. The fourth line contains NN positive integers n1,n2,…,nNn_1, n_2, \ldots, n_N, the position of each piece of cheese.

Output

The first line prints the answer for option (A) as a symbol P1P_1 and a number B1B_1, separated by one space. P1P_1 is the direction of movement, and B1B_1 is the minimum number of mice that stay hungry.

The second line prints the answer for option (B) in the same format, with P2P_2 and B2B_2 having the same meanings as P1P_1 and B1B_1.

P1P_1 and P2P_2 are one of L, R, or D. L means left, R means right, and D means the minimum is the same whether the mice move left or right.

Limits

1≤M≤1000001 \le M \le 100000

1≤N≤1000001 \le N \le 100000

Examples2

  1. Example 1

    Input
    6
    2 3 8 9 11 12
    5
    1 4 6 7 10
    
    Expected output
    L 1
    L 3
    
  2. Example 2

    Input
    4
    1 2 3 5
    5
    2 2 3 3 4
    
    Expected output
    D 1
    L 1