#include <bits/stdc++.h>
using namespace std;
long long a[110000], n, sum[110000];
long long solve(long long k) {
  long long now = n - 1, temp = 0, kk = k;
  while (1) {
    temp = temp + sum[now];
    if (now <= kk) break;
    now -= kk;
    kk = kk * k;
  }
  return temp;
}
int main() {
  long long k, i, q, ans;
  scanf("%I64d", &n);
  for (i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  sort(a + 1, a + 1 + n);
  sum[0] = 0;
  for (i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
  scanf("%I64d", &q);
  long long spec = 0;
  for (i = 1; i < n; i++) spec = spec + sum[i];
  for (i = 1; i <= q; i++) {
    scanf("%I64d", &k);
    if (k == 1) {
      printf("%I64d ", spec);
      continue;
    }
    ans = solve(k);
    printf("%I64d ", ans);
  }
  puts("");
  return 0;
}
