#include <bits/stdc++.h>
using namespace std;
int n, q, k;
long long now;
long long a[100010];
long long dp[100010];
long long sum[100010];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%I64d", &a[i]);
  sort(a, a + n);
  reverse(a, a + n);
  for (int i = n - 1; i >= 0; i--)
    i == n - 1 ? sum[i] = a[i] : sum[i] = a[i] + sum[i + 1];
  cin >> q;
  for (int i = 0; i < 100010; i++) dp[i] = -1;
  for (int qq = 0; qq < q; qq++) {
    scanf("%d", &k);
    if (dp[k] != -1) {
      printf("%I64d ", dp[k]);
      continue;
    }
    long long s = 0;
    int c = 1;
    long long f = 1;
    now = k;
    int i;
    while (true) {
      if (f + now < n) {
        s += c * (sum[f] - sum[f + now]);
      } else {
        if (f >= n) break;
        s += c * (sum[f]);
        break;
      }
      c++;
      f = f + now;
      now = now * k;
    }
    dp[k] = s;
    printf("%I64d ", s);
  }
  cout << endl;
  return 0;
}
