#include <bits/stdc++.h>
using namespace std;
const int K_MAX = 100000;
int main() {
  std::ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int Q;
  cin >> Q;
  sort(A, A + N, greater<int>());
  long long sum[N + 1];
  sum[0] = 0;
  for (int i = 1; i <= N; i++) {
    sum[i] = sum[i - 1] + A[i - 1];
  }
  long long ans[K_MAX + 1];
  fill_n(ans, K_MAX + 1, 0);
  for (int q = 0; q < Q; q++) {
    int K;
    cin >> K;
    if (ans[K] == 0) {
      int idx = 0;
      long long cnt = 0;
      int p = 0;
      long long len = 1;
      while (idx < N) {
        int pos = (int)min(N * 1LL, idx + len);
        cnt += (sum[pos] - sum[idx]) * p;
        idx = pos;
        p++;
        len *= K;
      }
      ans[K] = cnt;
    }
    cout << ans[K] << " ";
  }
  cout << endl;
  return 0;
}
