#include <bits/stdc++.h>
using namespace std;
int angka[100001];
long long total[100001];
int main() {
  int banyak, minta;
  scanf("%d", &banyak);
  for (int i = 1; i <= banyak; ++i) scanf("%d", &angka[i]);
  sort(angka + 1, angka + banyak + 1);
  long long sial = 0;
  for (int i = 1; i <= banyak; ++i) {
    total[i] = total[i - 1] + (long long)angka[banyak - i + 1];
    sial += (long long)angka[banyak - i + 1] * (long long)(i - 1);
  }
  scanf("%d", &minta);
  for (int i = 1; i <= minta; ++i) {
    if (i > 1) printf(" ");
    long long mau;
    long long jawab = 0;
    cin >> mau;
    if (mau > 1) {
      long long ambil = 1;
      long long cur = 1;
      long long kali = 0;
      while (cur <= (long long)banyak) {
        long long akhir = cur + ambil - 1LL;
        if (akhir > banyak) akhir = banyak;
        jawab += kali * (total[akhir] - total[cur - 1LL]);
        cur += ambil;
        ambil *= mau;
        ++kali;
      }
    } else
      jawab = sial;
    cout << jawab;
  }
  printf("\n");
  return 0;
}
