#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, n, q, x, k, t, s[100005] = {0}, d[100005] = {0};
  cin >> n;
  long long int a[n];
  a[0] = 0;
  for (i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  s[1] = a[1];
  for (i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
  cin >> q;
  j = 0;
  while (j < q) {
    i = n - 1;
    cin >> k;
    x = k;
    if (d[k] == 0) {
      t = 0;
      while (i >= 1) {
        t += s[i];
        i -= x;
        x = x * k;
      }
      d[k] = t;
    }
    cout << d[k] << " ";
    j++;
  }
  return 0;
}
