#include <bits/stdc++.h>
int n, T;
long long ans, times, cur, p, sum[100010], ans1, data[100010];
bool bo;
long long min(long long a, long long b) { return a < b ? a : b; }
void qs(int l, int r) {
  int i = l, j = r;
  long long mid = data[(l + r) >> 1], t;
  while (i <= j) {
    while (data[i] > mid) i++;
    while (mid > data[j]) j--;
    if (i <= j) {
      t = data[i];
      data[i] = data[j];
      data[j] = t;
      i++;
      j--;
    }
  }
  if (l < j) qs(l, j);
  if (i < r) qs(i, r);
}
void solve(int x) {
  cur = 1;
  times = ans = 0;
  p = 2;
  while (p <= n) {
    cur *= x;
    times++;
    ans += (sum[min(p + cur - 1, n)] - sum[p - 1]) * times;
    p += cur;
  }
}
int main() {
  int i, x;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%I64d", &data[i]);
  qs(1, n);
  for (i = 2; i <= n; i++) {
    sum[i] = sum[i - 1] + data[i];
    ans1 += data[i] * (i - 1);
  }
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &x);
    if (x == 1)
      ans = ans1;
    else
      solve(x);
    if (!bo) {
      printf("%I64d", ans);
      bo = true;
    } else
      printf(" %I64d", ans);
  }
  printf("\n");
}
