#include <bits/stdc++.h>
using namespace std;
long long a[100005], sum[100005];
int main() {
  int n, q;
  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];
  long long t = 0;
  for (int i = n - 1; i >= 1; i--) t = t + a[i] * (n - i);
  scanf("%d", &q);
  while (q--) {
    int x;
    long long ans = 0;
    scanf("%d", &x);
    if (x == 1)
      ans = t;
    else {
      int m = n - 1, cnt = 1;
      long long k = x;
      while (m >= k) {
        ans = ans + cnt * (sum[m] - sum[m - k]);
        m = m - k;
        k = k * x;
        cnt++;
      }
      ans = ans + cnt * sum[m];
    }
    printf("%I64d ", ans);
  }
  puts("");
  return 0;
}
