#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
using namespace std;
int cmp(long long a, long long b) { return a < b; }
int main() {
  long long n;
  scanf("%I64d", &n);
  int i;
  long long a[100005], s[100005];
  for (i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  sort(a + 1, a + 1 + n);
  s[0] = 0;
  for (i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
  long long data = 0;
  for (i = n - 1; i >= 1; i--) data += a[i] * (n - i);
  n--;
  int q;
  scanf("%d", &q);
  while (q--) {
    long long ans = 0;
    long long k;
    scanf("%I64d", &k);
    int t = k;
    long long cnt = 1, m = n;
    if (k != 1) {
      while (m >= k) {
        ans += (s[m] - s[m - k]) * cnt;
        cnt++;
        m -= k;
        k = k * t;
      }
      ans += cnt * s[m];
    } else
      ans = data;
    printf("%I64d ", ans);
  }
  return 0;
}
