import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static final TreeMap operations = new TreeMap<>(); static final Map> cloudStarts = new HashMap<>(); static final Map> cloudEnds = new HashMap<>(); static long maximumPeople(long[] population, long[] city, long[] cloud, long[] radius) { // Return the maximum number of people that will be in a sunny town after removing exactly one cloud. for (int i = 0; i < population.length; ++i) { final long pop = population[i]; final long cityX = city[i]; final long index = cityX * 3; final long currentValue = operations.getOrDefault(index, 0L); operations.put(index, currentValue + pop); } for (int i = 0; i < cloud.length; ++i) { final long cloudStart = cloud[i] - radius[i]; final long cloudEnd = cloud[i] + radius[i]; final long indexStart = cloudStart * 3 - 1; final long indexEnd = cloudEnd * 3 + 1; long currentValue = operations.getOrDefault(indexStart, 0L); operations.put(indexStart, currentValue + 1); currentValue = operations.getOrDefault(indexEnd, 0L); operations.put(indexEnd, currentValue + 1); cloudStarts.computeIfAbsent(indexStart, x -> new HashSet<>()).add(i); cloudEnds.computeIfAbsent(indexEnd, x -> new HashSet<>()).add(i); } long clearPopulation = 0; long bestOneCloudPopulation = 0; long cloudCount = 0; final Set clouds = new HashSet<>(); final Map oneCloudCover = new HashMap<>(); for (Map.Entry entry : operations.entrySet()) { final long index = entry.getKey(); final long value = entry.getValue(); final long operation = (index % 3 + 3) % 3; if (operation == 2) { // start cloud cloudCount += value; clouds.addAll(cloudStarts.get(index)); } else if (operation == 1) { // end cloud cloudCount -= value; clouds.removeAll(cloudEnds.get(index)); } else { // population if (cloudCount == 0) { clearPopulation += value; } else if (cloudCount == 1) { long cloudNumber = clouds.stream().findFirst().orElse(0); long currentValue = oneCloudCover.getOrDefault(cloudNumber, 0L); currentValue += value; oneCloudCover.put(cloudNumber, currentValue); bestOneCloudPopulation = Math.max(bestOneCloudPopulation, currentValue); } } } return clearPopulation + bestOneCloudPopulation; } public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); StringTokenizer st; // Scanner in = new Scanner(System.in); st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); st = new StringTokenizer(br.readLine()); long[] p = new long[n]; for(int p_i = 0; p_i < n; p_i++){ p[p_i] = Long.parseLong(st.nextToken()); } st = new StringTokenizer(br.readLine()); long[] x = new long[n]; for(int x_i = 0; x_i < n; x_i++){ x[x_i] = Long.parseLong(st.nextToken()); } st = new StringTokenizer(br.readLine()); int m = Integer.parseInt(st.nextToken()); st = new StringTokenizer(br.readLine()); long[] y = new long[m]; for(int y_i = 0; y_i < m; y_i++){ y[y_i] = Long.parseLong(st.nextToken()); } st = new StringTokenizer(br.readLine()); long[] r = new long[m]; for(int r_i = 0; r_i < m; r_i++){ r[r_i] = Long.parseLong(st.nextToken()); } long result = maximumPeople(p, x, y, r); System.out.println(result); //in.close(); } }