#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
long long sum[M], ans, s[M];
int k, n, q;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  sort(s, s + n);
  reverse(s, s + n);
  sum[0] = s[0];
  for (int i = 1; i < n; i++) sum[i] = sum[i - 1] + s[i];
  long long m = 0;
  for (int i = 1; i < n; i++) m += s[i] * i;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> k;
    if (k == 1) {
      cout << m << " ";
      continue;
    }
    ans = 0;
    long long num = 1;
    for (long long l = 1, c = 1; l < n; l += num, c++) {
      num *= k;
      if (l + num - 1 < n)
        ans += (sum[l + num - 1] - sum[l - 1]) * c;
      else
        ans += (sum[n - 1] - sum[l - 1]) * c;
    }
    cout << ans << " ";
  }
  return 0;
}
