#include <bits/stdc++.h>
const int MAXN = 1e5 + 15;
using namespace std;
long long A[MAXN], S[MAXN], val[MAXN];
void solve() {
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> A[i];
  sort(A, A + n);
  reverse(A, A + n);
  for (int i = 1; i <= n - 1; i++) {
    S[i] = S[i - 1] + A[i];
  }
  for (int k = 1; k <= n - 1; k++) {
    long long t = 1, in = 1;
    for (long long p = 1; p <= n - 1; p += in) {
      in *= k;
      val[k] += t * (S[min(n - 1, p + in - 1)] - S[p - 1]);
      t++;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int x;
    cin >> x;
    if (x >= n - 1) {
      cout << S[n - 1];
    } else
      cout << val[x];
    cout << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cout << fixed << setprecision(12);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
    cout << "\n";
  }
  return 0;
}
