#include <bits/stdc++.h>
using namespace std;
const int MAX = int(1e5) + 10;
const long long oo = 1LL << 60;
int N;
long long a[MAX];
long long s[MAX];
int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> a[i];
  sort(a + 1, a + N + 1);
  long long one = 0;
  for (int i = N; i > 0; i--) one += a[i] * (N - i);
  for (int i = 1; i <= N; i++) s[i] = s[i - 1] + a[i];
  int q;
  int k;
  cin >> q;
  for (int it = 0; it < q; it++) {
    cin >> k;
    if (it) cout << " ";
    if (k == 1) {
      cout << one;
      continue;
    }
    long long ans = 0;
    long long p = 0, pot = 1, last = N;
    while (last > 0) {
      long long hi = last, lo = max(last - pot, 0LL);
      ans += p * (s[hi] - s[lo]);
      last -= pot;
      p++;
      pot *= k;
    }
    cout << ans;
  }
  cout << endl;
  return 0;
}
