#include <bits/stdc++.h>
using namespace std;
long long int x, y;
long long int gcd(long long int a, long long int b) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long int gc = gcd(b % a, a);
  long long int temp;
  temp = x;
  x = y - (b / a) * temp;
  y = temp;
  return gc;
}
long long int a[200005];
long long int val[200005];
long long int ser[200005];
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  long long int n, q, i, j;
  cin >> n;
  long long int k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  cin >> q;
  ser[0] = a[0];
  for (i = 1; i < n; i++) {
    ser[i] = ser[i - 1] + a[i];
  }
  val[n] = ser[n - 2];
  for (k = 1; k < n; k++) {
    val[k] = 0;
    j = 1;
    for (i = n - 2; i >= 0; i -= j) {
      val[k] += ser[i];
      j *= k;
    }
  }
  for (j = 0; j < q; j++) {
    cin >> i;
    if (i <= n)
      cout << val[i] << " ";
    else
      cout << ser[n - 2] << " ";
  }
}
