#include <bits/stdc++.h>
using namespace std;
bool comp(long long a, long long b) { return (a > b); }
long long sum[100009];
long long in[100009];
int main() {
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> in[i];
  sort(in + 1, in + 1 + n, comp);
  sum[0] = 0;
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + in[i];
  }
  long long tail = 0;
  for (int i = 2; i <= n; i++) tail += (i - 1) * in[i];
  int Q, k;
  cin >> Q;
  for (int i = 1; i <= Q; i++) {
    cin >> k;
    if (k == 1) {
      cout << tail << endl;
      continue;
    }
    long long sz = 1;
    long long ans = 0;
    int prev = 1;
    for (long long d = 1;; d++) {
      sz = sz * k;
      long long st = prev + 1;
      long long ed = min(n, st + sz - 1);
      ans += (d) * (sum[ed] - sum[st - 1]);
      prev = ed;
      if (ed == n) break;
    }
    cout << ans << " ";
  }
  return 0;
}
