#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool Up(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool Down(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
inline int getus() {
  int tmp, c;
  while (tmp = fgetc(stdin), tmp < '0' || tmp > '9')
    ;
  tmp -= '0';
  while (c = fgetc(stdin), '0' <= c && c <= '9') tmp = tmp * 10 + c - '0';
  return tmp;
}
inline int getint() {
  int tmp, c, flag;
  while (flag = fgetc(stdin), flag != '-' && (flag < '0' || flag > '9'))
    ;
  if (flag == '-')
    tmp = 0;
  else
    tmp = flag - '0';
  while (c = fgetc(stdin), '0' <= c && c <= '9') tmp = tmp * 10 + c - '0';
  return flag == '-' ? -tmp : tmp;
}
int N, A[100022];
long long Sum[100022], ans[100022];
int main() {
  scanf("%d", &N);
  for (int i = (1); i <= (N); ++i) scanf("%d", A + i);
  sort(A + 1, A + N + 1, greater<int>());
  Sum[0] = 0;
  for (int i = (1); i <= (N); ++i) Sum[i] = Sum[i - 1] + A[i];
  for (int deg = 1; deg < N; ++deg) {
    long long len = 1, begin = 1, end = 1;
    long long &res = ans[deg] = 0;
    for (int dep = 0;; ++dep) {
      res += (Sum[end] - Sum[begin - 1]) * dep;
      len *= deg;
      begin = end + 1;
      end = begin - 1 + len;
      if (begin > N) break;
      if (end > N) end = N;
    }
  }
  int Q;
  for (scanf("%d", &Q); Q--;) {
    int d;
    scanf("%d", &d);
    if (d > N - 1) d = N - 1;
    printf("%I64d", ans[d]);
    if (!Q)
      putchar('\n');
    else
      putchar(' ');
  }
  return 0;
}
