#include <bits/stdc++.h>
using namespace std;
long long a[100005], b[100005];
bool cmp(long long x, long long y) { return x > y; }
int main() {
  long long n, i, j, k;
  long long p, s;
  for (i = 0; i < 100001; i++) b[i] = 0;
  scanf("%I64d", &n);
  for (i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  sort(a + 1, a + 1 + n, cmp);
  for (i = 1; i <= n; i++) a[i] += a[i - 1];
  for (p = 100000, i = 1; i <= p; i++)
    for (s = 0, j = 1, k = 0;; s += j, j *= i, k++)
      if (s + j > n) {
        b[i] += (a[n] - a[s]) * k;
        break;
      } else
        b[i] += (a[s + j] - a[s]) * k;
  scanf("%I64d", &n);
  while (n--) scanf("%d", &i), printf("%I64d%s", b[i], n ? " " : "\n");
  return 0;
}
