#include #include #include #include #include #include using namespace std; #define ran(i, a, b) for ((i) = (a); (i) < (b); (i)++) #define rep(i, a) ran ((i), 0, (a)) #define rep1(i, a) ran ((i), 1, (a)+1) using ll = long long; using vi = vector; using ii = pair; #if defined(SHIROKO1_LOCAL) && !defined(NDEBUG) template static void DEBUG(T&& s) { cerr << s << endl; } template static void DEBUG(T&& a, Ts&&... as) { cerr << a << ' '; DEBUG(as...); } #else #define DEBUG(...) ((void)0) #endif int main() { ll n; cin >> n; static ii Ts[200100]; ll i; rep (i, n) cin >> Ts[i].second; rep (i, n) cin >> Ts[i].first; ll m; cin >> m; static ll y[200100]; static ii Add[200100]; static ii Rm[200100]; rep (i, m) cin >> y[i]; rep (i, m) { ll r; cin >> r; Add[i] = { y[i] - r, i }; Rm[i] = { y[i] + r+1, i }; } sort(Ts, Ts+n); { ll l, r; l = 0; ran (r, 1, n) { if (Ts[l].first == Ts[r].first) { Ts[l].second += Ts[r].second; } else { Ts[++l] = Ts[r]; } } n = l+1; } ll anyway = 0; static ll profit[200100]; sort(Add, Add+m); sort(Rm, Rm+m); unordered_set S; ll ti = 0, ai = 0, ri = 0; for (;;) { ll tx = ti < n ? Ts[ti].first : 1LL<<60; ll ax = ai < m ? Add[ai].first : 1LL<<60; ll rx = ri < m ? Rm[ri].first : 1LL<<60; ll mi = min(tx, min(ax, rx)); if (mi == 1LL<<60) break; if (ax == mi) { S.insert(Add[ai].second); ai++; } else if (rx == mi) { S.erase(Rm[ri].second); ri++; } else if (tx == mi) { ll n = S.size(); if (n == 0) anyway += Ts[ti].second; else if (n == 1) profit[*S.begin()] += Ts[ti].second; ti++; } } ll ans = 0; rep (i, m) ans = max(ans, profit[i]); cout << (ans + anyway) << endl; return 0; }