import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static class Point { long x; long population; long id; boolean isCity; boolean isBegin; public Point(long x, long population, long id) { this.x = x; this.population = population; this.isCity = true; this.id = id; } public Point(long x, boolean isBegin, long id) { this.x = x; this.isBegin = isBegin; isCity = false; this.id = id; } } public static class Points { List cloudBegin; List cloudEnd; List cities; public Points() { cloudBegin = new ArrayList<>(); cloudEnd = new ArrayList<>(); cities = new ArrayList<>(); } } static long maximumPeople(long[] p, long[] x, long[] y, long[] r) { List points = new ArrayList<>(); long idg = 0; for(int i = 0; i < p.length; i++) { points.add(new Point(x[i], p[i], idg++)); } for(int i = 0; i < y.length; i++) { points.add(new Point(y[i] - r[i], true, idg)); points.add(new Point(y[i] + r[i], false, idg++)); } TreeMap map = new TreeMap<>(); for(Point pp : points) { if(!map.containsKey(pp.x)) map.put(pp.x, new Points()); Points col = map.get(pp.x); if(pp.isCity) col.cities.add(pp.population); else { if(pp.isBegin) col.cloudBegin.add(pp.id); else col.cloudEnd.add(pp.id); } } long total = 0; Map removedBest = new HashMap<>(); Set activeClouds = new HashSet<>(); for(Long key : map.keySet()) { Points pp = map.get(key); for(Long cl : pp.cloudBegin) { activeClouds.add(cl); } for(Long p1 : pp.cities) { if(activeClouds.size() == 1) { Long id = null; for(Long lll : activeClouds) { id = lll; } if(!removedBest.containsKey(id)) removedBest.put(id, p1); else removedBest.put(id, removedBest.get(id) + p1); } else if(activeClouds.isEmpty()) total += p1; } for(Long cl : pp.cloudEnd) { activeClouds.remove(cl); } } long best = 0; for(Long l : removedBest.keySet()) { best = Math.max(best, removedBest.get(l)); } return total + best; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); long[] p = new long[n]; for(int p_i = 0; p_i < n; p_i++){ p[p_i] = in.nextLong(); } long[] x = new long[n]; for(int x_i = 0; x_i < n; x_i++){ x[x_i] = in.nextLong(); } int m = in.nextInt(); long[] y = new long[m]; for(int y_i = 0; y_i < m; y_i++){ y[y_i] = in.nextLong(); } long[] r = new long[m]; for(int r_i = 0; r_i < m; r_i++){ r[r_i] = in.nextLong(); } long result = maximumPeople(p, x, y, r); System.out.println(result); in.close(); } }