#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[400000];
long long b[400000];
long long jie(int k) {
  long long h = 0;
  long long x = 1;
  long long d = 1;
  for (int i = 1; x < n; i++) {
    h += b[n] - b[x];
    d *= k;
    x = x + d;
  }
  return h;
}
int main(int argc, char *argv[]) {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) b[i] = b[i - 1] + a[n - i + 1];
  long long u = 0;
  for (int i = n; i > 1; i--) u += b[n] - b[i - 1];
  cin >> m;
  for (int i = 0; i < m; i++) {
    int v;
    scanf("%d", &v);
    if (v == 1)
      cout << u << " ";
    else
      cout << jie(v) << " ";
  }
  cout << endl;
  return 0;
}
