#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
long long int A[MAXN];
long long int SM[MAXN];
int main() {
  int n;
  int q;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) cin >> A[i];
  sort(A, A + n);
  long long int tmp = 0;
  for (int i = 0; i < n; i++) tmp += (long long int)(n - 1 - i) * A[i];
  for (int i = 1; i < n; i++) SM[i] = SM[i - 1] + A[n - 1 - i];
  scanf("%d", &q);
  while (q--) {
    int k;
    scanf("%d", &k);
    if (k == 1) {
      cout << tmp << " ";
      continue;
    }
    long long int sum = 0;
    long long int f = (long long int)k;
    long long int cnt = 1;
    long long int s = (long long int)k;
    while (1) {
      if (s - f >= n - 1) break;
      sum += cnt * (SM[min(s, (long long int)(n - 1))] - SM[max(s - f, 0ll)]);
      f *= (long long int)k;
      s += f;
      cnt++;
    }
    cout << sum << " ";
  }
  return 0;
}
