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