from heapq import heappop,heappush n = int(input()) A = list(map(int,input().split())) q = int(input()) X = list(map(int,input().split())) ans = sum(A) dic = {} for a in A: dic[a] = dic.get(a,0)+1 h = [] for key in dic.keys(): heappush(h,-key) for x in X: while -h[0] >= x: key = -heappop(h) num = dic[key] ans -= key*num nkey = key%x ans += nkey*num if nkey in dic: dic[nkey] += num else: dic[nkey] = num heappush(h,-nkey) print(ans)