#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, q, a[N];
long long s[N], z;
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++)
    s[i] = s[i - 1] + a[i], z += (long long)(n - i) * a[i];
  scanf("%d", &q);
  while (q--) {
    int k;
    long long ans = 0;
    scanf("%d", &k);
    if (k == 1) {
      printf("%lld\n", z);
      continue;
    }
    for (long long t = n - 1, p = k, x = 1; t > 0; t -= p, p *= k, x++)
      ans += (long long)x * (s[t] - s[max(0ll, t - p)]);
    printf("%lld\n", ans);
  }
  return 0;
}
