#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  long long sum[n + 1];
  sum[0] = 0;
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + arr[i - 1];
  int q;
  cin >> q;
  long long pos = n - 1;
  long long fact = 0;
  long long sol[100001];
  memset(sol, -1, sizeof(sol));
  long long var;
  for (int i = 0; i < q; i++) {
    fact = 0;
    pos = n - 1;
    cin >> var;
    if (sol[var] != -1) {
      cout << sol[var] << ' ';
      continue;
    }
    long long x = 1;
    long long res = 0;
    while (pos >= 0) {
      res += fact * (sum[pos + 1] - sum[max(0LL, pos - x + 1)]);
      pos = pos - x;
      x *= var;
      fact++;
    }
    cout << (sol[var] = res) << ' ';
  }
}
