#include <bits/stdc++.h>
using namespace std;
int in[101000], n, q, k;
long long sum[101000];
bool cmp(int a, int b) { return a > b; }
int main() {
  cin >> n;
  for (int i = 0; i < (n); i++) cin >> in[i];
  sort(in, in + n, cmp);
  cin >> q;
  sum[0] = 0;
  for (int i = 0; i < (n); i++) sum[i + 1] = sum[i] + in[i];
  long long a1 = 0;
  for (int i = (1); i <= (n - 1); i++) a1 += i * 1LL * in[i];
  while (q--) {
    cin >> k;
    if (k == 1)
      cout << a1;
    else {
      int np = 1;
      long long s = k, ans = 0;
      int cnt = 1;
      while (np < n) {
        long long tnp = np + s;
        if (tnp > n) tnp = n;
        ans += cnt * (sum[tnp] - sum[np]);
        np = tnp;
        s *= k;
        cnt++;
      }
      cout << ans;
    }
    printf("%c", ((!q) ? '\n' : ' '));
  }
}
