Problem A

Statement
Copy Copied
A. Make All Equaltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a cyclic array $$$a_1, a_2, \ldots, a_n$$$.You can perform the following operation on $$$a$$$ at most $$$n - 1$$$ times:  Let $$$m$$$ be the current size of $$$a$$$, you can choose any two adjacent elements where the previous one is no greater than the latter one (In particular, $$$a_m$$$ and $$$a_1$$$ are adjacent and $$$a_m$$$ is the previous one), and delete exactly one of them. In other words, choose an integer $$$i$$$ ($$$1 \leq i \leq m$$$) where $$$a_i \leq a_{(i \bmod m) + 1}$$$ holds, and delete exactly one of $$$a_i$$$ or $$$a_{(i \bmod m) + 1}$$$ from $$$a$$$. Your goal is to find the minimum number of operations needed to make all elements in $$$a$$$ equal.InputEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). The description of the test cases follows.The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the length of the array $$$a$$$.The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — the elements of array $$$a$$$.OutputFor each test case, output a single line containing an integer: the minimum number of operations needed to make all elements in $$$a$$$ equal.ExampleInput71131 2 331 2 255 4 3 2 161 1 2 2 3 388 7 6 3 8 7 6 361 1 4 5 1 4Output0
2
1
4
4
6
3
NoteIn the first test case, there is only one element in $$$a$$$, so we can't do any operation.In the second test case, we can perform the following operations to make all elements in $$$a$$$ equal:  choose $$$i = 2$$$, delete $$$a_3$$$, then $$$a$$$ would become $$$[1, 2]$$$.  choose $$$i = 1$$$, delete $$$a_1$$$, then $$$a$$$ would become $$$[2]$$$. It can be proven that we can't make all elements in $$$a$$$ equal using fewer than $$$2$$$ operations, so the answer is $$$2$$$.