#include <bits/stdc++.h>
using namespace std;
int N, M;
int a[100000 + 5];
long long sum[100000 + 5], zz = -1;
long long query(int n) {
  long long ans = 0;
  if (n == 1) {
    if (zz != -1) return zz;
    for (int i = 0; i < N; i++) ans += 1LL * i * a[i];
    zz = ans;
    return ans;
  }
  long long now = 0, dth = 0;
  for (long long k = 1; now < N; k *= n, dth++) {
    int tmp = min(now + k - 1, 1LL * N - 1);
    ans += (sum[tmp + 1] - sum[now]) * dth;
    now = tmp + 1;
  }
  return ans;
}
int ans[100000 + 5];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", &a[i]);
  sort(a, a + N);
  reverse(a, a + N);
  for (int i = 1; i <= N; i++) sum[i] = sum[i - 1] + a[i - 1];
  scanf("%d", &M);
  for (int i = 0, _x; i < M; i++) {
    scanf("%d", &_x);
    printf("%I64d\n", query(_x));
  }
  return 0;
}
