#include <bits/stdc++.h>
using namespace std;
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
const long long int MAXN = 1e5 + 10;
long long int a[MAXN];
long long int prefix[MAXN];
void solve() {
  long long int n;
  cin >> n;
  for (long long int i = (1); i <= (n); ++i) cin >> a[i];
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  for (long long int i = (1); i <= (n); ++i) prefix[i] = prefix[i - 1] + a[i];
  long long int ans_1 = 0;
  for (long long int i = (1); i <= (n); ++i) ans_1 = ans_1 + a[i] * (i - 1);
  long long int q;
  cin >> q;
  for (long long int i = (1); i <= (q); ++i) {
    long long int k;
    cin >> k;
    if (k == 1)
      cout << ans_1 << " ";
    else {
      long long int ans = 0;
      long long int mul = 1;
      long long int add = 1;
      long long int idx = 1;
      while (1) {
        ans += (prefix[min(add * k + idx, n)] - prefix[idx]) * mul;
        idx = add * k + idx;
        add = add * k;
        mul++;
        if (idx >= n) break;
      }
      cout << ans << " ";
    }
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  t = 1;
  for (long long int i = (1); i <= (t); ++i) {
    solve();
  }
}
