import heapq n = int(input()) a = list(map(int, input().split())) q = int(input()) x = list(map(int, input().split())) ans = 0 hp = [] for i in range(n): ans += a[i] heapq.heappush(hp, - a[i]) for i in range(q): while True: cur = heapq.heappop(hp) if - cur < x[i]: heapq.heappush(hp, cur) break else: ans -= (- cur) nxt = - ((- cur) % x[i]) ans += (- nxt) heapq.heappush(hp, nxt) print(ans)