#include <bits/stdc++.h>
using namespace std;
long long a[111111];
inline long long csum(int x) {
  if (x < 0) return 0;
  return a[x];
}
inline long long csum(int x, int y) { return csum(y) - csum(x - 1); }
int main() {
  int n, q;
  scanf("%d", &n);
  for (int i = (0); i <= ((n)-1); i++) {
    int x;
    scanf("%d", &x);
    a[i] = x;
  }
  scanf("%d", &q);
  vector<int> queries(q), p;
  map<int, long long> ans;
  for (int i = (0); i <= ((q)-1); i++) scanf("%d", &queries[i]);
  p = queries;
  sort((p).begin(), (p).end());
  sort((p).begin(), (p).end()), p.erase(unique(p.begin(), p.end()), p.end());
  sort(a, a + n);
  reverse(a, a + n);
  for (int i = (0); i <= ((n)-1); i++) {
    if (i) a[i] += a[i - 1];
  }
  for (int t = 0; t < p.size(); t++) {
    int k = p[t];
    long long res = 0;
    for (long long i = 0, c = 1, it = 0; i < n; i += c, c *= k, it++) {
      res += it * csum(i, min((long long)n - 1, i + c - 1));
    }
    ans[k] = res;
  }
  for (int i = (0); i <= ((q)-1); i++) {
    if (i) printf(" ");
    printf("%I64d", ans[queries[i]]);
  }
  puts("");
  return 0;
}
