#include <bits/stdc++.h>
using namespace std;
unsigned long long arr[200000], cum[200000];
unsigned long long forone;
unsigned long long n;
unsigned long long make(unsigned long long st, unsigned long long mult,
                        unsigned long long lim, unsigned long long level) {
  if (st > n) return 0;
  unsigned long long end = min(n, st + lim - 1);
  return make(end + 1, mult, lim * mult, level + 1) +
         (cum[end] - cum[st - 1]) * level;
}
bool comp(int p, int q) { return p > q; }
int main() {
  while (cin >> n) {
    unsigned long long i;
    for (i = 1; i <= n; i++) cin >> arr[i];
    sort(&arr[1], &arr[n + 1], comp);
    cum[0] = 0;
    forone = 0;
    for (i = 1; i <= n; i++) {
      forone += (i - 1) * arr[i];
      cum[i] = cum[i - 1] + arr[i];
    }
    unsigned long long q;
    cin >> q;
    unsigned long long tem;
    for (i = 1; i <= q; i++) {
      cin >> tem;
      if (tem == 1) {
        cout << forone;
        if (i != q) cout << " ";
        continue;
      }
      cout << make(2, tem, tem, 1);
      if (i != q) cout << " ";
    }
    printf("\n");
  }
  return 0;
}
