#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, q, a[N];
long long f[N], s[N];
bool cmp(const int &x, const int &y) { return x > y; }
long long solve(int k) {
  if (~f[k]) return f[k];
  long long ret = 0, t = 0, p = 1;
  for (int i = 2, j; i <= n; i = j) {
    ++t, p = p * k;
    j = min((long long)(n + 1), i + p);
    ret += t * (s[j - 1] - s[i - 1]);
  }
  return f[k] = ret;
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i < (n + 1); ++i) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n, cmp);
  for (int i = (1); i < (n + 1); ++i) s[i] = s[i - 1] + a[i];
  memset(f, -1, sizeof(f));
  scanf("%d", &q);
  for (int i = (0); i < (q); ++i) {
    int k;
    scanf("%d", &k);
    if (i) putchar(' ');
    printf("%lld", solve(k));
  }
  return 0;
}
