#include <bits/stdc++.h>
using namespace std;
int comp(long long a, long long b) { return a > b; }
long long arr[100000], cdf[100000];
int main() {
  int i, m;
  long long k, n;
  cin >> n;
  cin >> arr[0];
  for (i = 1; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n, comp);
  cdf[0] = arr[0];
  for (i = 1; i < n; i++) {
    cdf[i] = arr[i] + cdf[i - 1];
  }
  cin >> m;
  long long rrr = 0;
  for (i = 1; i < n; i++) {
    rrr += arr[i] * i;
  }
  int ll;
  for (ll = 0; ll < m; ll++) {
    cin >> k;
    long long sum = 0LL;
    if (k == 1)
      cout << rrr << " ";
    else {
      int mm;
      long long as, t = 1;
      for (as = 1, mm = 1; as < n; as = as + t, mm++) {
        t *= k;
        sum += (cdf[min(as + t - 1, n - 1)] - cdf[as - 1]) * mm;
      }
      cout << sum << " ";
    }
  }
  cout << "\n";
  return 0;
}
