#include <bits/stdc++.h>
using namespace std;
long long a[111111], ans[111111];
int n, kk;
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) scanf("%I64d", &a[i]);
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  for (int i = (1); i <= (n); ++i) a[i] += a[i - 1];
  scanf("%d", &kk);
  for (int t = (0); t < (kk); ++t) {
    int k;
    scanf("%d", &k);
    k = (k > n - 1) ? n - 1 : k;
    if (!ans[k]) {
      long long l, r, st, tmp;
      l = r = tmp = 1;
      st = 0;
      while (l <= n) {
        ans[k] += (a[r] - a[l - 1]) * st;
        tmp *= k;
        ++st;
        l = r + 1;
        r += tmp;
        r = (r > n) ? n : r;
      }
    }
    printf("%I64d ", ans[k]);
  }
  return 0;
}
