#include <bits/stdc++.h>
using namespace std;
long long MaxVal;
long long n;
vector<long long> v;
vector<long long> tree;
long long read(long long idx) {
  long long sum = 0;
  if (idx > MaxVal) idx = MaxVal;
  while (idx > 0) {
    sum += tree[idx];
    idx -= (idx & -idx);
  }
  return sum;
}
void update(long long idx, long long val) {
  while (idx <= MaxVal) {
    tree[idx] += val;
    idx += (idx & -idx);
  }
}
int main() {
  map<long long, long long> m;
  cin >> n;
  MaxVal = n - 1;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    v.push_back(a);
    tree.push_back(0);
  }
  sort((v).begin(), (v).end());
  reverse((v).begin(), (v).end());
  v.erase(v.begin());
  for (int i = 0; i < n; i++) {
    update(i + 1, v[i]);
  }
  long long q;
  cin >> q;
  while (q--) {
    long long t;
    cin >> t;
    if (q == 0 && m.find(t) != m.end()) {
      cout << m[t] << " ";
      continue;
    }
    if (m.find(t) != m.end()) {
      cout << m[t] << " ";
      continue;
    }
    if (q == 0 && v.size() == 0) {
      cout << "0";
      continue;
    }
    if (v.size() == 0) {
      cout << "0 ";
      continue;
    }
    long long lo = 0;
    long long sum = t;
    long long mul = 1;
    long long ans = 0;
    while (lo < MaxVal) {
      long long hi = lo + sum;
      ans += mul * (read(hi) - read(lo));
      mul++;
      sum *= t;
      lo = hi;
    }
    m[t] = ans;
    if (q == 0)
      cout << ans;
    else
      cout << ans << " ";
  }
}
