#include <bits/stdc++.h>
using namespace std;
long long arr[100001];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &arr[i]);
  sort(arr + 1, arr + n + 1, greater<long long>());
  long long OneAnswer = 0;
  for (int i = 2; i <= n; i++) OneAnswer += (long long)(i - 1) * arr[i];
  for (int i = 1; i <= n; i++) arr[i] += arr[i - 1];
  int q;
  scanf("%d", &q);
  while (q--) {
    long long last = 1;
    long long cursz = 1, sz = 0;
    int ccurq;
    scanf("%d", &ccurq);
    if (ccurq == 1) {
      printf("%I64d\n", OneAnswer);
      continue;
    }
    long long ans = 0;
    while (last < n) {
      sz++;
      cursz *= (long long)ccurq;
      if ((long long)last + cursz > n) {
        ans += (long long)sz * (arr[n] - arr[last]);
      } else
        ans += (long long)sz * (arr[last + cursz] - arr[last]);
      last = last + cursz;
    }
    printf("%I64d%c", ans, " \n"[q == 0]);
  }
  return 0;
}
