#include <bits/stdc++.h>
using namespace std;
const int DMAX = 1e5 + 10;
long long int V[DMAX];
long long int Sp[DMAX];
long long int ans[DMAX];
long long int suma;
long long int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int i, j, cate, k, x, s;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> V[i];
    suma += V[i];
  }
  sort(V + 1, V + n + 1);
  reverse(V + 1, V + n + 1);
  for (i = 1; i <= n; i++) Sp[i] = Sp[i - 1] + V[i];
  for (i = 2; i < n; i++) {
    for (j = 1, s = 0, cate = 0; s <= n; s += j, cate++, j *= i) {
      ans[i] += 1LL * (Sp[min(n, s + j)] - Sp[s]) * cate;
    }
  }
  for (i = 2; i <= n; i++) ans[1] += (1LL * V[i] * (i - 1));
  cin >> k;
  while (k--) {
    cin >> x;
    x = min(x, n - 1);
    cout << ans[x] << ' ';
  }
  return 0;
}
