#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 22;
int n, q;
long long data[maxn];
long long ans;
long long jie;
long long step, k;
long long miao[maxn];
bool used[maxn];
int main() {
  scanf("%d", &n);
  data[0] = 0;
  for (int i = 1; i <= n; ++i) scanf("%I64d", &data[i]);
  sort(data + 1, data + 1 + n);
  for (int i = 2; i <= n; ++i) data[i] += data[i - 1];
  scanf("%d", &q);
  memset(used, false, sizeof(used));
  while (q--) {
    scanf("%I64d", &k);
    if (used[k]) {
      printf("%I64d ", miao[k]);
      continue;
    }
    long long kk = k;
    ans = 0;
    step = n - 1;
    jie = 1;
    while (step > 0) {
      if (step - kk >= 0)
        ans += jie * (data[step] - data[step - kk]);
      else
        ans += jie * data[step];
      step -= kk;
      ++jie;
      kk *= k;
    }
    printf("%I64d ", ans);
    used[k] = true;
    miao[k] = ans;
  }
  return 0;
}
