#include <bits/stdc++.h>
using namespace std;
long long i, n, now, hh, ceng, ans, t, t1, la, a[100001], f[100001], g[100001],
    sum[100001];
bool cmp(long long a, long long b) { return a > b; }
int main() {
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  sort(a + 1, a + n + 1, cmp);
  for (i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
  scanf("%lld", &t1);
  while (t1--) {
    scanf("%lld", &t);
    if (g[t])
      printf("%lld\n", f[t]);
    else {
      ans = 0;
      hh = t;
      ceng = 1;
      la = 2;
      for (i = 2; i <= n; i = la) {
        ans += (sum[min(n, la + hh - 1)] - sum[i - 1]) * ceng;
        la += hh;
        ceng++;
        hh *= t;
      }
      printf("%lld\n", ans);
      g[t] = 1;
      f[t] = ans;
    }
  }
}
