from heapq import heappop, heappush N = int(input()) A = list(map(int, input().split())) Q = int(input()) X = list(map(int, input().split())) hq = [] sm = 0 for i in range(N): heappush(hq,-A[i]) sm += A[i] for x in X: while 1: v = -heappop(hq) if v>=x: sm -= v sm += v%x heappush(hq,-(v%x)) else: heappush(hq,-v) break print(sm)