import numpy as np if __name__ == "__main__": input() A = np.fromiter(map(int, input().split(" ")), dtype=np.int) input() X = list(map(int, input().split(" "))) min_X = X.pop(0) A %= min_X sum_A = A.sum() print(sum_A) for x in X: if min_X > x: A %= x min_X = x sum_A = A.sum() print(sum_A)