#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1e5 + 5;
LL n;
LL in[N], sum[N];
LL f(LL a, LL b) {
  b = min(b, n - 1LL);
  return sum[b] - sum[a - 1];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> in[i];
  }
  sort(in, in + n, greater<LL>());
  for (int i = 0; i < n; i++) {
    sum[i] = in[i];
    if (i) sum[i] += sum[i - 1];
  }
  LL res1 = 0;
  for (int i = 1; i < n; i++) {
    res1 += in[i] * i;
  }
  int q;
  cin >> q;
  while (q--) {
    int k;
    cin >> k;
    if (k == 1)
      cout << res1 << "\n";
    else {
      LL s = 0;
      LL sz = 1;
      for (LL i = 1, j = 1; i < n; i += sz, j++) {
        sz *= k;
        s += f(i, i + sz - 1) * j;
      }
      cout << s << "\n";
    }
  }
}
