#include <bits/stdc++.h>
using namespace std;
long long num[100009];
long long sol[100009];
int main() {
  int n, k, a;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &num[i]);
  sort(num + 1, num + n + 1);
  num[0] = 0;
  for (int i = 1; i <= n; ++i) num[i] += num[i - 1];
  scanf("%d", &k);
  long long j;
  while (k--) {
    scanf("%d", &a);
    j = 1;
    long long q = 1;
    if (sol[a] == 0) {
      for (long long i = n - 1; i > 0; i -= q, ++j) {
        q *= a;
        sol[a] = sol[a] + (num[i] - num[max((long long)0, i - q)]) * j;
      }
    }
    printf("%I64d%c", sol[a], k == 0 ? '\n' : ' ');
  }
}
