#K82212. Minimum Operations to Equal Array Elements

    ID: 35926 Type: Default 1000ms 256MiB

Minimum Operations to Equal Array Elements

Minimum Operations to Equal Array Elements

You are given an integer n and a sequence of n integers. In one operation, you can adjust an element's value (the exact operation is described below) with the aim of making all elements equal.

In this problem, the operation is defined in a very simple way: if all the elements are already equal, no operation is required (the answer is 0). Otherwise, the answer is n - 1. Mathematically, the answer is given by:

\( ans = \begin{cases} 0, & \text{if } a_1 = a_2 = \cdots = a_n, \\ n-1, & \text{otherwise.} \end{cases} \)

This means if the sequence is not uniform, you will need exactly n-1 operations to equalize the elements.

Note that although this may appear trivial, understanding the conditions under which no operations are necessary is key in many algorithmic problems.

inputFormat

The input is given via standard input. The first line contains an integer T representing the number of test cases. Each test case is described in two lines:

  • The first line contains an integer n which is 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 a single integer on a new line: the minimum number of operations required to make all elements equal.

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

2 0

</p>