#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;

    vector<long long> a(n + 1), prefix(n + 1, 0);

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    // Sort the array
    sort(a.begin() + 1, a.begin() + n + 1);

    // Build prefix sum
    for (int i = 1; i <= n; i++) {
        prefix[i] = prefix[i - 1] + a[i];
    }

    long long totalSum = prefix[n];

    int q;
    cin >> q;

    while (q--) {
        long long target;
        cin >> target;

        // Binary search: last index with a[i] <= target
        int low = 1, high = n, g = 0;

        while (low <= high) {
            int mid = low + (high - low) / 2;
            if (a[mid] <= target) {
                g = mid;
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }

        // Left part cost
        long long left_cost = target * g - prefix[g];

        // Right part cost
        long long right_cost =
            (totalSum - prefix[g]) - target * (n - g);

        long long ans = left_cost + right_cost;

        cout << ans << "\n";
    }

    return 0;
}
