#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long a[maxn], s[maxn];
long long n;
long long sum(long long l, long long r) {
  r = min(r, n - 1);
  return s[r] - s[l - 1];
}
int main() {
  scanf("%I64d", &n);
  for (int i = 0; i < n; ++i) scanf("%I64d", &a[i]);
  sort(a, a + n);
  reverse(a, a + n);
  s[0] = a[0];
  for (int i = 1; i < n; ++i) s[i] = a[i] + s[i - 1];
  int q;
  scanf("%d", &q);
  long long ans1 = 0;
  for (int i = 1; i < n; ++i) ans1 += a[i] * i;
  while (q--) {
    int k;
    scanf("%d", &k);
    if (k == 1) {
      printf("%I64d ", ans1);
      continue;
    }
    long long ans = 0;
    long long sz = 1;
    for (long long i = 1, j = 1; j < n; ++i, j += sz) {
      sz *= k;
      ans += sum(j, j + sz - 1) * i;
    }
    printf("%I64d ", ans);
  }
  printf("\n");
  return 0;
}
