#include <bits/stdc++.h>
const int MOD = 1E9 + 7;
const int N = 500000 + 5;
const int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1};
const int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
using namespace std;
long long a[N];
long long ans[N], sum[N];
long long bucket[N];
int main() {
  long long n;
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
  int q;
  scanf("%d", &q);
  int sizee = q;
  int kase = 0;
  bool flag = true;
  while (q--) {
    if (n == 1) {
      flag = false;
      printf("0 ");
    } else {
      kase++;
      int k;
      scanf("%d", &k);
      if (k > n) k = n;
      if (bucket[k] != 0) {
        ans[kase] = bucket[k];
        continue;
      }
      long long l, r = n - 1;
      long long temp = 1;
      long long cha = 0;
      for (long long i = 1;; i++) {
        temp *= k;
        cha += temp;
        l = max(n - cha, (long long)1);
        ans[kase] += (sum[r] - sum[l - 1]) * i;
        r = l - 1;
        if (l == 1) break;
      }
      bucket[k] = ans[kase];
    }
  }
  if (flag) {
    for (int i = 1; i <= sizee; i++) printf("%lld ", ans[i]);
    printf("\n");
  }
  return 0;
}
