#include <bits/stdc++.h>
using namespace std;
struct classcomp {
  bool operator()(const int& lhs, const int& rhs) const { return lhs > rhs; }
};
int gcd(int x, int y) { return (y == 0) ? x : gcd(y, x % y); }
string convertint(int x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
bool f(int a, int b) { return a > b; }
int a[100005];
int kk[100005];
long long sum[100005];
long long tot[100005];
int main(void) {
  int n, q;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) scanf("%d", &kk[i]);
  sort(a, a + n, f);
  tot[0] = a[0];
  for (int i = 1; i < n; i++) tot[i] = tot[i - 1] + a[i];
  for (int k = 1; k <= 100005; k++) {
    long long start = 1LL;
    long long end = k * 1LL;
    int times = 1;
    while (start < n && end >= start) {
      sum[k] +=
          1LL * times * (tot[((end < n - 1) ? end : n - 1)] - tot[start - 1]);
      start = k * start + 1;
      end = k * (end + 1);
      times++;
    }
  }
  for (int i = 0; i < q; i++) {
    cout << sum[kk[i]] << " ";
  }
  return 0;
}
