#include <bits/stdc++.h>
using namespace std;
int n, m, a[100001];
long long s[100001], ans[100001];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
  cin >> m;
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    if (!ans[k]) {
      long long res = 0;
      long long koef = 1, cnt = k, j0 = 2, j1;
      while (j0 <= n) {
        j1 = min((long long)n, j0 + cnt - 1);
        res += (s[j1] - s[j0 - 1]) * koef;
        j0 = j0 + cnt;
        koef++;
        cnt *= k;
      }
      ans[k] = res;
    }
    cout << ans[k] << " ";
  }
  return 0;
}
