#include <bits/stdc++.h>
using namespace std;
inline uint64_t get_sum(uint64_t *sums, uint64_t ind, uint64_t len) {
  if (ind < len)
    return sums[ind];
  else
    return sums[ind] - sums[ind - len];
}
uint64_t calc_res_1(uint64_t *sums, int n) {
  uint64_t res = 0;
  if (n > 1) {
    uint64_t ind = n - 2;
    uint64_t len = 1;
    int factor = 1;
    while (true) {
      res += get_sum(sums, ind, len) * factor;
      if (ind >= len)
        ind = ind - len;
      else
        break;
      factor++;
    }
  }
  return res;
}
int main() {
  istream *is = &cin;
  int n;
  *is >> n;
  int *numbers = new int[n];
  for (int i = 0; i < n; i++) *is >> numbers[i];
  int q;
  *is >> q;
  stable_sort(numbers, numbers + n);
  uint64_t *sums = new uint64_t[n];
  sums[0] = numbers[0];
  for (int i = 1; i < n; i++) sums[i] = sums[i - 1] + numbers[i];
  uint64_t res_for_1 = calc_res_1(sums, n);
  for (int l = 0; l < q; l++) {
    int k;
    *is >> k;
    uint64_t res = 0;
    if (k == 1)
      res = res_for_1;
    else {
      if (n > 1) {
        uint64_t ind = n - 2;
        uint64_t len = k;
        int factor = 1;
        while (true) {
          res += get_sum(sums, ind, len) * factor;
          if (ind >= len)
            ind = ind - len;
          else
            break;
          len *= k;
          factor++;
        }
      }
    }
    cout << res << " ";
  }
  return 0;
}
