#include <bits/stdc++.h>
using namespace std;
const int N = 101000;
int a[N];
long long int s[N];
int n, q;
map<int, long long int> mem;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  sort(a, a + n);
  s[0] = 0;
  for (int i = 1; i < n; ++i) s[i] = s[i - 1] + a[n - i - 1];
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int k;
    scanf("%d", &k);
    if (mem.find(k) != mem.end()) {
      printf("%I64d ", mem[k]);
      continue;
    }
    long long int res = 0;
    long long int l = 0, r = 0;
    int mul = 0;
    long long int p = 1;
    while (r < n - 1) {
      p *= k;
      l = r;
      r = l + p;
      if (r > n - 1) r = n - 1;
      res += ++mul * (s[r] - s[l]);
    }
    printf("%I64d ", res);
    mem[k] = res;
  }
  printf("\n");
  return 0;
}
