#include <bits/stdc++.h>
using namespace std;
const long long N = 111111;
long long a[N], sum[N];
long long n, q;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (long long i = (1); i <= (n); i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1, std::greater<long long>());
  for (long long i = (1); i <= (n); i++) {
    sum[i] = sum[i - 1] + a[i];
  }
  cin >> q;
  long long a1 = 0;
  while (q--) {
    long long k;
    cin >> k;
    if (k == 1 && a1) {
      cout << a1 << " ";
    } else {
      long long l = 1, r, p = 1, cnt = 0;
      long long ans = 0;
      while (l <= n) {
        r = min(n, l + p - 1);
        ans += (sum[r] - sum[l - 1]) * cnt;
        l += p;
        p *= k;
        cnt++;
      }
      if (k == 1) {
        a1 = ans;
      }
      cout << ans << " ";
    }
  }
  cout << "\n";
  return 0;
}
