#include <bits/stdc++.h>
using namespace std;
long long nums[100001], sums[100001];
int N, Q, K;
long long get(long long v, long long u) {
  if (u >= N) return sums[N - 1] - sums[v - 1];
  return sums[u] - sums[v - 1];
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) cin >> nums[i];
  sort(nums + 0, nums + N);
  for (int i = 0; i < N / 2; i++) swap(nums[i], nums[N - i - 1]);
  sums[0] = nums[0];
  for (int i = 1; i < N; i++) {
    sums[i] = sums[i - 1] + nums[i];
  }
  long long s = 0;
  for (int i = N - 1; i >= 1; i--) {
    s += nums[i] * i;
  }
  scanf("%d", &Q);
  vector<int> ks;
  while (Q--) {
    scanf("%d", &K);
    ks.push_back(K);
  }
  for (int i = 0; i < ks.size(); i++) {
    K = ks[i];
    if (K == 1) {
      cout << s << " ";
      continue;
    }
    long long idx = 1;
    long long len = 1;
    long long ans = 0;
    int times = 1;
    while (true) {
      if (idx >= N) break;
      len = len * K;
      ans += get(idx, idx + len - 1) * times;
      times++;
      idx = idx + len;
    }
    cout << ans << " ";
  }
  return 0;
}
