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

Tayuya wants to play a melody of $n$ 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]$, and the sequence of notes is $4, 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 $10$, the minimal one will be $3$, and the answer is $10 - 3 = 7$, as shown on the picture. [Image] 


-----Input-----

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

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

The third line consists of $n$ integers $b_{1}$, $b_{2}$, ..., $b_{n}$ ($1 \leq b_{i} \leq 10^{9}$), separated by space. They describe the notes to be played. It's guaranteed that $b_i > a_j$ for all $1\leq i\leq n$ and $1\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.


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

Output
0

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

Output
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 $100$-th fret is used each time, so the difference is $100 - 100 = 0$. [Image] 

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 $10$, the minimal one will be $3$, and the answer is $10 - 3 = 7$. [Image]

Difficulty: interview

Starter code:

Solutions:
from sys import stdin
input = stdin.readline

a = sorted([int(i) for i in input().split()])
n = int(input())
b = sorted([int(i) for i in input().split()])

c = []
for i in range(n):
    c += [[b[i] - a[j], i] for j in range(6)]
c.sort()

d = [0] * n
e = 0

ans = 10 ** 10

u = 0
for i in range(len(c)):
    while u < len(c) and e < n:
        x = c[u][1]
        if d[x] == 0:
            e += 1
        d[x] += 1
        u += 1

    if e == n:
        ans = min(ans, c[u - 1][0] - c[i][0])

    x = c[i][1]
    d[x] -= 1
    if d[x] == 0:
        e -= 1

print(ans)
        
        


a=list(map(int,input().split()))
n=int(input())
s=list(map(int,input().split()))
b=[]
for i in range(n):
	for j in a:
		b.append((s[i]-j)*n+i)
b.sort()
cs={}
i=j=0
ans=10**18
def dd(w):
	cs[w]=cs.get(w,0)+1
def em(w):
	cs[w]-=1
	if cs[w]==0:cs.pop(w)
