#include <bits/stdc++.h>
using namespace std;
int n, m;
int arr[100100];
long long sum[100100];
map<int, long long> ans;
int main() {
  cin >> n;
  for (int i = 0, _i = (n); i < _i; ++i) {
    cin >> arr[i];
  }
  sort(arr, arr + n, greater<int>());
  for (int i = 0, _i = (n); i < _i; ++i) {
    sum[i + 1] = sum[i] + arr[i];
  }
  cin >> m;
  for (int i = 0, _i = (m); i < _i; ++i) {
    int q;
    cin >> q;
    if (ans.find(q) != ans.end()) {
      cout << ans[q] << ' ';
      continue;
    }
    long long &res = ans[q] = 0;
    long long curi = 0, curl = 1;
    int cnt = 0;
    while (curi < n) {
      res += (sum[min(curi + curl, (long long)n)] - sum[curi]) * cnt;
      curi += curl;
      curl *= q;
      cnt++;
    }
    cout << res << ' ';
  }
}
