#include <bits/stdc++.h>
using namespace std;
long long dp[100005] = {};
long long sum[100005] = {};
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + a[i];
  int q;
  cin >> q;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < q; i++) {
    if (i) cout << " ";
    int k;
    cin >> k;
    if (dp[k] != -1) {
      cout << dp[k];
      continue;
    }
    long long l = 1, r = 1;
    long long ans = 0;
    long long step = k;
    for (int j = 0; l < n; j++) {
      r += step;
      step *= k;
      if (r > n) r = n;
      long long cur = sum[r] - sum[l];
      ans += cur * (j + 1);
      l = r;
    }
    dp[k] = ans;
    cout << ans;
  }
  cout << endl;
  return 0;
}
