#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
long long a[maxn];
long long ans[maxn], sum[maxn];
int main() {
  int n, m, bb;
  while (scanf("%d", &n) == 1) {
    for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
    sort(a + 1, a + 1 + n, greater<long long>());
    sum[1] = 0;
    for (int i = 2; i <= n; i++) sum[i] = sum[i - 1] + a[i];
    for (int k = 1; k < n; k++) {
      long long start = 2, kk = k, step = 1;
      ans[k] = 0;
      while (start <= n) {
        long long tail = kk + start - 1;
        if (tail > n) tail = n;
        ans[k] += (sum[tail] - sum[start - 1]) * step;
        step++;
        kk *= k;
        start = tail + 1;
      }
    }
    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
      scanf("%d", &bb);
      bb = min(bb, n - 1);
      if (i) putchar(' ');
      printf("%I64d", ans[bb]);
    }
    puts("");
  }
  return 0;
}
