#include <bits/stdc++.h>
using namespace std;
int n, q, k;
long long sum[101000] = {0}, a[101000], SUM = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + a[i];
    SUM += sum[i];
  }
  scanf("%d", &q);
  while (q--) {
    long long ans = 0, t = 1, temp;
    scanf("%d", &k);
    if (k == 1) {
      printf("%I64d ", SUM - sum[n]);
      continue;
    }
    for (temp = n - 1; temp > 0; temp -= t) {
      ans += sum[temp];
      t *= k;
    }
    printf("%I64d ", ans);
  }
  printf("\n");
  return 0;
}
