#include <bits/stdc++.h>
using namespace std;
const int IINF = 1 << 28;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
long long n, q;
long long a[100005], k[100005], sum[100005], memo[100005];
long long solve(int num) {
  if (memo[num]) return memo[num];
  long long ans = 0;
  if (num == 1) {
    for (int i = 0; i < n; ++i) {
      ans += a[i] * i;
    }
  } else {
    long long cur = 0, base = 1, depth = 0;
    while (cur < n) {
      ans += (sum[min(cur + base, n)] - sum[cur]) * depth;
      cur += base;
      base *= num;
      depth++;
    }
  }
  return memo[num] = ans;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n, greater<int>());
  for (int i = 0; i < n; ++i) {
    sum[i + 1] = sum[i] + a[i];
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> k[i];
  }
  for (int i = 0; i < q; ++i) {
    cout << solve(k[i]) << (i == q - 1 ? "\n" : " ");
  }
}
