#include <bits/stdc++.h>
using namespace std;
int n, a[100005];
long long S[100005];
long long F[100005];
int main() {
  if (!1)
    freopen(
        ""
        ".in",
        "r", stdin);
  if (!1)
    freopen(
        ""
        ".out",
        "w", stdout);
  int i, j, k, _T;
  while (~scanf("%d", &n)) {
    for (i = 1; i <= n; i++) scanf("%d", &a[i]);
    sort(a + 1, a + 1 + n);
    reverse(a + 1, a + 1 + n);
    memset(F, 0, sizeof F);
    S[0] = 0;
    for (i = 1; i <= n; i++) S[i] = S[i - 1] + a[i];
    for (k = 1; k <= 100000; k++) {
      int id = 0, mul = 0;
      long long len = 1;
      while (id < n) {
        F[k] += (S[min(id + len, 1LL * n)] - S[id]) * mul;
        mul++;
        id = min(id + len, 1LL * n);
        len *= k;
      }
    }
    int Q;
    scanf("%d", &Q);
    while (Q--) {
      scanf("%d", &k);
      cout << F[k] << "\n";
    }
  }
  return 0;
}
