#!/bin/python3 import sys def maximumPeople(p, x, y, r): # Return the maximum number of people that will be in a sunny town after removing exactly one cloud. cloudy ={} partlyCity ={} sunnyCity ={} townpop ={} sunnyPop=0 clearcloud=[] maxPos = max(max(x),max(y)+max(r)) for i in range(maxPos+1): cloudy[i]=0 partlyCity[i] = 0 for j in range(len(y)): cloud = y[j] c_range =r[j] for i in range(cloud-c_range, cloud+c_range+1): cloudy[i] +=1 for i in range(len(x)): townpop[x[i]] = p[i] if cloudy[x[i]] ==1: partlyCity[x[i]] =1 elif cloudy[x[i]] ==0: sunnyPop+=p[i] for j in range(len(y)): cloud = y[j] c_range =r[j] for i in range(cloud-c_range, cloud+c_range+1): cloudcoverpop = 0 if partlyCity[i]: cloudcoverpop += townpop[i] clearcloud.append(cloudcoverpop) return sunnyPop+max(clearcloud) if __name__ == "__main__": n = int(input().strip()) p = list(map(int, input().strip().split(' '))) #population x = list(map(int, input().strip().split(' '))) #town position m = int(input().strip()) #number of clouds y = list(map(int, input().strip().split(' '))) #position of clouds r = list(map(int, input().strip().split(' '))) #range of clouds result = maximumPeople(p, x, y, r) print(result)