#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 100010;
int ar[maxn], k[maxn];
long long result[maxn], sum[maxn];
int main() {
  int n, q, mk = -1;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &ar[i]);
  }
  sort(ar, ar + n);
  reverse(ar, ar + n);
  for (int i = 1; i < n; ++i) {
    sum[i] = sum[i - 1] + ar[i];
  }
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d", &k[i]);
    mk = max(mk, k[i]);
  }
  for (int i = 1; i <= mk; ++i) {
    long long res = 0, dc = i;
    for (long long c = 1, p = 1; p < n; ++c, p += dc, dc *= i) {
      res +=
          (sum[min((long long)n - 1, p + dc - 1)] - sum[p - 1]) * (long long)c;
    }
    result[i] = res;
  }
  for (int i = 0; i < q; ++i) {
    printf("%I64d ", result[k[i]]);
  }
  puts("");
  return 0;
}
