#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  long long n;
  cin >> n;
  if (n < 1 || n > 100000) {
    cout << 0;
    return 0;
  }
  vector<long long> piles(n);
  vector<long long> cost(n);
  for (long long i = 0; i < n; i++) {
    cin >> piles[i];
  }
  sort(piles.begin(), piles.end());
  long long total = 0;
  cost[0] = 0;
  for (long long i = 0; i < n - 1; i++) {
    cost[i + 1] = piles[i] + cost[i];
    total += cost[i + 1];
  }
  long long q;
  cin >> q;
  if (q < 1 || q > 100000) {
    cout << 0;
    return 0;
  }
  map<long long, long long> caches_solutions;
  for (long long i = 0; i < q; i++) {
    long long query;
    cin >> query;
    if (caches_solutions.find(query) != caches_solutions.end()) {
      cout << caches_solutions.at(query) << " ";
      continue;
    }
    long long ans = 0;
    long long step = 1;
    for (long long j = n - 1; j > 0; j -= step) {
      ans += cost[j];
      step = step * query;
    }
    caches_solutions[query] = ans;
    cout << ans << " ";
  }
  cout << endl;
  return 0;
}
