import sys from collections import defaultdict def main(): input = sys.stdin.read().split() idx = 0 N, M = int(input[idx]), int(input[idx+1]) idx += 2 P = list(map(int, input[idx:idx+N])) idx += N cups = [] for _ in range(N): a, b = int(input[idx]), int(input[idx+1]) cups.append((a, b)) idx += 2 balls = [] for _ in range(M): c, d = int(input[idx]), int(input[idx+1]) balls.append((c, d)) idx += 2 sign_pairs = [(1, 1), (1, -1), (-1, 1), (-1, -1)] max_total = 0 for s_x, s_y in sign_pairs: delta_sum = defaultdict(int) for (cj, dj) in balls: for i in range(N): ai, bi = cups[i] dx = cj - s_x * ai dy = dj - s_y * bi delta_sum[(dx, dy)] += P[i] current_max = max(delta_sum.values(), default=0) if current_max > max_total: max_total = current_max print(max_total) if __name__ == "__main__": main()