#include <bits/stdc++.h>
using namespace std;
long long a[211111] = {};
long long s[211111] = {};
long long sss = 0;
long cmp(long a, long b) {
  if (a > b)
    return 1;
  else
    return 0;
}
long long solve(long x, long n) {
  if (x == 1) {
    return sss;
  }
  long long last = 0;
  long long ans = 0;
  long long tt = 1;
  long long p = 1;
  long long cnt = 0;
  while (tt < n) {
    p = p * x;
    tt = last + p;
    if (tt >= n) tt = n;
    cnt++;
    ans += (s[tt] - s[last]) * cnt;
    last = tt;
  }
  return ans;
}
int main() {
  long n, q;
  long i, j, k;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n, cmp);
  s[0] = a[0];
  for (i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
  for (i = 1; i <= n; i++) sss += a[i] * i;
  cin >> q;
  for (i = 0; i < q; i++) {
    long x;
    cin >> x;
    cout << solve(x, n) << " ";
  }
}
