#include <bits/stdc++.h>
const int N = 100005;
long long a[N], s[N];
long long max;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
  }
  std::sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    s[i] = s[i - 1] + a[i];
    max += s[i];
  }
  int m, k;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &k);
    if (i) putchar(' ');
    if (k == 1)
      printf("%I64d\n", max - s[n]);
    else {
      long long ans = 0, t = n - 1, d = 1;
      while (t >= 0) {
        ans += s[t];
        d *= k;
        t -= d;
      }
      printf("%I64d", ans);
    }
  }
  puts("");
  return 0;
}
