#include <bits/stdc++.h>
using namespace std;
long long n, q, k;
long long ara[1000000 + 10];
bool cmp(long long a, long long b) { return a > b; }
int main() {
  scanf("%I64d", &n);
  for (long long i = 0; i < n; i++) scanf("%I64d", &ara[i]);
  sort(ara, ara + n, cmp);
  ara[0] = 0;
  long long xtra = 0;
  for (long long i = 1; i < n; i++) {
    xtra += ara[i] * i;
    ara[i] += ara[i - 1];
  }
  scanf("%I64d", &q);
  while (q--) {
    scanf("%I64d", &k);
    if (k == 1) {
      if (q)
        printf("%I64d ", xtra);
      else
        printf("%I64d\n", xtra);
      continue;
    }
    k = min(n - 1, k);
    long long lft = 0, rgt = min(k, n - 1), mul = 1;
    long long dif = k;
    long long ans = 0;
    while (lft < n - 1) {
      ans += (ara[rgt] - ara[lft]) * mul;
      mul++;
      lft = rgt;
      dif *= k;
      rgt += dif;
      rgt = min(rgt, n - 1);
    }
    if (q)
      printf("%I64d ", ans);
    else
      printf("%I64d\n", ans);
  }
  return 0;
}
