#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<long long>());
  vector<long long> integral(n + 1);
  for (int i = 0; i < n; ++i) {
    integral[i + 1] = integral[i] + a[i];
  }
  long long k_is_one = 0;
  for (int i = 0; i < n; ++i) {
    k_is_one += a[i] * i;
  }
  int q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    if (k == 1) {
      cout << k_is_one;
    } else {
      long long p = 0, r = 1, mul = 0, answer = 0;
      while (p < n) {
        answer += (integral[min((long long)n, p + r)] - integral[p]) * mul;
        p += r;
        r *= k;
        ++mul;
      }
      cout << answer;
    }
    if (q == 0) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
  return 0;
}
