#K33072. Minimum Operations to Equalize Array

    ID: 25006 Type: Default 1000ms 256MiB

Minimum Operations to Equalize Array

Minimum Operations to Equalize Array

You are given an array of n integers. In a single operation, you can choose an element and change it to any other integer. The goal is to make all elements in the array equal using the minimum number of operations.

The optimal strategy is to change all elements to the value that occurs most frequently. Let \(f\) be the frequency of the most common element. Then the minimum number of operations required is \(n - f\).

inputFormat

The input is given via standard input (stdin). The first line contains an integer \(T\), representing the number of test cases. Each test case is described as follows:

  • The first line contains a single integer \(n\) – the number of elements in the array.
  • The second line contains \(n\) space-separated integers representing the array elements.

outputFormat

For each test case, output the minimum number of operations needed to make all the elements equal. Print each result on a new line via standard output (stdout).

## sample
1
3
1 1 1
0

</p>