import java.io.*; import java.util.*; public class Hourrank26 { static class Event implements Comparable { int idx; int x; int delta; int pop; public Event(int idx, int x, int delta, int pop) { this.idx = idx; this.x = x; this.delta = delta; this.pop = pop; } @Override public int compareTo(Event o) { if (x != o.x) { return x < o.x ? -1 : 1; } return -Integer.compare(delta, o.delta); } } void submit() { int n = nextInt(); int[] pop = new int[n]; int[] coord = new int[n]; for (int i = 0; i < n; i++) { pop[i] = nextInt(); } for (int i = 0; i < n; i++) { coord[i] = nextInt(); } int m = nextInt(); int[][] qwe = new int[2][m]; for (int i = 0; i < 2; i++) { for (int j = 0; j < m; j++) { qwe[i][j] = nextInt(); } } Event[] es = new Event[n + 2 * m]; for (int i = 0; i < m; i++) { es[2 * i] = new Event(i, qwe[0][i] - qwe[1][i], 1, 0); es[2 * i + 1] = new Event(i, qwe[0][i] + qwe[1][i], -1, 0); } for (int i = 0; i < n; i++) { es[2 * m + i] = new Event(i, coord[i], 0, pop[i]); } Arrays.sort(es); TreeSet all = new TreeSet<>(); long ans = 0; long[] aans = new long[m]; for (Event e : es) { if (e.delta == 1) { all.add(e.idx); } else if (e.delta == -1) { all.remove(e.idx); } else { if (all.isEmpty()) { ans += e.pop; } else if (all.size() == 1) { aans[all.iterator().next()] += e.pop; } } } out.println(ans + Arrays.stream(aans).max().getAsLong()); } void preCalc() { } void stress() { } void test() { } Hourrank26() throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); preCalc(); submit(); // stress(); // test(); out.close(); } static final Random rng = new Random(); static int rand(int l, int r) { return l + rng.nextInt(r - l + 1); } public static void main(String[] args) throws IOException { new Hourrank26(); } BufferedReader br; PrintWriter out; StringTokenizer st; String nextToken() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } String nextString() { try { return br.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } }