import java.util.*;
public class Main {
// Binary search: find last index where value <= target
static int findLastSmallerOrEqual(long[] arr, long target) {
int left = 0, right = arr.length - 1;
int index = -1;
while (left <= right) {
int mid = (left + right) / 2;
if (arr[mid] <= target) {
index = mid; // valid index
left = mid + 1; // move right to find last
} else {
right = mid - 1;
}
}
return index;
}
public static void main
(String[] args
) {
Scanner sc
= new Scanner
(System.
in);
// Size of array
int n = sc.nextInt();
// Input array
long[] numbers = new long[n];
for (int i = 0; i < n; i++) {
numbers[i] = sc.nextLong();
}
// Sort array
// Prefix sum
long[] prefixSum = new long[n + 1];
for (int i = 1; i <= n; i++) {
prefixSum[i] = prefixSum[i - 1] + numbers[i - 1];
}
long totalSum = prefixSum[n];
// Number of queries
int queries = sc.nextInt();
// Process each query
for (int q = 0; q < queries; q++) {
long target = sc.nextLong();
// Binary search index
int lastIndex = findLastSmallerOrEqual(numbers, target);
// Count of elements <= target
int leftCount = lastIndex + 1;
// Operations to increase smaller elements
long leftOps = target * leftCount - prefixSum[leftCount];
// Operations to decrease bigger elements
long rightOps = (totalSum - prefixSum[leftCount])
- target * (n - leftCount);
// Total operations
long totalOperations = leftOps + rightOps;
System.
out.
println(totalOperations
); }
sc.close();
}
}