#include <bits/stdc++.h>
using namespace std;
const int MAX = 100001;
long long a[MAX];
long long sum[MAX];
int main() {
  ios::sync_with_stdio(false);
  long long N, ret = 0;
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> a[i];
  sort(a, a + N, greater<long long>());
  for (int i = 1; i < N; ++i) {
    ret += a[i] * i;
    sum[i] = sum[i - 1] + a[i];
  }
  int runs, k, i;
  long long v;
  cin >> runs;
  while (runs--) {
    cin >> k;
    if (k == 1)
      cout << ret;
    else {
      long long ans = 0;
      long long ant = 0;
      long long steep = k;
      bool flag = true;
      for (i = 1, v = steep; flag; v = steep + v, ++i) {
        if (v >= N) v = N - 1, flag = false;
        ans += (sum[v] - sum[ant]) * i;
        ant = v;
        steep *= k;
      }
      cout << ans;
    }
    if (runs) cout << " ";
  }
  cout << endl;
  return 0;
}
