#include <bits/stdc++.h>
using namespace std;
template <class T>
inline int size(const T &c) {
  return c.size();
}
template <class T>
inline int length(const T &c) {
  return c.length();
}
template <class T>
inline void RP(T &a) {
  cin >> a.first >> a.second;
}
void RI(int &a) { scanf("%d", &a); }
void RI(int &a, int &b) {
  RI(a);
  RI(b);
}
void RI(long long &a) { scanf("%I64d", &a); }
void RI(long long &a, long long &b) {
  RI(a);
  RI(b);
}
void WI(int a) { printf("%d ", a); }
void WI(int a, int b) {
  WI(a);
  WI(b);
}
void WI(long long a) { printf("%I64d ", a); }
void WI(long long a, long long b) {
  WI(a);
  WI(b);
}
pair<int, int> operator+(const pair<int, int> a, const pair<int, int> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<int, int> operator-(const pair<int, int> a, const pair<int, int> b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
pair<int, int> operator*(const pair<int, int> a, const int b) {
  return make_pair(a.first * b, a.second * b);
}
pair<int, int> operator/(const pair<int, int> a, const int b) {
  return make_pair(a.first / b, a.second / b);
}
pair<double, double> operator+(const pair<double, double> a,
                               const pair<double, double> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<double, double> operator-(const pair<double, double> a,
                               const pair<double, double> b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
pair<double, double> operator*(const pair<double, double> a, const double b) {
  return make_pair(a.first * b, a.second * b);
}
pair<double, double> operator/(const pair<double, double> a, const double b) {
  return make_pair(a.first / b, a.second / b);
}
const double eps = 1e-8;
double dist(pair<double, double> a, pair<double, double> b) {
  return sqrt(a.first - b.first * a.first - b.first + a.second -
              b.second * a.second - b.second);
}
int n, q;
int a[100010];
long long s[100010];
int main() {
  RI(n);
  for (int i = (1), _b = (n); i <= _b; i++) RI(a[i]);
  sort(a + 1, a + n + 1, greater<int>());
  s[0] = 0;
  long long r1 = 0;
  for (int i = (1), _b = (n); i <= _b; i++) s[i] = s[i - 1] + a[i];
  for (int i = (1), _b = (n); i <= _b; i++) r1 += s[n] - s[i];
  RI(q);
  for (int i = (1), _b = (q); i <= _b; i++) {
    int k;
    RI(k);
    if (k == 1) {
      WI(r1);
      continue;
    }
    long long ret = 0;
    for (long long v = 1, kk = k; v < n; v += kk, kk *= k) ret += s[n] - s[v];
    WI(ret);
  }
  return 0;
}
