from heapq import * n = int(input()) *a, = map(int,input().split()) for i in range(n): a[i] *= -1 heapify(a) ans = -sum(a) Q = int(input()) *x, = map(int,input().split()) for xi in x: while xi <= -a[0]: v = -heappop(a) ans -= v v %= xi ans += v heappush(a,-v) print(ans)