#include <bits/stdc++.h>
using namespace std;
long long n, arr[100003], prefSum[100003], answer[100003];
long long getSum(int i, int j) { return prefSum[j] - prefSum[i - 1]; }
bool cmp(long long a, long long b) { return a > b; }
int main() {
  long long i, j;
  scanf("%lld", &n);
  ;
  for (i = 1; i <= n; i++) scanf("%lld", &arr[i]);
  ;
  sort(arr + 1, arr + 1 + n, cmp);
  for (i = 1; i <= n; i++) prefSum[i] = (prefSum[i - 1] + arr[i]);
  for (i = 1; i <= n; i++) {
    long long windowLength = 1, counter = 0, ans = 0;
    for (j = 1; j <= n;) {
      ans = (ans + counter * getSum(j, min(n, j + windowLength - 1)));
      counter++;
      j += windowLength;
      windowLength = windowLength * i;
    }
    answer[i] = ans;
  }
  long long q, num;
  scanf("%lld", &q);
  ;
  while (q--) {
    scanf("%lld", &num);
    ;
    if (num >= n) num = n;
    cout << answer[num] << " ";
  }
  cout << endl;
  return 0;
}
