#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979;
const double eps = 1e-15;
const int INF = 1000000000;
const int maxn = 100010;
const int maxm = 20;
long long n, q, k;
long long sum[maxn], a[maxn], ans[maxn];
int main() {
  memset(ans, -1, sizeof(ans));
  scanf("%I64d", &n);
  for (int i = 0; i < n; ++i) scanf("%I64d", &a[i]);
  sort(a, a + n);
  sum[0] = 0;
  for (int i = 1; i < n + 1; ++i) sum[i] = sum[i - 1] + a[i - 1];
  scanf("%I64d", &q);
  while (q--) {
    scanf("%I64d", &k);
    if (ans[k] == -1) {
      long long tmp = 0, p = 1, m = n - 1, x = k;
      while (m >= x) {
        tmp += p * (sum[m] - sum[m - x]);
        m -= x;
        x *= k;
        ++p;
      }
      tmp += p * sum[m];
      ans[k] = tmp;
    }
    if (q == 0)
      printf("%I64d\n", ans[k]);
    else
      printf("%I64d ", ans[k]);
  }
  return 0;
}
