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