#include <bits/stdc++.h>
using namespace std;
vector<int> v;
vector<long long> sum;
int main() {
  int n, q, k, x;
  long long k1 = 0;
  scanf(" %d", &n);
  for (int i = 0; i < n; i++) {
    scanf(" %d", &x);
    v.push_back(x);
  }
  sort(v.rbegin(), v.rend());
  sum.push_back(v[0]);
  for (int i = 1; i < n; i++) {
    sum.push_back(sum[i - 1] + v[i]);
    k1 += (long long)v[i] * i;
  }
  scanf(" %d", &q);
  while (q--) {
    scanf(" %d", &k);
    if (k >= 2) {
      int pos, d;
      long long result = 0, mul = 1;
      for (pos = d = 1; mul * k + pos < n; pos += mul)
        result += (sum[pos + (mul *= k) - 1] - sum[pos - 1]) * d++;
      result += (sum[n - 1] - sum[pos - 1]) * d;
      printf("%I64d%c", result, q ? ' ' : '\n');
    } else
      printf("%I64d%c", k1, q ? ' ' : '\n');
  }
  return 0;
}
