#include<iostream> #include<cstdio> #include<vector> #include<queue> #include<stack> #include<cstring> #include<algorithm> #include<cctype> #include<cstdlib> #define maxn 100010 #define ll long long #define pb push_back #define cn const node #define cQ const Queue #define gc getchar #define INF 1000000000 usingnamespacestd; intread(){ int x = 0; char c = gc(); while (!isdigit(c)) c = gc(); while (isdigit(c)) x = x * 10 + c - '0', c = gc(); return x; } int n, a[7], b[maxn], c[maxn * 6], c1; int Ans = INF; intmain(){ for (int i = 1; i <= 6; ++i) cin >> a[i]; sort(a + 1, a + 7); cin >> n; for (int i = 1; i <= n; ++i) cin >> b[i]; sort(b + 1, b + n + 1); for (int i = 1; i <= n; ++i) for (int j = 1; j <= 6; ++j) c[++c1] = b[i] - a[j]; for (int i = 1; i <= c1; ++i) { int mx = 0, p = 1; if (c[i] > b[1] - a[1]) continue; for (int j = 2; j <= 6; ++j) { int l = p + 1, r = n, mid, ans = n + 1; while (l <= r) { mid = l + r >> 1; if (b[mid] - a[j] >= c[i]) ans = mid, r = mid - 1; else l = mid + 1; } mx = max(b[ans - 1] - a[j - 1], mx); } mx = max(mx, b[n] - a[6]); Ans = min(Ans, mx - c[i]); } cout << Ans << endl; return0; }