import heapq N = int(input()) A = list(map(lambda x: -int(x), input().split())) Q = int(input()) X = list(map(int, input().split())) heapq.heapify(A) ans = -sum(A) for x in X: while x <= -A[0]: a = -heapq.heappop(A) ans -= a heapq.heappush(A, -(a % x)) ans += a % x print(ans)