#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[100010];
int b;
long long s[100010], sum[100010];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    s[i] = s[i - 1] + a[i];
    sum[i] = sum[i - 1] + (n - i) * a[i];
  }
  cin >> m;
  long long ans = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d", &b);
    if (b == 1) {
      cout << sum[n] << " ";
      continue;
    }
    ans = 0;
    int k = 1;
    long long j, t = b;
    for (j = n - t - 1; j > 0; j -= t) {
      ans += k * (s[j + t] - s[j]);
      t *= b;
      k++;
    }
    ans += k * s[j + t];
    cout << ans << " ";
  }
  cout << endl;
  return 0;
}
