#include <bits/stdc++.h>
using namespace std;
long long ac[101010];
int main() {
  int n, q, vet[101010];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &vet[i]);
  sort(vet, vet + n);
  reverse(vet, vet + n);
  ac[0] = vet[0];
  for (int i = 1; i < n; i++) ac[i] = ac[i - 1] + vet[i];
  long long k1 = 0;
  for (int j = 1; j < n; j++) k1 += (long long)j * vet[j];
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int k;
    long long ans = 0, ult = 1, cnt = 1;
    scanf("%d", &k);
    if (k == 1) {
      cout << k1 << " ";
      continue;
    }
    for (int j = 1; ult < n; j++) {
      cnt *= k;
      ans += j * (ac[min(ult + cnt, (long long)n) - 1] - ac[ult - 1]);
      ult += cnt;
    }
    cout << ans << " ";
  }
}
