#include <bits/stdc++.h>
using namespace std;
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
  s << "{";
  for (int i = 0; i < t.size(); i++)
    s << t[i] << (i == t.size() - 1 ? "" : ",");
  return s << "}" << endl;
}
int a[100002];
long long wyn[100002];
long long s[100002];
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  scanf("%d", &(n));
  ;
  for (int i = 0; i < n; i++) scanf("%d", &(a[i]));
  ;
  sort(a, a + n);
  n--;
  reverse(a, a + n);
  s[0] = 0;
  for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i - 1];
  for (int i = 1; i <= n; i++) {
    int k = 0;
    int k2;
    int cnt = 1;
    long long plus = i;
    while (k < n) {
      k2 = min(k + plus, (long long)n);
      wyn[i] += cnt * (s[k2] - s[k]);
      k = k2;
      cnt++;
      plus *= i;
    }
  }
  int q;
  scanf("%d", &(q));
  ;
  while (q--) {
    int z;
    scanf("%d", &(z));
    ;
    z = min(z, n);
    printf("%I64d ", wyn[z]);
  }
  return 0;
}
