#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 100004;
long long a[N], ans[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; ++i) a[i] += a[i - 1];
  for (int k = 1; k <= n; ++k) {
    int r = n - 1;
    long long s = k;
    for (int j = 1; r > 0; ++j) {
      int l = max(0LL, r - s);
      ans[k] += j * (a[r] - a[l]);
      r = l;
      s *= k;
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int u;
    scanf("%d", &u);
    printf("%lld ", ans[min(u, n)]);
  }
}
