import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.PriorityQueue; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] sa = br.readLine().split(" "); PriorityQueue que = new PriorityQueue<>((o1, o2) -> o2 - o1); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); que.add(a[i]); } int q = Integer.parseInt(br.readLine()); sa = br.readLine().split(" "); int[] x = new int[q]; for (int i = 0; i < q; i++) { x[i] = Integer.parseInt(sa[i]); } br.close(); long sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; } PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < q; i++) { while (que.peek() >= x[i]) { int cur = que.poll(); int next = cur % x[i]; que.add(next); sum -= cur - next; } pw.println(sum); } pw.flush(); } }