#include <bits/stdc++.h>
using namespace std;
long long a[100007];
long long q[100007];
long long sum[100007];
int main() {
  int n, m;
  cin >> n;
  for (int(i) = (int)(0); (i) < (int)(n); ++(i)) cin >> a[i];
  cin >> m;
  for (int(i) = (int)(0); (i) < (int)(m); ++(i)) cin >> q[i];
  sort(a, a + n);
  memset(sum, 0, sizeof(sum));
  sum[0] = a[0];
  for (int(i) = (int)(1); (i) < (int)(n); ++(i)) sum[i] = sum[i - 1] + a[i];
  long long sum1 = 0;
  for (int i = n - 2, k = 1; i >= 0; --i, ++k) sum1 += a[i] * k;
  for (int(i) = (int)(0); (i) < (int)(m); ++(i)) {
    if (q[i] == 1)
      cout << sum1 << " ";
    else {
      long long ans = 0;
      long long d = q[i];
      for (long long j = n - 2, k = 1; j >= 0; ++k) {
        ans += (sum[j] - (j >= d ? sum[j - d] : 0)) * k;
        j -= d;
        d *= q[i];
      }
      cout << ans << " ";
    }
  }
  return 0;
}
