#C6882. Minimum Removals for Distinct Elements

    ID: 50691 Type: Default 1000ms 256MiB

Minimum Removals for Distinct Elements

Minimum Removals for Distinct Elements

You are given T test cases. In each test case, you are provided with an integer M and an array of M integers. Your task is to determine the minimum number of elements to remove from the array so that all the remaining elements are distinct.

If the array already contains all distinct elements, the answer is 0.
Formally, for an array \(N\) of length \(M\), let the frequency of each element be \(f(x)\). The number of removals required is:

[ \text{removals} = \sum_{x} (f(x) - 1) \quad \text{for every } f(x) > 0, ]

Output the result for each test case on a separate line.

inputFormat

The first line contains a single integer T representing the number of test cases. For each test case, the first line contains an integer M denoting the number of elements in the array. The second line contains M space-separated integers representing the array elements. When M is 0, the second line will be empty.

outputFormat

For each test case, output a single integer on a new line representing the minimum number of removals required so that all the elements of the array are distinct.

## sample
3
4
1 2 2 3
5
4 4 4 4 4
3
1 2 3
1

4 0

</p>