import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long sum = 0; TreeMap remain = new TreeMap<>(); for (int i = 0; i < n; i++) { int x = - sc.nextInt(); if (remain.containsKey(x)) { remain.put(x, remain.get(x) + 1); } else { remain.put(x, 1); } sum -= x; } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int y = sc.nextInt(); while (- remain.firstKey() >= y) { Map.Entry entry = remain.pollFirstEntry(); int x = - entry.getKey(); sum -= (long)x * entry.getValue(); int mod = x % y; if (remain.containsKey(-mod)) { remain.put(-mod, remain.get(-mod) + entry.getValue()); } else { remain.put(-mod, entry.getValue()); } sum += (long)mod * entry.getValue(); } sb.append(sum).append("\n"); } System.out.print(sb); } }