#P1413C. Perform Easily

    ID: 1231 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>binary searchbrute forcedpimplementationsortingstwo pointers*1900

Perform Easily

No submission language available for this problem.

Description

After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has 66 strings and an infinite number of frets numbered from 11. Fretting the fret number jj on the ii-th string produces the note ai+ja_{i} + j.

Tayuya wants to play a melody of nn notes. Each note can be played on different string-fret combination. The easiness of performance depends on the difference between the maximal and the minimal indices of used frets. The less this difference is, the easier it is to perform the technique. Please determine the minimal possible difference.

For example, if a=[1,1,2,2,3,3]a = [1, 1, 2, 2, 3, 3], and the sequence of notes is 4,11,11,12,12,13,134, 11, 11, 12, 12, 13, 13 (corresponding to the second example), we can play the first note on the first string, and all the other notes on the sixth string. Then the maximal fret will be 1010, the minimal one will be 33, and the answer is 103=710 - 3 = 7, as shown on the picture.

The first line contains 66 space-separated numbers a1a_{1}, a2a_{2}, ..., a6a_{6} (1ai1091 \leq a_{i} \leq 10^{9}) which describe the Tayuya's strings.

The second line contains the only integer nn (1n1000001 \leq n \leq 100\,000) standing for the number of notes in the melody.

The third line consists of nn integers b1b_{1}, b2b_{2}, ..., bnb_{n} (1bi1091 \leq b_{i} \leq 10^{9}), separated by space. They describe the notes to be played. It's guaranteed that bi>ajb_i > a_j for all 1in1\leq i\leq n and 1j61\leq j\leq 6, in other words, you can play each note on any string.

Print the minimal possible difference of the maximal and the minimal indices of used frets.

Input

The first line contains 66 space-separated numbers a1a_{1}, a2a_{2}, ..., a6a_{6} (1ai1091 \leq a_{i} \leq 10^{9}) which describe the Tayuya's strings.

The second line contains the only integer nn (1n1000001 \leq n \leq 100\,000) standing for the number of notes in the melody.

The third line consists of nn integers b1b_{1}, b2b_{2}, ..., bnb_{n} (1bi1091 \leq b_{i} \leq 10^{9}), separated by space. They describe the notes to be played. It's guaranteed that bi>ajb_i > a_j for all 1in1\leq i\leq n and 1j61\leq j\leq 6, in other words, you can play each note on any string.

Output

Print the minimal possible difference of the maximal and the minimal indices of used frets.

Samples

Sample Input 1

1 4 100 10 30 5
6
101 104 105 110 130 200

Sample Output 1

0

Sample Input 2

1 1 2 2 3 3
7
13 4 11 12 11 13 12

Sample Output 2

7

Note

In the first sample test it is optimal to play the first note on the first string, the second note on the second string, the third note on the sixth string, the fourth note on the fourth string, the fifth note on the fifth string, and the sixth note on the third string. In this case the 100100-th fret is used each time, so the difference is 100100=0100 - 100 = 0.

In the second test it's optimal, for example, to play the second note on the first string, and all the other notes on the sixth string. Then the maximal fret will be 1010, the minimal one will be 33, and the answer is 103=710 - 3 = 7.