Under construction

Still being built. Things may change

Choreography

Time limit2sMemory limit512 MB

Summary
Members on non-overlapping equal intervals move one at a time to an intersecting interval, and the task is to reach set E from set S in the fewest steps.
Level

Hard8 of 10

Topics
Greedy, Shortest path, Intervals
Solved
No attempts yet

Problem

Korean idol groups are known around the world for dynamic and elaborate group dances, called Kalgunmu. A group has mm members. One day the members practice their choreography on a stage. The stage is simplified as a line, and nn closed intervals of identical length are placed on it. During the choreography, the following rules must hold at every moment.

  • R1) Each member stands on one of the intervals.
  • R2) No two or more members can stand on the same interval.
  • R3) Two intervals on which any two members stand cannot intersect.

Two closed intervals [a,b][a, b] and [c,d][c, d] with a≤ca \le c intersect if c≤bc \le b.

The choreography consists of several steps with the following rules.

  • R4) At any step, only one member can move from her or his current interval to another interval. Two or more members cannot move at the same time.
  • R5) When a member changes the interval she or he stands on, the member has to move into one of the intervals that the current interval intersects. A member cannot move into an interval II if II intersects an interval on which another member stands, according to R3.
  • R6) The set of intervals on which the members stand at the start is SS.
  • R7) The set of intervals on which the members stand at the end is EE.

The sets SS and EE are given in the input. Each has size mm, and the intervals in each set do not intersect each other. Each member moves from an interval ss in SS to an interval ee in EE during the choreography. Find a choreography from SS to EE that satisfies R1 to R7 with the minimum number of steps, and output every step.

In the first figure, six intervals are numbered 1 to 6. The blue intervals 1 and 4 are the starting set SS, and the red intervals 3 and 6 are the ending set EE.

Figure E.1 Initial configuration SS.

Figure E.2 Four steps of a choreography. The member on interval 4 moves to interval 6 in one step, which allows the whole choreography to finish in three steps.

Input

The first line contains two integers mm and nn (1≤m≤n≤5,0001 \le m \le n \le 5{,}000). The intervals are numbered 1 to nn, and the left endpoint of interval ii is strictly less than the left endpoint of interval i+1i+1. The second line contains the length rr of the intervals (1≤r≤10,0001 \le r \le 10{,}000). The third line contains nn integers in ascending order, where the ii-th number is the left endpoint of interval ii. These values are between 0 and 10910^9. The next line contains the mm interval numbers of SS in ascending order. The last line contains the mm interval numbers of EE in ascending order.

Output

On the first line, print the minimum number of steps MINMIN. On each of the following MINMIN lines, print two integers aa and bb, meaning that at step ii a member moves from interval aa to interval bb. If several solutions exist, print any one of them. If no solution exists, print −1-1.

Examples3

  1. Example 1

    Input
    2 6
    6
    1 6 8 11 15 16
    1 4
    3 6
    
    Expected output
    3
    4 6
    1 2
    2 3
    
  2. Example 2

    Input
    2 6
    6
    1 6 8 11 15 16
    1 4
    1 4
    
    Expected output
    0
    
  3. Example 3

    Input
    2 6
    3
    1 6 8 11 15 16
    1 4
    3 6
    
    Expected output
    -1