#include <bits/stdc++.h>
using namespace std;
const int maxn = 111111;
int a[maxn];
long long s[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  s[0] = 0;
  long long ans1 = 0;
  for (int i = 0; i < n - 1; ++i) {
    s[i + 1] = s[i] + a[i];
    ans1 += s[i + 1];
  }
  int q;
  for (scanf("%d", &q); q-- > 0;) {
    int k;
    scanf("%d", &k);
    if (k == 1) {
      cout << ans1 << (q == 0 ? '\n' : ' ');
    } else {
      long long ans = 0;
      long long base = 1;
      for (long long at = n - 1; at > 0; base *= k, at -= base) {
        ans += s[at];
      }
      cout << ans << (q == 0 ? '\n' : ' ');
    }
  }
}
