#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
int a[N];
long long d[N];
int q;
long long solve(int k) {
  long long p = 1;
  long long sum = p;
  long long res = 0;
  while (sum < n) {
    res += d[n - sum];
    p *= k;
    sum += p;
  }
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) {
    d[i] = d[i - 1] + a[i];
  }
  scanf("%d", &q);
  long long ans1 = solve(1);
  for (int i = 0, k; i < q; ++i) {
    scanf("%d", &k);
    if (k == 1) {
      printf("%I64d%c", ans1, " \n"[i == q - 1]);
    } else {
      printf("%I64d%c", solve(k), " \n"[i == q - 1]);
    }
  }
  return 0;
}
