#include <bits/stdc++.h>
using namespace std;
stringstream ss;
long long dp[100010], a[100010], sum[100010];
int main() {
  long long n, m, q, k;
  cin >> n;
  for (long long i = 1LL; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (long long i = 1LL; i <= n; i++) sum[i] = sum[i - 1] + a[i];
  for (long long k = 1LL; k <= n; k++) {
    long long t = k;
    for (long long r = n - 1, l = max(0LL, n - t - 1), cc = 1; r;
         r = l, l = max(0LL, l - t), cc++) {
      dp[k] += (sum[r] - sum[l]) * cc;
      t *= k;
    }
  }
  for (long long k = n + 1; k < 100010LL; k++) dp[k] = dp[k - 1];
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> k;
    cout << (i ? " " : "") << dp[k];
  }
  cout << endl;
  return 0;
}
