#include <bits/stdc++.h>
using namespace std;
const int INF = numeric_limits<int>::max();
const int MAXN = 100100;
int a[MAXN];
long long pref[MAXN];
inline long long getSum(int l, int r) {
  long long res = pref[r];
  if (l > 0) {
    res -= pref[l - 1];
  }
  return res;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  --n;
  reverse(a, a + n);
  long long cur = 0;
  long long one_ans = 0;
  int p = 1;
  for (int i = 0; i < n; ++i) {
    one_ans += 1LL * p * a[i];
    ++p;
    cur += a[i];
    pref[i] = cur;
  }
  fprintf(stderr, "Init ok\n");
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int k;
    scanf("%d", &k);
    if (k == 1) {
      cout << one_ans << ' ';
      continue;
    }
    long long ans = 0;
    int p = 1;
    long long len = k;
    int l = 0;
    while (true) {
      if (len > n) {
        len = n;
      }
      if (l >= n) {
        break;
      }
      ans += p * getSum(l, min(n - 1, l + (int)len - 1));
      if (l + len >= n) {
        break;
      }
      l += len;
      len *= k;
      ++p;
    }
    cout << ans << ' ';
  }
  cout << endl;
  return 0;
}
