#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<deque>
#include<functional>
#include<ctime>
#include<cassert>
#include<cstring>
using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define fdj(a,b) for(int j=a-1;j>=b;--j)
#define fdo(a,b) for(int o=a-1;o>=b;--o)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double ld;
typedef vector<int> vi;

template<class T> bool uin(T &a, T b){ return (a > b ? a = b, true : false); }
template<class T> bool uax(T &a, T b){ return (a < b ? a = b, true : false); }

/////////////////////////////////

int const N = 1e6 + 41;
ll ans;
int n, m;
int p[N], x[N];
int y[N], R[N];
int l[N], r[N];

map<int, int> h;
vi a;

void hashall(){
	fi(0, n) a.pb(x[i]);
	fi(0, m){
		a.pb(y[i]-R[i]);
		a.pb(y[i]-R[i] - 1);
		a.pb(y[i]+R[i]);
		a.pb(y[i]+R[i]+1);
	}
	sort(a.begin(), a.end());
	fi(0, sz(a)){
		if(h.find(a[i]) == h.end()){
			int v = sz(h);
			h[a[i]] = v;
		}
	}
	fi(0, n) x[i] = h[x[i]];
	fi(0, m) l[i] = h[y[i]-R[i]], r[i] = h[y[i]+R[i]];
	//for(pii x : h) cerr << x.first << " " << x.second << endl;
}

int b[N];
ll s[N], s0, s1[N];

void solve(){
	hashall();	
	fi(0, n){
//		cerr << i << " " << x[i] << endl;
	}
	fi(0, m){
	//	cerr << i << " " << l[i] << " " << r[i] << endl;
	}
	fi(0, n) s[x[i]] += p[i]; 
	fi(0, m){
		b[l[i]] += 1;
		b[r[i]+1] -= 1;
	}
	int c = 0;
	fi(0, sz(a)){
//		cerr << i << " " << "c[i] = " << c << endl;
		c += b[i];
		if(c == 0){
			s0 += s[i];
		}		
		if(i) s1[i] += s1[i-1];
		if(c == 1){
			s1[i] += s[i];
		}
	}
	ll mx = 0;
	fi(0, m){
		int l0 = l[i];
		int r0 = r[i];
		ll v = s1[r0];
		if(l0) v -= s1[l0-1];
		mx = max(mx, v);
	}
	ans = s0 + mx;

}

int main(){
#ifdef LOCAL_DEFINE
	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
#endif

	scanf("%d",&n);
	fi(0, n) scanf("%d",&p[i]);	
	fi(0, n) scanf("%d",&x[i]);
	scanf("%d",&m);
	fi(0, m) scanf("%d",&y[i]);
	fi(0, m) scanf("%d",&R[i]);

	solve();		
	printf("%lld\n",ans);
	
#ifdef LOCAL_DEFINE
	fprintf(stderr, "ELAPSED TIME: %.3lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}