We are asked: given an array a of n integers (1 ≤ a_i ≤ 100), we can perform an operation any number of times: choose some subsequence (any subset of indices, preserving order but we don't need to care), compute average AVG = (sum of chosen elements) / (size of subsequence). Then delete from that subsequence all elements that are strictly larger than AVG. That means we remove those elements from the array entirely? The operation says: "choose some subsequence of a and delete every element from it which is strictly larger than AVG". It implies we delete those elements from the array; they are removed. The other elements in the subsequence (those ≤ AVG) remain. The operation can be applied multiple times. We need to maximize total number of deletions.
We need to output the maximum number of elements that can be deleted overall.
Observations: The operation deletes elements that are strictly greater than the average of the chosen subsequence. If we pick a subsequence, the average is something. Typically, the elements that are strictly larger than the average are "above average". After deletion, the remaining elements are those ≤ average.
We can repeat the operation. The goal is to delete as many elements as possible. Possibly we can eventually delete all elements except maybe the smallest ones? Let's explore.
We need to characterize which elements can be deleted.
Consider the set of values. The operation deletes an element only if we can find a subsequence that includes that element, and the average of the subsequence is less than that element (strictly). Since average is ≤ max of the elements, to have an element > average, we need other smaller elements to bring down the average.
The operation is similar to: we can remove an element x if there exists a multiset S of elements (the subsequence) containing x such that the average of S is < x. Equivalently, sum(S) / |S| < x => sum(S) < x * |S| => sum(S - {x}) < x*(|S|-1). So the sum of the other elements must be less than x times (|S|-1). If we include many small numbers, we can achieve that.
But note that we can apply multiple operations, so we can delete elements in stages.
Simplify: The operation can be applied to any subsequence, and we delete all elements > average. So effectively, in a single operation we can delete any subset of elements (subject to being able to be chosen with some other elements) as long as they are > average of that chosen set. But careful: The deletion applies to the chosen subsequence; we cannot delete elements not in the subsequence. So to delete an element x, we must include it in a subsequence, compute average, and if x > avg, it gets deleted. Also, other elements in that subsequence that are > avg also get deleted. So it's like we can pick a set, and then delete all elements in that set that are above the average.
We can perform multiple operations. So we might delete some elements, then later use the remaining elements to delete more.
We want to maximize deletions.
Think about invariants: The operation deletes only elements that are strictly larger than the average of the chosen set. Could we ever delete an element that is the minimum? If the minimum is included, average could be less than it? No, because minimum ≤ average (since average is at least the minimum). Actually average can be less than the minimum? Not possible: the minimum is ≤ each element, so the average is at least the minimum. But could it be strictly less? No: average = sum / k ≥ min * k / k = min. So average ≥ min. So the minimum element is never strictly greater than average. Could it be equal? If all elements equal, average = that value, then no element is strictly larger than average. So the minimum element(s) can never be deleted. So at least one copy of the minimum value will remain. So maximum deletions cannot exceed n - (number of minimum elements?) Actually maybe we could delete all but the minimum? Possibly yes: if there are multiple minima, maybe we can delete all others? But can we delete all non-minimum elements? Let's test: Suppose array = [1,2,3]. Minimum =1. Can we delete 2 and 3? We need to design operations. First, pick subsequence [1,3]. Average =2. 3 >2, so 3 deleted. Then array becomes [1,2]. Now pick subsequence [1,2]. Average =1.5. 2 >1.5, so 2 deleted. So we can delete both non-minimum elements, leaving only 1. So all except min can be deleted. But in this case there is only one min. So we deleted 2 out of 3. So maximum deletions = n - count_of_min? Possibly. However, consider [1,1,2]. Minimum =1, count=2. Can we delete the 2? Yes: pick [1,1,2] average =4/3 ≈1.333, 2>1.333 => delete 2. So we delete the 2, leaving both 1's. So we deleted 1 element, but n - count_min = 1. That works. Could we delete one of the 1's? Possibly? But 1 is min, cannot be > avg. So cannot delete 1's. So maximum deletions = n - (number of minimum elements). But is it always possible to delete all elements that are not equal to the global minimum? Let's test more complicated examples.
Consider [1,100,100,100,...]. We have many large numbers and one small 1. Can we delete all the 100s? We need to construct operations. Let's think: If we take the whole array, average ≈ (1+100k)/(1+k). For large k, average close to 100 but slightly less. Actually with one 1 and many 100's, the average is (1+100k)/(k+1). This is less than 100 because 1 is smaller. For k=1, average = 50.5, 100 >50.5 => deleted. For k=2, average = (1+200)/3 ≈ 67, 100>67 => both 100's would be deleted? Actually all elements > avg are deleted. Since both 100's >67, they would both be deleted. But also the 1 is not > avg. So operation on whole array would delete all 100's at once! Let's verify: For array of length n, if there is at least one min value less than the max, then the average is less than the max. However, it might not be less than all the non-min values if some non-min values are less than average? Actually if the min is much smaller, the average might be less than many of the larger values. But could it be that some non-min values are ≤ average? Possibly if there are values close to the average. For example: [2,3,4]. Min=2. Average=3. So 2<3, 3 is equal? 3 is not strictly greater, so 3 is not deleted. 4>3 is deleted. So after operation, we get [2,3]. The 3 remains. So not all non-min were deleted; 3 survived because it was exactly average? Actually 3 is not > average, it is equal. So equal to average is not deleted. So we need to be careful: Only strictly larger than average are deleted. So elements equal to the average survive.
So in [1,100,100], average = (1+200)/3 = 201/3=67. So 100 > 67, both 100's are > average, so they get deleted. So after one operation, we have [1]. So all non-min deleted. That's good.
In [2,3,4], average=3, 3 is not >3, so it remains. So we have leftover 2 and 3. Then can we delete the 3 later? With remaining [2,3], average=2.5, 3 > 2.5 => delete 3. So we can delete 3 in a second operation. So eventually only 2 remains. So we can delete all non-min by possibly multiple steps. So seems that all non-min can be deleted.
But wait: Could there be a scenario where some non-min cannot be deleted because it is always at most average when combined with any subset? For an element x > min, we need to find some subset (including x) whose average is less than x. Since we have the global min m, we can always take subset {m, x}. The average = (m+x)/2. Since m < x, (m+x)/2 < (x+x)/2 = x, and also > m. So average is less than x. Thus x > average, so x will be deleted. So for any x > m, we can delete it in one operation by pairing with one copy of the minimum element. But careful: The operation deletes all elements > average. So if we choose subsequence {m, x}, average = (m+x)/2, x > average (since (m+x)/2 < x). m is not > average (since m <= average? Let's check: m <= average? Since m is the smallest, m <= average. Could m be > average? No, average is at least m. Since m < x, average = (m+x)/2 > (m+m)/2 = m, so average > m. So m < average? Actually m < (m+x)/2 because x > m. So m < average, so m is not > average. So only x gets deleted. So by picking subsequence consisting of one min and one x, we delete x. So any x > m can be deleted in one operation, as long as there is at least one minimum element present. But note: After some deletions, the minimum element(s) remain (since they cannot be deleted). So we can always use one min element to delete any other element individually. However, we need to consider that we might want to delete multiple elements at once, but individually is fine.
Thus, it appears that we can delete every element that is not equal to the minimum value, provided we have at least one minimum element to use as the "anchor". Since we cannot delete the minimum itself, the maximum number of deletions is n - (count of minimum elements). However, is there any scenario where an element > m cannot be deleted because the operation requires selecting a subsequence; but we can always select that element and one min element (provided the min hasn't been deleted, and we can choose them regardless of order). So yes, we can do it. But we must ensure that the operation does not inadvertently delete the min? No, min not > avg. So it remains.
But wait, the operation is defined as: choose some subsequence and delete every element from it which is strictly larger than AVG. It says delete from the array the elements that are strictly larger than AVG, which are part of the chosen subsequence. So if we choose {m, x}, we delete x (since x > avg). The min m is not deleted. So it's fine.
Thus, maximum deletions = total number of elements - (number of occurrences of the minimum value). However, is there any nuance? Could we also delete some minimum elements if we use a different approach? For a minimum element m, can we ever have m > average? As argued, average of any set containing m is at least m, since average = sum/k >= min. So m cannot be > average, only ≥. If all elements equal m, average = m, so no element > avg. So minimum elements are safe; they can never be deleted. So they will always remain. So the maximum number of deletable elements is exactly the count of elements strictly greater than the global minimum.
But wait, look at sample test cases:
Test case 1: n=6, array: 1 1 1 2 2 3. Minimum =1, count=3. So predicted max deletions = 6-3=3. Output is 3. Yes.
Test case 2: 9 9 9 9 9 9. All equal, min=9, count=6 => deletions = 0. Output 0. Yes.
Test case 3: 6 4 1 1 4 1. Minimum =1, count? array: 6,4,1,1,4,1 => three 1's. So predicted deletions = 6-3=3. Output 3. Yes.
So indeed the answer is simply number of elements greater than the minimum.
But wait, are there any constraints where an element > min may not be deletable because we might not have a minimum element available at the time? But we start with all elements, we have min elements. We can delete elements one by one: for each element > min, we can select it together with a min element and delete it. After we delete some > min elements, the min elements remain. So we can repeat. So all > min can be deleted. So indeed.
But is there any scenario where we could delete more than that? Could we also delete some minimum elements by using a set where the average is less than the minimum? That's impossible because average can't be less than min. So no.
Thus answer is n - count(min).
But is there any twist? Let's double-check the operation definition: "choose some subsequence of a and delete every element from it which is strictly larger than AVG, where AVG is the average of the numbers in the chosen subsequence." So we delete elements from the subsequence that are strictly larger than the average. The subsequence can have multiple elements. Could we possibly delete an element that is equal to the min but not the global min? Suppose there are two values, m and M > m. The min is m. Consider a subsequence that contains only elements equal to M? Then the average is M, and nothing is strictly larger. So no. If we have a mix, the min could be > average? No. So min always ≤ average, so not deleted.
Thus the solution is straightforward.
Now confirm constraints: n up to 100, t up to 100, values up to 100. So we can compute min, count min, answer = n - count(min).
Therefore, for each test case, output n - (frequency of minimum element).
We need to read t test cases, for each, read n and array.
Implement.
But let's also think about why the problem statement gave more complex examples and notes? Possibly to mislead. But answer is simple.
Double-check edge cases: n=1. Then array has one element, min count=1, deletions = 0. Can we delete that element? If we choose subsequence containing that element, average = that element, no element strictly larger, so cannot delete. So 0 is correct.
n=2: e.g., [1,2]. min count=1, deletions=1. Can we delete 2? Choose subsequence [1,2], avg=1.5, 2>1.5 => delete 2. Yes.
[2,2] => deletions=0.
[2,3,4] min=2 count=1 => deletions=2. We saw we can delete 4 then 3, or both? Actually can we delete both in one operation? If we choose [2,3,4], avg=3, 4>3 deleted, 3 not >3, 2 not >3. So only 4 deleted. Then second op delete 3. So total 2. Works.
[2,2,3] min=2 count=2 => deletions=1. Can we delete the 3? Use [2,3] with a 2. avg=2.5, 3>2.5 => delete 3. So yes.
Thus correct.
So solution: For each test case, find min, count min, answer = n - count_min.
But wait, could there be a scenario where we might need to delete elements in a certain order because after deleting some elements we might lose the ability to delete others? For instance, suppose we have [1, 5, 5] and we delete 5's by pairing with 1. If we delete one 5, the other 5 remains; we still have 1, so we can delete the second 5. So fine.
But what about [1, 2, 100]? Delete 100 with [1,100] => delete 100. Then [1,2] => delete 2. So all >1 deleted.
Now consider if we had a situation where there is no min element? There is always a min. So fine.
Thus answer is trivial.
But why would Codeforces problem (I think it's from Codeforces Round #722 Div.2 problem A?) be that trivial? It's problem A, so indeed it's simple. The examples and statement maybe to confuse.
Thus we can produce solution.
We'll implement: For each test case, read n, read list a, compute min_val = min(a), count_min = a.count(min_val), answer = n - count_min, print answer.
But hold on: There's maybe a nuance: the operation deletes elements from the array, and we can apply it multiple times. However, after we delete some elements, the array size reduces. But the argument that we can delete any >min using a min holds as long as min remains. Since min remains, we can always use it. So okay.
But is there any possibility that we could delete some min elements if we involve more than one min? Suppose we have [1,1,2]. The mins are 1 and 1. Could we ever delete a 1? If we choose subsequence [1,2], avg=1.5, 1 is not > avg. If we choose [1,1,2], avg=4/3≈1.333, 1 not > avg. If we choose [1,1], avg=1, no element >1. So can't delete 1. So mins are safe.
Thus answer stands.
Therefore solution: For each test case, output n - freq(min).
Now produce final answer with Python code.
But we also need to consider that the problem might have trick: if the minimum appears only once, we can delete all others; but if it appears multiple times, we cannot delete any of them, so answer = n - count(min). That's exactly.
Thus code:
def solve():
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
mn = min(a)
cnt = a.count(mn)
print(n - cnt)
That's it.
But check constraints: t up to 100, n up to 100. So fine.
We should output each answer on separate line.
Thus final. ```python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
t = int(next(it))
out_lines = []
for _ in range(t):
n = int(next(it))
a = [int(next(it)) for _ in range(n)]
mn = min(a)
cnt_min = a.count(mn)
out_lines.append(str(n - cnt_min))
sys.stdout.write("\n".join(out_lines))
if name == "main":
solve()