#include <bits/stdc++.h>
using namespace std;
long long sum[100010], a[100010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%I64d", &a[i]);
  sort(a, a + n);
  reverse(a, a + n);
  sum[0] = a[0];
  long long ans1 = 0;
  for (int i = 1; i < n; i++) {
    sum[i] = sum[i - 1] + a[i];
    ans1 += a[i] * i;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int x;
    scanf("%d", &x);
    if (x == 1)
      printf("%I64d ", ans1);
    else {
      long long len = x, now = 1, summ = 0;
      for (int pos = 1; pos < n; len = len * x) {
        if (pos + len < n) {
          summ += (sum[pos + len - 1] - sum[pos - 1]) * now;
          pos += len;
        } else {
          summ += (sum[n - 1] - sum[pos - 1]) * now;
          pos = n;
        }
        now++;
      }
      printf("%I64d ", summ);
    }
    puts("");
  }
}
