#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
long long a[maxn], sum[maxn], ans[maxn];
long long n;
inline long long solve(const long long &k) {
  long long ret = 0, pk = k;
  for (long long i = n - 1; i >= 1; i -= pk, pk *= k) ret += sum[i];
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
  int q;
  cin >> q;
  memset(ans, -1, sizeof ans);
  while (q--) {
    int k;
    cin >> k;
    if (k >= n - 1)
      cout << sum[n - 1] << " ";
    else {
      if (ans[k] == -1)
        cout << (ans[k] = solve(k)) << " ";
      else
        cout << ans[k] << " ";
    }
  }
  return 0;
}
