import java.util.*; public class Solution { static long maximumPeople(long[] p, long[] x, long[] y, long[] r, int m, int n) { Map<Long, Long> map = new HashMap<Long, Long>(); for(int i = 0; i < m; i++){ long range = r[i]; for(int j = 0; j <= range; j++){ long index = j + y[i]; if(map.containsKey(index)){ map.put(index, map.get(index) + 1L); } else { map.put(index, 1L); } } for(int j = 1; j <= range; j++){ long index = y[i] - 1; if(map.containsKey(index)){ map.put(index, map.get(index) + 1L); } else { map.put(index, 1L); } } } long sunnyCount = 0; long maxCount = 0; for(int i = 0; i < n; i++){ if(!map.containsKey(x[i])) { sunnyCount += p[i]; } else { if(map.get(x[i]) == 1 && p[i] > maxCount){ maxCount = p[i]; } } } //System.out.println("Sunnycount: " + sunnyCount); //System.out.println("MaxCount: " + maxCount); return sunnyCount + maxCount; } 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, m, n); System.out.println(result); in.close(); } }