def main(): import sys from heapq import heappush, heappop, heapify input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) Q = int(input()) X = list(map(int, input().split())) for i in range(N): A[i] *= -1 heapify(A) ans = -sum(A) for x in X: tmp = [] #print(x, A) while A: a = -heappop(A) #print(x, a) if a >= x: ans -= a - a%x a = a%x tmp.append(a) else: heappush(A, -a) break for a in tmp: heappush(A, -a) print(ans) if __name__ == '__main__': main()