#include <bits/stdc++.h>
using namespace std;
int n, q, k;
long long a[100001];
long long s[100001];
long long qs[100001];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%I64d", &a[i]);
  sort(a + 1, a + n + 1);
  s[1] = a[1];
  memset(qs, 0, sizeof(qs));
  for (int i = 2; i <= n; ++i) s[i] = s[i - 1] + a[i];
  for (int i = 1; i <= n - 1; ++i) {
    long long p = i;
    long long x = n - 1, y = x - p, cnt = 1;
    while (x >= 1) {
      if (y >= 1)
        qs[i] += cnt * (s[x] - s[y]);
      else
        qs[i] += cnt * s[x];
      x = y;
      p *= i;
      y = x - p;
      cnt++;
    }
  }
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d", &k);
    if (k >= n - 1)
      printf("%I64d ", qs[n - 1]);
    else
      printf("%I64d ", qs[k]);
  }
  return 0;
}
