#include <bits/stdc++.h>
using namespace std;
pair<long long int, long long int> pll;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const long long int Inf = 1LL << 62;
long long int ar[Max];
long long int ans[Max];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, q, k;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
  }
  sort(ar + 1, ar + n + 1);
  for (int i = 1; i <= n; i++) {
    ar[i] += ar[i - 1];
  }
  for (long long int i = 1; i <= n; i++) {
    long long int cnt = 1;
    long long int cur = i;
    for (long long int j = n - 1; j >= 1;) {
      ans[i] += (ar[j] - ar[max(0LL, (long long int)(j - cur))]) * cnt;
      cnt++;
      j -= cur;
      cur *= i;
    }
  }
  cin >> q;
  while (q--) {
    cin >> k;
    if (k > n) {
      k = n;
    }
    cout << ans[k] << " ";
  }
  return 0;
}
