#include <bits/stdc++.h>
const long long inf = 1e18 + 44;
const int MAX = 3e5 + 9;
const long long MOD = 1e9 + 7;
const int TOT_PRIMES = 1e6 + 9;
const int MAX_A = 71;
const int LN = 20;
const double eps = 1e-1;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long arr[n + 1];
  memset(arr, 0, sizeof(arr));
  for (int i = 1; i <= n; i++) cin >> arr[i];
  sort(arr + 1, arr + n + 1);
  long long pre[n + 1];
  long long sum = 0;
  memset(pre, 0, sizeof(pre));
  for (int i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + arr[i];
    sum = sum + pre[i];
  }
  int q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    if (k == 1)
      cout << sum - pre[n] << " ";
    else {
      long long ans = 0;
      long long t = 1;
      for (long long j = n - 1; j > 0; j -= t) {
        ans = ans + pre[j];
        t = t * k;
      }
      cout << ans << " ";
    }
  }
}
