n = gets.to_i; towns_population = gets.split.map &:to_i; towns_pos = gets.split.map &:to_i; m = gets.to_i; cloud_pos = gets.split.map &:to_i; cloud_range = gets.split.map &:to_i; town_clouds = towns_pos.map{|j| cloud_pos.each_with_index.count{|c,i| r = cloud_range[i] ; (c-i..c+i) === j}} cloud_numfree = cloud_pos.map.with_index{|c,j| towns_pos.each_with_index.inject(0){|m,(v,i)| r = cloud_range[j] ; (c-r..c+r)===v && town_clouds[i]==1 ? m+towns_population[i] : m}} total_free = 0 town_clouds.each_with_index{|count,i| if count == 0 total_free += towns_population[i]; end } puts total_free + cloud_numfree.max