#include <bits/stdc++.h>
const int INF = 1000 * 1000 * 1000;
using namespace std;
int n;
long long pref[100005];
long long ans[100005];
int a[100005];
long long sum(int l, long long r) {
  r = min((long long)n, r);
  return pref[r] - pref[l - 1];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) pref[i] = a[i] + pref[i - 1];
  for (int k = 1; k <= 100000; k++) {
    long long sz = 1;
    int coef = 0;
    long long prev = 0;
    while (prev < n) {
      ans[k] += coef * sum(prev + 1, prev + sz);
      prev += sz;
      coef++;
      sz *= k;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int k;
    cin >> k;
    cout << ans[k] << " ";
  }
}
