func_code_string: #include <bits/stdc++.h>   using namespace std;   long long n, q, i, s1, s[100010], a[100010], k[100010], t, at, dp, sum, now;   bool cmp(long long a, long long b) { return a > b; }   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     cin >> q;     for (i = 0; i < q; i++) {       cin >> k[i];     }     sort(a, a + n, cmp);     s[0] = 0;     for (i = 0; i < n; i++) {       s[i + 1] = s[i] + a[i];     }     s1 = 0;     for (i = 0; i < n; i++) {       s1 += a[i] * i;     }     for (i = 0; i < q; i++) {       if (i != 0) cout <<    ;       if (k[i] == 1) {         cout << s1;         continue;       }       t = 1;       dp = 1;       now = k[i];       sum = 0;       while (t + now < n) {         at = s[t + now] - s[t];         at = at * dp;         sum += at;         t = t + now;         now = now * k[i];         dp++;       }       at = s[n] - s[t];       at = at * dp;       sum += at;       cout << sum;     }     cout << endl;     return 0;   }   