#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a.rbegin(), a.rend());
  long long ret1 = 0;
  for (int i = 1; i < n; ++i) ret1 += a[i] * i;
  for (int i = 0; i < n - 1; ++i) a[i + 1] += a[i];
  long long q;
  cin >> q;
  while (--q >= 0) {
    int k;
    cin >> k;
    if (k == 1) {
      cout << ret1 << endl;
      continue;
    }
    long long i = 0;
    long long x = 1;
    long long len = k;
    long long ret = 0;
    while (i < n) {
      ret += (a[min(n - 1, i + len)] - a[i]) * x;
      i += len;
      ++x;
      len *= k;
    }
    cout << ret << endl;
  }
  return 0;
}
