#include <bits/stdc++.h>
using namespace std;
int v[100500];
int n;
long long int ac[100500];
long long int memo[100500];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); i++) {
    scanf("%d", &v[i]);
  }
  sort(v, v + n);
  ac[0] = 0;
  int k = 1;
  for (int i = n - 2; i >= 0; i--) {
    ac[k] = ac[k - 1] + v[i];
    k++;
  }
  int q;
  scanf("%d", &q);
  long long int res = 0;
  long long int ind, ant, num;
  memset(memo, -1, sizeof(memo));
  num = 1;
  for (int i = 0; i < (q); i++) {
    long long int x;
    cin >> x;
    if (i != 0) printf(" ");
    if (memo[x] != -1) {
      cout << memo[x];
      continue;
    }
    ind = x;
    ant = 0;
    num = 1;
    res = 0;
    while (1) {
      if (ind >= n) {
        res += (ac[n - 1] - ac[ant]) * num;
        break;
      }
      res += (ac[ind] - ac[ant]) * num;
      ant = ind;
      ind = x + ind * x;
      num++;
    }
    memo[x] = res;
    cout << res;
  }
  printf("\n");
  return 0;
}
