#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
long long arr[N], ans[N], sum[N];
int main() {
  long long m, n, k, p, cnt = 0;
  while (cin >> n) {
    memset(sum, 0, sizeof(sum));
    for (int i = 1; i <= n; i++) {
      cin >> arr[i];
    }
    sort(arr + 1, arr + 1 + n);
    for (int i = 1; i <= n; i++) {
      sum[i] = sum[i - 1] + arr[i];
    }
    for (int i = 1; i < n; i++) {
      p = n;
      k = 1;
      cnt = 0;
      while (p >= 1) {
        ans[i] +=
            (long long)cnt * (long long)(sum[p] - sum[(int)max(0LL, p - k)]);
        p -= k;
        k *= i;
        cnt++;
      }
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
      cin >> k;
      k = min(k, n - 1);
      cout << ans[k] << " ";
    }
    cout << endl;
  }
  return 0;
}
