#include <bits/stdc++.h>
using namespace std;
long long ans[100003];
int arr[100001];
long long prefSum[100001];
int n;
inline long long sum(long long a, long long b) {
  if (a == 0)
    return prefSum[b];
  else
    return prefSum[b] - prefSum[a - 1];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  prefSum[0] = arr[0];
  for (int i = 1; i < n; i++) {
    prefSum[i] = prefSum[i - 1] + arr[i];
  }
  for (long long base = 1; base <= n; base++) {
    ans[base] = 0;
    long long len = base;
    long long right = n - 2;
    long long hwm = 1;
    while (right >= 0) {
      long long s = sum(max(0LL, right - len + 1), (long long)right);
      ans[base] += s * hwm;
      hwm++;
      right = right - len;
      len *= base;
    }
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    if (k > 100000) {
      while (1) {
        k++;
      }
    }
    k = min(k, n);
    cout << ans[k] << " ";
  }
  return 0;
}
