#include <bits/stdc++.h>
using namespace std;
int totalCases, testNum;
vector<int> arr;
int N, Q;
vector<int> K;
long long prefs[1 << 17];
long long one;
long long query(int i, long long j) {
  j = min(N - 1ll, j);
  return prefs[j + 1] - prefs[i];
}
void preprocess() { one = -1; }
bool input() {
  scanf("%d", &N);
  arr.resize(N);
  for (int i = 0; i < N; i++) scanf("%d", &arr[i]);
  scanf("%d", &Q);
  K.resize(Q);
  for (int i = 0; i < Q; i++) scanf("%d", &K[i]);
  return true;
}
long long f(int k) {
  long long start = 0;
  long long dep = 0;
  long long gpsz = 1;
  long long tot = 0;
  for (; start < N; dep++, gpsz *= k) {
    tot += dep * query(start, start + gpsz - 1);
    start += gpsz;
  }
  return tot;
}
void solve() {
  sort(arr.rbegin(), arr.rend());
  prefs[0] = 0;
  for (int i = 0; i < N; i++) prefs[i + 1] = prefs[i] + arr[i];
  for (int i = 0; i < Q; i++) {
    if (K[i] == 1) {
      if (one == -1) one = f(1);
      cout << one << " ";
    } else
      cout << f(K[i]) << " ";
  }
  cout << endl;
}
int main() {
  preprocess();
  totalCases = 1;
  for (testNum = 1; testNum <= totalCases; testNum++) {
    if (!input()) break;
    solve();
  }
}
