#include <bits/stdc++.h>
using namespace std;
int N, Q;
int niz[100010];
long long sum, q1;
long long cumSum[100010];
int main(void) {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) scanf("%d", &niz[i]);
  sort(niz, niz + N);
  for (int i = 0; i < N; ++i) {
    cumSum[i + 1] = (long long)niz[i] + cumSum[i];
    q1 += (long long)(N - i - 1) * niz[i];
  }
  scanf("%d", &Q);
  for (int i = 0; i < Q; ++i) {
    int q;
    scanf("%d", &q);
    if (q > N - 1) q = N - 1;
    if (q == 1) {
      printf("%I64d ", q1);
      continue;
    }
    long long _q = (long long)q, potq = q;
    long long sol = cumSum[N - 1];
    while ((long long)N - 1 - _q >= 0 && _q != 0) {
      sol += cumSum[N - 1 - _q];
      potq *= q;
      _q += potq;
    }
    printf("%I64d ", sol);
  }
  printf("\n");
  return 0;
}
