#include <bits/stdc++.h>
using namespace std;
int a[110000];
long long sum[110000], ans[110000];
void qsort(int l, int r) {
  int i, j, x, t;
  i = l;
  j = r;
  x = a[(l + r) / 2];
  while (1) {
    if (i > j) break;
    while (a[i] < x) i++;
    while (x < a[j]) j--;
    if (i <= j) {
      t = a[i];
      a[i] = a[j];
      a[j] = t;
      i++;
      j--;
    }
  }
  if (i < r) qsort(i, r);
  if (l < j) qsort(l, j);
}
int main() {
  int n, m, i, j, k;
  long long f11 = -1;
  scanf("%d", &n);
  sum[0] = 0;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  qsort(1, n);
  for (i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
  scanf("%d", &m);
  for (int kk = 1; kk <= m; kk++) {
    scanf("%d", &k);
    if (k == 1) {
      if (f11 == -1) {
        f11 = 0;
        for (i = 1; i <= n - 1; i++) f11 += sum[i];
      }
      ans[kk] = f11;
      continue;
    }
    long long dc = 0, cf = 1;
    ans[kk] = 0;
    long long fi = (long long)n;
    for (j = 1;; j++) {
      if (fi - cf >= 0)
        dc = sum[fi] - sum[fi - cf];
      else
        dc = sum[fi];
      fi -= cf;
      cf *= k;
      ans[kk] += dc * ((long long)j - 1);
      if (fi <= 0) break;
    }
  }
  for (i = 1; i < m; i++) printf("%I64d ", ans[i]);
  printf("%I64d\n", ans[m]);
  return 0;
}