dd(b[0]%n)
while j<len(b):
	while j+1<len(b) and len(cs)<n:
		j+=1
		dd(b[j]%n)
	while len(cs)==n:
		ans=min(ans,b[j]//n-b[i]//n)
		em(b[i]%n)
		i+=1
	if j+1==len(b):
		break
print(ans)

a=list(map(int,input().split()));n=int(input());s=list(map(int,input().split()));b=[]
for i in range(n):
	for j in a:b.append((s[i]-j)*n+i)
b=sorted(b);cs={};i=j=0;ans=10**18
cs[b[0]%n]=cs.get(b[0]%n,0)+1;z=len(b)
while j<z:
	while j+1<z and len(cs)<n:j+=1;cs[b[j]%n]=cs.get(b[j]%n,0)+1
	while len(cs)==n:
		ans=min(ans,b[j]//n-b[i]//n)
		cs[b[i]%n]-=1
		if cs[b[i]%n]==0:cs.pop(b[i]%n)
		i+=1
	if j+1==z:break
print(ans)

from sys import stdin
input = stdin.readline

a = sorted([int(i) for i in input().split()])
n = int(input())
b = sorted([int(i) for i in input().split()])

c = []
for i in range(n):
    c += [[b[i] - a[j], i] for j in range(6)]
c.sort()

d = [0] * n
e = 0

ans = 10 ** 10

u = 0
for i in range(len(c)):
    while u < len(c) and e < n:
        x = c[u][1]
        if d[x] == 0:
            e += 1
        d[x] += 1
        u += 1

    if e == n:
        ans = min(ans, c[u - 1][0] - c[i][0])

    x = c[i][1]
    d[x] -= 1
    if d[x] == 0:
        e -= 1

print(ans)
        
        

































a=list(map(int,input().split()));n=int(input());s=list(map(int,input().split()));b=[]
for i in range(n):
	for j in a:b.append((s[i]-j)*n+i)
b=sorted(b);i=j=0;ans=10**18;cs=[0]*n;cs[b[0]%n]+=1;nz=1;z=len(b)
while j<z:
	while j+1<z and nz<n:
		j+=1;cs[b[j]%n]+=1
		if cs[b[j]%n]==1:nz+=1
	while nz==n:
		ans=min(ans,b[j]//n-b[i]//n)
		cs[b[i]%n]-=1
		if cs[b[i]%n]==0:nz-=1
		i+=1
	if j+1==z:break
print(ans)

a=list(map(int,input().split()));n=int(input());s=list(map(int,input().split()));b=[];i=j=0;ans=10**18;cs=[0]*n;nz=1;z=n*6
for y in range(n):
	for x in a:b.append((s[y]-x)*n+y)
b.sort();cs[b[0]%n]+=1
while j<z:
	while j+1<z and nz<n:
		j+=1;cs[b[j]%n]+=1
		if cs[b[j]%n]==1:nz+=1
	while nz==n:
		ans=min(ans,b[j]//n-b[i]//n);cs[b[i]%n]-=1
		if cs[b[i]%n]==0:nz-=1
		i+=1
	if j+1==z:break
print(ans)

a=list(map(int,input().split()));n=int(input());s=list(map(int,input().split()));b=[];i=j=0;ans=10**18;cs=[0]*n;nz=1;z=n*6
for y in range(n):
	for x in a:b.append((s[y]-x)*n+y)
b.sort();cs[b[0]%n]+=1
while j+1<z:
	while j+1<z and nz<n:j+=1;nz+=cs[b[j]%n]<1;cs[b[j]%n]+=1
	while nz==n:ans=min(ans,b[j]//n-b[i]//n);cs[b[i]%n]-=1;nz-=cs[b[i]%n]==0;i+=1
print(ans)

from collections import deque as _deque
from itertools import chain as _chain
import sys as _sys


def main():
    a_seq = tuple(_read_ints())
    n, = _read_ints()
    notes = tuple(_read_ints())
    result = find_minimal_melody_difficulty(a_seq, notes)
    print(result)


def find_minimal_melody_difficulty(strings_values, notes):
    strings_values = set(strings_values)
    strings_values = sorted(strings_values, reverse=True)
    if len(strings_values) == 1:
        return max(notes) - min(notes)
    
    frets_by_notes_indices = [[note - x for x in strings_values] for note in notes]
    # frets_by_notes_indices[i_note] is sorted for every correct i_note
    del strings_values
    del notes
    
    max_from_initially_selected_frets = max(frets[0] for frets in frets_by_notes_indices)
    for frets in frets_by_notes_indices:
        i_first_interesting_fret = 0
        while i_first_interesting_fret + 1 < len(frets) \
                and frets[i_first_interesting_fret+1] <= max_from_initially_selected_frets:
            i_first_interesting_fret += 1
        frets[:] = frets[i_first_interesting_fret:]
    
    selected_frets = [frets[0] for frets in frets_by_notes_indices]
    selected_frets.sort()
    selected_frets = _deque(selected_frets)
    
    available_selections = _chain.from_iterable(
        list(zip(frets[1:], frets[0:]))
        for frets in frets_by_notes_indices
    )
    available_selections = sorted(available_selections)
    
    # defaultdict(int) is slower
    frets_to_unselect = dict()
    for frets in frets_by_notes_indices:
        for fret in frets:
            frets_to_unselect[fret] = 0
    
    min_selected_fret = selected_frets[0]
    max_selected_fret = max(selected_frets)
    result = max_selected_fret - min_selected_fret
    
    for new_fret, fret_to_unselect in available_selections:
        frets_to_unselect[fret_to_unselect] += 1
        _clean_deque_begin(selected_frets, frets_to_unselect)
        selected_frets.append(new_fret)
        
        min_selected_fret = selected_frets[0]
        max_selected_fret = new_fret
        result = min(result, max_selected_fret - min_selected_fret)
    
    return result


def _clean_deque_begin(deque, deletions_ns):
    while deque and deletions_ns[deque[0]] > 0:
        deleted_element = deque.popleft()
        deletions_ns[deleted_element] -= 1


def _read_line():
    result = _sys.stdin.readline()
    assert result[-1] == "\n"
    return result[:-1]


def _read_ints():
    return list(map(int, _read_line().split()))


def __starting_point():
    main()

__starting_point()

import sys
import operator


#-----------

def solve():
    a = [int(x) for x in input().split()]

    n = int(input())

    b = [int(x) for x in input().split()]

    have = []
    arr_append = have.append
    for i in range(0, n):
        for j in range(0, 6):
            arr_append([ b[i] - a[j], i ])

    cnt = [0]*n

    z = n
    sz = len(have)
    ans = 999999999999
    r = 0
    have.sort(key=operator.itemgetter(0))

    for i in range(0, sz):
        while (r < sz) and (z > 0):
            cnt[have[r][1]] += 1
            if (cnt[have[r][1]] == 1):
                z-=1
        
            r+=1
    
        if (z > 0):
           break

        ans = min(ans, have[r - 1][0] - have[i][0]);
        cnt[have[i][1]] -= 1
        if (cnt[have[i][1]] == 0):
            z+=1
    
    print(ans)


#-----------

def main(argv):
    solve()

def __starting_point():
    main(sys.argv)

__starting_point()

import sys
import operator
import array

#-----------

def solve():
    a = [int(x) for x in input().split()]

    n = int(input())

    b = [int(x) for x in input().split()]

    have = [ [] ] * (n*6)
    arr_append = have.append
    for i in range(0, n):
        for j in range(0, 6):
            #arr_append([ b[i] - a[j], i ])
            have[i*6 + j] = [ b[i] - a[j], i ]
    
    cnt = array.array('L', [0])*n

    z = n
    sz = len(have)
    ans = 999999999999
    r = 0
    have.sort(key=operator.itemgetter(0))

    for i in range(0, sz):
        while (r < sz) and (z > 0):
            cnt[have[r][1]] += 1
            if (cnt[have[r][1]] == 1):
                z-=1
        
            r+=1
    
        if (z > 0):
           break

        ans = min(ans, have[r - 1][0] - have[i][0]);
        cnt[have[i][1]] -= 1
        if (cnt[have[i][1]] == 0):
            z+=1
    
    print(ans)


#-----------

def main(argv):
    solve()

def __starting_point():
    main(sys.argv)

__starting_point()

import sys
import operator

#-----------

def solve():
    a = (list(map(int, input().split())))

    n = int(input())

    b = (list(map(int, input().split())))

    #have = [ [] ] * (n*6)
    have = []
    arr_append = have.append
    for i in range(0, n):
        for j in range(0, 6):
            arr_append([ b[i] - a[j], i ])
            #have[i*6 + j] = [ b[i] - a[j], i ]

    have.sort(key=operator.itemgetter(0))

    cnt = [0]*n

    z = n
    sz = len(have)
    ans = 999999999999
    r = 0
    
    for i in range(0, sz):
        while (r < sz) and (z > 0):
            cnt[have[r][1]] += 1
            if (cnt[have[r][1]] == 1):
                z-=1
        
            r+=1
    
        if (z > 0):
           break

        ans = min(ans, have[r - 1][0] - have[i][0]);
        cnt[have[i][1]] -= 1
        if (cnt[have[i][1]] == 0):
            z+=1
    
    print(ans)


#-----------

def main(argv):
    solve()

def __starting_point():
    main(sys.argv)

__starting_point()

from itertools import chain as _chain
import sys as _sys


def main():
    a_seq = tuple(_read_ints())
    n, = _read_ints()
    notes = tuple(_read_ints())
    result = find_minimal_melody_difficulty(a_seq, notes)
    print(result)


def find_minimal_melody_difficulty(strings_values, notes):
    strings_values = set(strings_values)
    strings_values = sorted(strings_values, reverse=True)
    if len(strings_values) == 1:
        return max(notes) - min(notes)
    
    frets_by_notes_indices = [[note - x for x in strings_values] for note in notes]
    # frets_by_notes_indices[i_note] is sorted for every correct i_note
    del strings_values
    del notes
    
    max_initially_selected_fret = max(frets[0] for frets in frets_by_notes_indices)
    for frets in frets_by_notes_indices:
        i_first_interesting_fret = 0
        while i_first_interesting_fret + 1 < len(frets) \
                and frets[i_first_interesting_fret+1] <= max_initially_selected_fret:
            i_first_interesting_fret += 1
        frets[:] = frets[i_first_interesting_fret:]
    
    sorted_frets = sorted(_chain.from_iterable(frets_by_notes_indices))
    
    initially_selected_frets = [frets[0] for frets in frets_by_notes_indices]
    min_initially_selected = min(initially_selected_frets)
    i_first_selected = sorted_frets.index(min_initially_selected)
    while i_first_selected+1 < len(sorted_frets) \
            and sorted_frets[i_first_selected+1] == min_initially_selected:
        i_first_selected += 1
    i_first_selected -= initially_selected_frets.count(min_initially_selected) - 1
    i_last_selected = i_first_selected + len(initially_selected_frets) - 1
    
    available_selections = _chain.from_iterable(
        list(zip(frets[1:], frets[0:]))
        for frets in frets_by_notes_indices
    )
    available_selections = sorted(available_selections)
    
    # TODO: can replace it with indices_to_unselect
    # defaultdict(int) is slower
    frets_to_unselect = dict()
    for frets in frets_by_notes_indices:
        for fret in frets:
            frets_to_unselect[fret] = 0
    
    result = sorted_frets[i_last_selected] - sorted_frets[i_first_selected]
    
    for new_fret, fret_to_unselect in available_selections:
        frets_to_unselect[fret_to_unselect] += 1
        i_first_selected = _shift_index_skipping(sorted_frets, i_first_selected, frets_to_unselect)
        i_last_selected += 1
        current_maxmin_difference = sorted_frets[i_last_selected] - sorted_frets[i_first_selected]
        if current_maxmin_difference < result:
            result = current_maxmin_difference
    
    return result


def _shift_index_skipping(sorted_seq, index, deletions_ns):
    while index < len(sorted_seq) and deletions_ns[sorted_seq[index]] > 0:
        deleted_element = sorted_seq[index]
        index += 1
        deletions_ns[deleted_element] -= 1
    return index


def _read_line():
    result = _sys.stdin.readline()
    assert result[-1] == "\n"
    return result[:-1]


def _read_ints():
    return list(map(int, _read_line().split()))


def __starting_point():
    main()

__starting_point()

import sys
import operator
import array

#-----------

def solve():
    a = (list(map(int, input().split())))

    n = int(input())

    b = (list(map(int, input().split())))

    #have = [ [] ] * (n*6)
    have = []
    arr_append = have.append
    for i in range(0, n):
        for j in range(0, 6):
            arr_append(( b[i] - a[j], i ))
            #have[i*6 + j] = [ b[i] - a[j], i ]

    have.sort(key=operator.itemgetter(0))

    cnt = array.array('L', [0])*n

    z = n
    sz = len(have)
    ans = 999999999999
    r = 0
    
    for i in range(0, sz):
        while (r < sz) and (z > 0):
            cnt[have[r][1]] += 1
            if (cnt[have[r][1]] == 1):
                z-=1
        
            r+=1
    
        if (z > 0):
           break

        ans = min(ans, have[r - 1][0] - have[i][0]);
        cnt[have[i][1]] -= 1
        if (cnt[have[i][1]] == 0):
            z+=1
    
    print(ans)


#-----------

def main(argv):
    solve()

def __starting_point():
    main(sys.argv)

__starting_point()

import sys
import operator
import array

#-----------

def solve():
    a = (list(map(int, input().split())))

    n = int(input())

    b = (list(map(int, input().split())))

    have = [ [] ] * (n*6)
    #have = []
    arr_append = have.append
    for i in range(0, n):
        for j in range(0, 6):
            #arr_append(( b[i] - a[j], i ))
            have[i*6 + j] = ( b[i] - a[j], i )

    have.sort(key=operator.itemgetter(0))

    cnt = array.array('L', [0])*n

    z = n
    sz = len(have)
    ans = 999999999999
    r = 0
    
    for i in range(0, sz):
        while (r < sz) and (z > 0):
            cnt[have[r][1]] += 1
            if (cnt[have[r][1]] == 1):
                z-=1
        
            r+=1
    
        if (z > 0):
           break

        ans = min(ans, have[r - 1][0] - have[i][0]);
        cnt[have[i][1]] -= 1
        if (cnt[have[i][1]] == 0):
            z+=1
    
    print(ans)


#-----------

def main(argv):
    solve()

def __starting_point():
    main(sys.argv)

__starting_point()

import sys
import operator
import array

#-----------

def solve():
    a = (list(map(int, input().split())))

    n = int(input())

    b = (list(map(int, input().split())))

    have = [ [] ] * (n*6)
    #have = []
    arr_append = have.append
    c=0
    for i in range(0, n):
        for j in range(0, 6):
            #arr_append(( b[i] - a[j], i ))
            have[c] = ( b[i] - a[j], i )
            c+=1

    have.sort(key=operator.itemgetter(0))

    cnt = array.array('L', [0])*n

    z = n
    sz = len(have)
    ans = 999999999999
    r = 0
    
    for i in range(0, sz):
        while (r < sz) and (z > 0):
            cnt[have[r][1]] += 1
            if (cnt[have[r][1]] == 1):
                z-=1
        
            r+=1
    
        if (z > 0):
           break

        ans = min(ans, have[r - 1][0] - have[i][0]);
        cnt[have[i][1]] -= 1
        if (cnt[have[i][1]] == 0):
            z+=1
    
    print(ans)


#-----------

def main(argv):
    solve()

def __starting_point():
    main(sys.argv)

__starting_point()

import sys
import operator
import array

#-----------

def solve():
    a = (tuple(map(int, input().split())))

    n = int(input())

    b = (tuple(map(int, input().split())))

    have = [ [] ] * (n*6)
    #have = []
    # arr_append = have.append
    c=0
    for i in range(0, n):
        for j in range(0, 6):
            #arr_append(( b[i] - a[j], i ))
            have[c] = ( b[i] - a[j], i )
            c+=1

    have.sort(key=operator.itemgetter(0))

    cnt = array.array('L', [0])*n

    z = n
    sz = len(have)
    ans = 999999999999
    r = 0
    
    for i in range(0, sz):
        while (r < sz) and (z > 0):
            cnt[have[r][1]] += 1
            if (cnt[have[r][1]] == 1):
                z-=1
        
            r+=1
    
        if (z > 0):
           break

        ans = min(ans, have[r - 1][0] - have[i][0]);
        cnt[have[i][1]] -= 1
        if (cnt[have[i][1]] == 0):
            z+=1
    
    print(ans)


#-----------

def main(argv):
    solve()

def __starting_point():
    main(sys.argv)

__starting_point()

import sys
import operator
import array

#-----------

def solve():
    a = (list(map(int, input().split())))

    n = int(input())

    b = (list(map(int, input().split())))

    lad = [ [] ] * (n*6)
    #lad = []
    # arr_append = lad.append
    c=0
    for i in range(0, n):
        for j in range(0, 6):
            #arr_append(( b[i] - a[j], i ))
            lad[c] = ( b[i] - a[j], i )
            c+=1

    lad.sort(key=operator.itemgetter(0))

    cnt = array.array('L', [0])*n

    z = n
    ladcnt = len(lad)
    ans = 999999999999
    r = 0
    
    for i in range(0, ladcnt):
        while (r < ladcnt) and (z > 0):
            cnt[lad[r][1]] += 1
            if (cnt[lad[r][1]] == 1):
                z-=1
        
            r+=1
    
        if (z > 0):
           break

        ans = min(ans, lad[r - 1][0] - lad[i][0]);
        cnt[lad[i][1]] -= 1
        if (cnt[lad[i][1]] == 0):
            z+=1
    
    print(ans)


#-----------

def main(argv):
    solve()

def __starting_point():
    main(sys.argv)

__starting_point()

import sys
import operator
import array

#-----------

def solve():
    a = (list(map(int, input().split())))

    n = int(input())

    b = (list(map(int, input().split())))

    lad = [ [] ] * (n*6)
    #lad = []
    # arr_append = lad.append
    c=0
    for i in range(0, n):
        for j in range(0, 6):
            #arr_append(( b[i] - a[j], i ))
            lad[c] = ( b[i] - a[j], i )
            c+=1

    lad.sort(key=operator.itemgetter(0))

    cnt = array.array('L', [0])*n

    z = n
    ladcnt = len(lad)
    ans = 999999999999
    r = 0
    
    for i in range(0, ladcnt):
        while (r < ladcnt) and (z > 0):
            cnt[lad[r][1]] += 1
            if (cnt[lad[r][1]] == 1):
                z-=1
        
            r += 1
    
        if (z > 0):
           break

        ans = min(ans, lad[r - 1][0] - lad[i][0]);
        cnt[lad[i][1]] -= 1
        if (cnt[lad[i][1]] == 0):
            z+=1
    
    print(ans)


#-----------

def main(argv):
    solve()

def __starting_point():
    main(sys.argv)

__starting_point()

la = input().split()
la = list(map(int,la))
t=input()
lb = input().split()
lb = list(map(int,lb))
lenb=len(lb)
l=[(lb[j]-i,j) for i in la for j in range(lenb)]
l.sort()
last=0
first=0

l0=[0]*lenb
l1=[i for i in range(lenb)]
dic=dict(list(zip(l1,l0)))
dic[l[first][1]]+=1
length=1
lenl=len(l)
while (length<lenb):
    last+=1
    if dic[l[last][1]]==0:
        length+=1
    dic[l[last][1]]+=1

minnum=l[last][0]-l[first][0]
t=0
while (1):
    dic[l[first][1]] -= 1
    while dic[l[first][1]]!=0:

        first += 1
        dic[l[first][1]]-=1

        if minnum > l[last][0] - l[first][0]:
            minnum = l[last][0] - l[first][0]
        if first == last:
            break
    first+=1
    last+=1
    if last>=lenl:
        break
    while dic[l[last][1]]!=0:
        dic[l[last][1]] += 1
        last=last+1
        if last >= lenl:
            break

    if last>=lenl:
        break
    dic[l[last][1]] += 1

    if minnum>l[last][0]-l[first][0]:
        minnum = l[last][0] - l[first][0]
    if minnum==0:
        break



print(minnum)