This page is still under construction.

Parts of this page are still being built. What you see may change.

Diamonds

Time limit1sMemory limit128 MB

Summary
Arthas opens boxes outward from his starting keys to collect every diamond with the fewest openings.
Level

Medium7 of 10

Topics
Dynamic programming, Intervals, Graph
Solved
No attempts yet

Problem

King Terenas ordered his minister to build a game that would sharpen the mind of his son, prince Arthas. The minister came up with a game that uses NN boxes labeled 11 through NN. Every box has its own lock, and a lock opens only with the key cut for that box.

Before the game starts, the minister copies the key of box ii and puts one copy in box i−1i-1 and one copy in box i+1i+1, skipping whichever of the two does not exist. He then places one diamond in each of DD distinct boxes. Finally he locks every box and hands Arthas the keys to MM of them.

Arthas can open any box whose key he holds, and when he opens a box he takes everything inside it, both the keys and the diamond. The keys he takes let him open more boxes. Find the smallest number of boxes Arthas has to open to collect every diamond.

Input

The input contains several test cases. The first line of each test case holds the number of boxes NN (1≤N≤5001 \le N \le 500), the number of keys handed to Arthas MM (1≤M≤N1 \le M \le N), and the number of diamonds DD (0≤D≤N0 \le D \le N), separated by spaces. The second line lists the MM labels of the boxes whose keys Arthas received. The third line lists the DD labels of the boxes that contain a diamond, and this line is empty when DD is 00.

The last line of the input is 0 0 0.

Output

For each test case, print on one line the minimum number of boxes Arthas has to open to collect all diamonds.

Examples1

  1. Example 1

    Input
    5 1 5
    1
    1 2 3 4 5
    5 3 3
    1 2 3
    3 4 5
    5 3 1
    1 2 3
    5
    0 0 0
    
    Expected output
    5
    3
    3