#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
int n, q;
long long spex;
long long a[MAX_N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    a[i] += a[i - 1];
    spex += a[i] * (i != n);
  }
  for (scanf("%d", &q); q--;) {
    long long k, s = 0;
    scanf("%I64d", &k);
    if (k == 1) {
      printf("%I64d\n", spex);
      continue;
    }
    for (long long step = 0, i = n, mul = 1; i > 0;
         i -= mul, mul *= k, step++) {
      long long j = max(0ll, i - mul);
      s += (a[i] - a[j]) * step;
    }
    printf("%I64d\n", s);
  }
}
