#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 100 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
int n, q;
long long arr[maxn];
long long sum[maxn];
long long ans[maxn];
vector<long long> que;
long long solve(long long k) {
  long long i = n - 1;
  long long z = 1;
  long long zi = 0;
  long long res = 0;
  while (i >= 0) {
    long long nxt = i - z;
    res += (sum[i] - (nxt >= 0 ? sum[nxt] : 0)) * zi;
    zi++;
    z *= k;
    i = nxt;
  }
  return res;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  sum[0] = arr[0];
  for (int i = 1; i < n; i++) sum[i] = arr[i] + sum[i - 1];
  cin >> q;
  for (int i = 0; i < maxn; i++) ans[i] = -1;
  que.resize(q);
  for (int i = 0; i < q; i++) {
    cin >> que[i];
    if (ans[que[i]] == -1) ans[que[i]] = solve(que[i]);
  }
  for (int i = 0; i < q; i++) cout << ans[que[i]] << " ";
  cout << endl;
  return 0;
}
