#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 1;
int n, q;
long long int ary[N];
long long int sum[N];
long long int cost[N];
long long int ans[N];
void read();
void initialize();
void readQueries();
void print();
void initializeSum();
void initializeAns();
int main() {
  read();
  sort(ary + 1, ary + n + 1);
  initialize();
  readQueries();
  print();
  return 0;
}
void read() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> ary[i];
}
void initialize() {
  initializeSum();
  initializeAns();
}
void readQueries() {
  cin >> q;
  for (int i = 0; i < q; i++) {
    int k;
    cin >> k;
    ans[i] = cost[k];
  }
}
void print() {
  for (int i = 0; i < q; i++) cout << ans[i] << ' ';
  cout << endl;
}
void initializeSum() {
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + ary[i];
}
void initializeAns() {
  for (int k = 1; k <= N; k++) {
    if (k < n) {
      long long int ind = n;
      long long int num = 1;
      while (ind - num > 0) {
        ind -= num;
        cost[k] += sum[ind];
        num *= k;
      }
    } else
      cost[k] = cost[k - 1];
  }
}
