#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 1;
long long n, a[N], s[N];
int main(int argc, const char* argv[]) {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
  long long ans1 = -1;
  int q, k;
  cin >> q;
  for (int ca = 0; ca < q; ca++) {
    cin >> k;
    long long last, sum;
    long long ans = 0;
    last = sum = 1;
    while ((!(k == 1 && ans1 >= 0)) && sum < n) {
      ans += s[(n - sum)];
      last *= k;
      sum += last;
    }
    if (k == 1) {
      if (ans1 < 0)
        ans1 = ans;
      else
        ans = ans1;
    }
    cout << ans;
    if (ca == q - 1)
      cout << endl;
    else
      cout << " ";
  }
  return 0;
}
