#include <bits/stdc++.h>
using namespace std;
long long all[100005];
long long sm[100005];
long long pre[100005];
int N;
int main() {
  cin >> N;
  for (int i = 0; i < (N); i++) cin >> all[i];
  sort(all, all + N);
  sm[0] = all[0];
  for (int i = 1; i < N; i++) {
    sm[i] = sm[i - 1] + all[i];
  }
  for (int k = 1; k < N; k++) {
    pre[k] = 0;
    long long cnt = 1;
    long long indx = N - 2;
    long long ln = 1;
    while (indx >= 0) {
      ln *= k;
      if (indx - ln >= 0) {
        pre[k] += (sm[indx] - sm[indx - ln]) * cnt;
      } else
        pre[k] += (sm[indx]) * cnt;
      indx -= ln;
      cnt++;
    }
  }
  int Q, K;
  cin >> Q;
  while (Q--) {
    cin >> K;
    if (K >= N) {
      if (N - 2 >= 0)
        cout << sm[N - 2] << " ";
      else
        cout << 0 << " ";
    } else
      cout << pre[K] << " ";
  }
  cout << endl;
  return 0;
}
