#include <bits/stdc++.h>   using namespace std;   bool isrange(int second, int first, int n, int m) {     if (0 <= second && second < n && 0 <= first && first < m) return true;     return false;   }   int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1},       ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1};   const int MAX = 101010;   long long int a[6], arr[MAX];   vector<pair<long long int, int> > v;   vector<int> tmp;   int num[MAX], start = 1;   long long int seg[MAX * 4];   multiset<long long int> s[MAX];   long long int getn(int l, int r) {     l += start;     r += start;     long long int ans = 0;     while (l <= r) {       if (l % 2) {         ans = max(ans, seg[l]);         l++;       }       if ((r % 2) == 0) {         ans = max(ans, seg[r]);         r--;       }       l /= 2;       r /= 2;     }     return ans;   }   void upd(int first, long long int second) {     first += start;     seg[first] = second;     for (int e = (first / 2); e >= 1; e /= 2)       seg[e] = max(seg[e * 2], seg[e * 2 + 1]);   }   void del(int first) {     long long int second = *s[first].begin();     s[first].erase(s[first].lower_bound(second));     second = *s[first].begin();     upd(first, second);   }   int main(void) {     while (start < MAX) start *= 2;     for (int e = 0; e < 6; e++) scanf( %lld , &a[e]);     int n;     scanf( %d , &n);     for (int e = 0; e < n; e++) {       long long int r;       scanf( %lld , &r);       for (int p = 0; p < 6; p++) {         v.push_back(make_pair(r - a[p], e));         s[e].insert(r - a[p]);       }     }     if (n == 1) return !printf( 0 );     for (int e = 0; e < n; e++) {       long long int first = *s[e].begin();       upd(e, first);     }     sort(v.begin(), v.end());     memset(num, 0, sizeof(num));     long long int ans = 1e18, lx = 0;     for (int e = 0; e < (int)v.size(); e++) {       if (lx != v[e].first) {         bool suc = false;         for (int p = 0; p < (int)tmp.size(); p++) {           num[tmp[p]]++;           if (num[tmp[p]] == 6) {             suc = true;             break;           }           del(tmp[p]);         }         if (suc) break;         tmp.clear();       }       long long int vv = 0;       if (0 <= v[e].second - 1) vv = max(vv, getn(0, v[e].second - 1));       if (v[e].second + 1 < n) vv = max(vv, getn(v[e].second + 1, n - 1));       ans = min(ans, vv - v[e].first);       tmp.push_back(v[e].second);       lx = v[e].first;     }     printf( %lld , ans);     return 0;   }   