#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int sum[100001];
  long long int ar[n];
  sum[0] = 0;
  for (int i = 1; i <= n; i++) cin >> ar[i];
  sort(ar + 1, ar + n + 1);
  reverse(ar + 1, ar + n + 1);
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + ar[i];
  long long int ans[100001];
  for (long long int i = 1; i <= 100000; i++) {
    ans[i] = 0;
    long long int p = 1;
    long long int a = 1;
    long long int m = 1;
    while (p <= n) {
      ans[i] += m * (sum[min(p + a * i, n)] - sum[p]);
      m++;
      p += a * i;
      a *= i;
    }
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int x;
    cin >> x;
    cout << ans[x] << endl;
  }
  return 0;
}
