#include <bits/stdc++.h>
using namespace std;
long long vals[100005], somas[100005];
bool cmp(long long a, long long b) { return a > b; }
int main() {
  int n;
  scanf(" %d", &n);
  for (int i = 0; i < n; i++) scanf(" %I64d", &vals[i]);
  sort(vals, vals + n, cmp);
  somas[0] = 0;
  for (int i = 1; i <= n; i++) somas[i] = somas[i - 1] + vals[i - 1];
  long long resk1 = 0;
  for (int i = 1; i < n; i++) resk1 += vals[i] * i;
  int nk;
  scanf(" %d", &nk);
  for (int i = 0; i < nk; i++) {
    if (i) printf(" ");
    long long k;
    scanf(" %I64d", &k);
    if (k == 1) {
      printf("%I64d", resk1);
      continue;
    }
    long long dp = 1, pos = 1, size = k, res = 0;
    while (pos + size < n) {
      res += (somas[pos + size] - somas[pos]) * dp;
      pos += size;
      size *= k;
      dp++;
    }
    res += (somas[n] - somas[pos]) * dp;
    printf("%I64d", res);
  }
  return 0;
}
