#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    vector<int> a(n);
    vector<long long> c(n);
    vector<long long> A(n);
    for (int i = (0); i <= ((n)-1); ++i) scanf("%d", &a[i]);
    sort((a).begin(), (a).end());
    long long s = 0, SA = 0;
    for (int i = (0); i <= ((n)-1); ++i)
      s += a[i], c[i] = s, A[i] = (long long)a[i] * (long long)(n - 1 - i),
                 SA += A[i];
    int q;
    scanf("%d", &q);
    for (int i = (0); i <= ((q)-1); ++i) {
      int Q;
      scanf("%d", &Q);
      if (Q > 1) {
        long long C = 0;
        long long R = n - 1;
        long long ki = Q;
        while (R > 0) {
          C += c[R - 1];
          R -= ki;
          ki *= Q;
        }
        cout << C << endl;
      } else {
        cout << SA << endl;
      }
    }
  }
  return 0;
}
