## https://yukicoder.me/problems/no/1552 import heapq def main(): N = int(input()) A = list(map(int, input().split())) Q = int(input()) X = list(map(int, input().split())) answer = sum(A) queue = [] for a in A: heapq.heappush(queue, -a) for x in X: while len(queue) > 0 and queue[0] <= -x: a = heapq.heappop(queue) a = -a answer -=a b = a % x heapq.heappush(queue, -b) answer += b print(answer) if __name__ == "__main__": main()