#include <bits/stdc++.h>
using namespace std;
long long a[100001], s[100001];
inline long long sum(int l, int r) { return s[r + 1] - s[l]; }
long long power(long long a, long long b) {
  if (b == 0) return 1;
  long long p = power(a, b / 2);
  if (b % 2 == 1)
    return p * p * a;
  else
    return p * p;
}
int main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  reverse(a, a + n);
  long long c = 0;
  for (long long i = 0; i < n; i++) c += a[i] * i;
  s[0] = 0;
  for (long long i = 0; i < n; i++) s[i + 1] = s[i] + a[i];
  int q;
  cin >> q;
  for (int test = 0; test < q; test++) {
    int k;
    cin >> k;
    if (k == 1) {
      cout << c << endl;
      continue;
    }
    long long p = 0, cnt = 0;
    long long ans = 0;
    while (cnt < n) {
      ans += p * sum(cnt, min(n - 1, cnt + power(k, p) - 1));
      cnt += power(k, p);
      p++;
    }
    cout << ans << " ";
  }
  return 0;
}
