#include <bits/stdc++.h>
using namespace std;
long long res[100010], sum[100010];
int n, q;
vector<int> vet;
long long f(int v) {
  if (res[v] != -1) return res[v];
  long long acm = 0;
  int aux = 1;
  for (int i = vet.size() - 2; i >= 0 && aux > 0; i -= aux) {
    acm += sum[i];
    aux *= (long long)v;
  }
  return res[v] = acm;
}
int main() {
  cin >> n;
  vet = vector<int>(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &vet[i]);
  }
  memset(res, -1, sizeof(res));
  memset(sum, 0, sizeof(sum));
  sort(vet.begin(), vet.end());
  for (int i = 0; i < n; i++) {
    if (i) sum[i] = sum[i - 1];
    sum[i] += (long long)vet[i];
  }
  cin >> q;
  for (int x, i = 0; i < q; i++) {
    scanf("%d", &x);
    cout << f(x) << endl;
  }
  return 0;
}
