Chef has an array A of length N.

In one operation, Chef can remove any one element from the array. 

Determine the minimum number of operations required to make all the elements same.

------ Input Format ------ 

- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a single integer N —the length of Array A.
- Next line contains N space-separated integers A_{1}, A_{2}, A_{3}, \dots, A_{N} - denoting the array A.

------ Output Format ------ 

For each test case, output the minimum number of operations required to make all the elements same.

------ Constraints ------ 

$1 ≤ T ≤ 4000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ A_{i} ≤ N$
- Sum of $N$ over all test cases do not exceed $3 \cdot 10^{5}$

----- Sample Input 1 ------ 
4
3
3 3 3
6
1 3 2 1 2 2
4
1 2 1 2
5
1 3 2 4 5

----- Sample Output 1 ------ 
0
3
2
4

----- explanation 1 ------ 
Test case $1$: All the elements are already same. Thus we need to perform zero operations.

Test case $2$: We remove the elements $A_{1}, A_{2},$ and $A_{4}$ using three operations. The array becomes $[2, 2, 2]$ where all elements are same.

Test case $3$: We remove the elements $A_{1}$ and $A_{3}$ using two operations. The array becomes $[2, 2]$ where all elements are same.

Test case $4$: We remove the elements $A_{1}, A_{2}, A_{3},$ and $A_{4}$ using four operations. The array becomes $[5]$.

Difficulty: EASY

Solutions:
from collections import Counter
n = int(input())
for j in range(n):
	n1 = int(input())
	l = list(map(int, input().split()))
	count = Counter(l)
	x = [int(x) for x in count.values()]
	print(len(l) - max(x))


from collections import Counter
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	b = Counter(l)
	m = [int(x) for x in b.values()]
	print(len(l) - max(m))


import statistics as st
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(len(l) - l.count(st.mode(l)))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = {}
	for j in a:
		if j in s:
			s[j] += 1
		else:
			s[j] = 1
	print(n - max(s.values()))


from collections import Counter
t = int(input())
for i in range(t):
	n = int(input())
	a = Counter(list(map(int, input().split()))).most_common(1)[0][1]
	print(n - a)


from collections import Counter
t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	b = Counter(a)
	max_item = max(b.values())
	print(n - max_item)


from collections import Counter
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = Counter(l)
	for (a, b) in c.most_common(1):
		m = b
	print(n - m)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	d = 0
	c = 1
	for i in range(n - 1):
		if arr[i] != arr[i + 1]:
			d = max(c, d)
			c = 1
		else:
			c += 1
	d = max(c, d)
	print(n - d)


from collections import Counter
s = int(input())
for i in range(s):
	a = int(input())
	b = list(map(int, input().split(' ')))
	b = dict(Counter(b))
	c = max(b.values())
	print(a - c)


t = int(input())
for i in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	d = {}
	for num in s:
		if num in d:
			d[num] = d[num] + 1
		else:
			d[num] = 1
	print(n - max(d.values()))


t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	d = {}
	for i in arr:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	print(n - max(d.values()))
	t -= 1


t = int(input())
while t:
	n = int(input())
	arr = [int(j) for j in input().split()]
	b = [0] * (max(arr) + 1)
	for j in range(n):
		b[arr[j]] += 1
	print(n - max(b))
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	c = dict()
	for a in A:
		if a in c:
			c[a] += 1
		else:
			c[a] = 1
	count = max(c.values())
	print(n - count)


t = int(input())
for y in range(t):
	n = int(input())
	series = [int(k) for k in input().split()]
	freq = [0] * (max(series) + 1)
	maxval = int(0)
	for i in range(n):
		freq[series[i]] += 1
	maxval = max(freq)
	print(n - maxval)


t = int(input())
while t > 0:
	x = int(input())
	arr = list(map(int, input().split()))
	b = [0] * (max(arr) + 1)
	for j in range(x):
		b[arr[j]] += 1
	y = 0
	for j in range(max(arr) + 1):
		y += b[j]
	print(y - max(b))
	t -= 1


from collections import Counter
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	o = Counter(a)
	k = o.values()
	g = list(k)
	e = len(a) - max(g)
	print(e)


from collections import Counter
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ob = Counter(l)
	x = [int(x) for x in ob.values()]
	print(len(l) - max(x))


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	se = Counter(li)
	lis = [int(x) for x in se.values()]
	print(n - max(lis))


import statistics
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	mode = statistics.mode(a)
	coun = a.count(mode)
	print(n - coun)


for dff in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = {}
	for i in a:
		if i not in c:
			c[i] = 1
		else:
			c[i] += 1
	m = max(c.values())
	print(n - m)


import statistics
from statistics import mode

def most_common(my_list):
	return mode(my_list)
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if n == len(set(l)):
		print(n - 1)
	else:
		t = most_common(l)
		print(abs(n - l.count(t)))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	freq = {}
	for i in arr:
		freq[i] = freq.get(i, 0) + 1
	max_freq = max(freq.values())
	print(n - max_freq)


from collections import Counter
for i in range(int(input())):
	N = int(input())
	li = [int(x) for x in input().split(' ', N) if int(x) >= 1 and int(x) <= N]
	x = Counter(li)
	y = [int(y) for y in x.values()]
	print(len(li) - max(y))


from collections import Counter
for i in range(int(input())):
	N = input()
	array = list(map(int, input().split()))
	c = Counter(array)
	print(len(array) - max(c.values()))


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = Counter(a)
	print(n - max(d.values()))


from collections import Counter
t = int(input(''))
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = Counter(a)
	k = c.values()
	print(sum(k) - max(k))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = dict()
	for i in a:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	print(n - max(d.values()))


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	f = [0 for j in range(n + 1)]
	for j in l:
		f[j] += 1
	print(n - max(f))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in l:
		if i in d.keys():
			d[i] = d[i] + 1
		else:
			d.update({i: 1})
	m = 0
	for i in d.values():
		if i > m:
			m = i
	print(n - m)


t = int(input())
for i in range(0, t):
	n = int(input())
	array = input().split(' ')
	map(int, array)
	dictionary = {}
	for j in range(0, len(array)):
		if array[j] not in dictionary:
			dictionary[array[j]] = 1
		else:
			dictionary[array[j]] += 1
	print(len(array) - int(dictionary[max(dictionary, key=dictionary.get)]))


from collections import Counter
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s = list(map(int, input().split()))
	c = Counter(s)
	v = max(c.values())
	print(n - v)


import statistics
for _ in range(int(input())):
	N = int(input())
	list1 = list(map(int, input().split()))
	max_element = statistics.mode(list1)
	final_out = len(list(filter(lambda x: max_element != x, list1)))
	print(final_out)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	freq = {}
	for i in a:
		if i in freq:
			freq[i] += 1
		else:
			freq[i] = 1
	max_freq = max(freq.values())
	min_ops = n - max_freq
	print(min_ops)


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	line = input()
	words = line.split()
	cnt = defaultdict(int)
	for num in words:
		cnt[num] += 1
	print(len(words) - max(cnt.values()))


t = int(input())
for _ in range(t):
	n = int(input())
	line = input()
	words = line.split()
	nums = [int(w) for w in words]
	cnt = {}
	for num in words:
		if num in cnt:
			cnt[num] += 1
		else:
			cnt[num] = 1
	print(len(nums) - max(cnt.values()))


from collections import Counter
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = Counter(l)
	a = [int(x) for x in s.values()]
	print(n - max(a))


from statistics import mode
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	res = mode(a)
	print(n - a.count(res))


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	x = 0
	m = 0
	for i in range(n - 1):
		if a[i] == a[i + 1]:
			x += 1
		else:
			x = 0
		m = max(m, x)
	print(n - m - 1)


from statistics import mode
T = int(input())
for t in range(0, T):
	n = int(input())
	A = list(map(int, input().split()))
	m = mode(A)
	n_most_comm = A.count(m)
	min_ops = len(A) - n_most_comm
	print(min_ops)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in l:
		d[i] = d.get(i, 0) + 1
	print(n - max(d.values()))


from collections import Counter
for i in range(int(input())):
	z = int(input())
	x = list(map(int, input().split()))
	c = 0
	m = Counter(x)
	c = max(m.values())
	print(len(x) - c)


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	m = 0
	C = Counter(l)
	m = max(C.values())
	print(n - m)


from collections import Counter
a = int(input())
for i in range(a):
	b = int(input())
	f = list(map(int, input().split()))
	d = Counter(f)
	t = [int(p) for p in d.values()]
	print(b - max(t))


from statistics import mode
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = mode(a)
	c2 = a.count(c)
	print(n - c2)


from statistics import mode
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	z = set(a)
	mod = mode(a)
	repeat = a.count(mod)
	if len(z) == len(a):
		print(len(a) - 1)
	else:
		print(len(a) - repeat)


from collections import Counter
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = Counter(l)
	print(n - max(d.values()))


from statistics import mode
t = int(input())
for i in range(t):
	a = int(input())
	b = list(map(int, input().split()))
	l = mode(b)
	print(a - b.count(l))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = dict()
	for x in a:
		d[x] = d.get(x, 0) + 1
	l = sorted(d.items(), key=lambda x: x[1], reverse=True)
	print(n - l[0][1])


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	s = {}
	for i in l:
		if i not in s:
			s[i] = 1
		else:
			s[i] = s[i] + 1
	x = list(s.values())
	y = max(x)
	if y > 1:
		print(len(l) - y)
	else:
		print(len(l) - 1)


for i in range(int(input())):
	l = int(input())
	li = list(map(int, input().split()))
	li = sorted(li)
	c = 0
	max = 0
	for t in range(l):
		if li[t] == li[t - 1]:
			c = c + 1
		else:
			c = 1
		if max < c:
			max = c
	print(l - max)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	elements_count = {}
	for element in arr:
		if element in elements_count:
			elements_count[element] += 1
		else:
			elements_count[element] = 1
	j = max(elements_count.values())
	print(n - j)


t = int(input())
while t:
	n = int(input())
	a = [int(i) for i in input().split()]
	freq = {}
	for i in a:
		if i in freq:
			freq[i] += 1
		else:
			freq[i] = 1
	maxelm = max(freq, key=lambda x: freq[x])
	steps = 0
	for i in freq.keys():
		if i != maxelm:
			steps += freq[i]
	print(steps)
	t -= 1


n = int(input())
for j in range(n):
	p = int(input())
	l = list(map(int, input().split()))
	k = {}
	for i in l:
		if i in k:
			k[i] = k[i] + 1
		else:
			k[i] = 1
	x = list(k.values())
	y = max(x)
	if y > 1:
		print(len(l) - y)
	else:
		print(len(l) - 1)


from collections import Counter
t = int(input())
for tc in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k = Counter(a)
	print(n - max(k.values()))


for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	x = {}
	for i in b:
		if i in x:
			x[i] += 1
		else:
			x[i] = 1
	y = 0
	for j in x:
		if x[j] > y:
			y = x[j]
	print(a - y)


t = int(input().strip())
for i in range(t):
	n = int(input().strip())
	v = list(map(int, input().strip().split()))
	mp = {}
	s = set()
	for j in range(n):
		s.add(v[j])
		if v[j] in mp:
			mp[v[j]] += 1
		else:
			mp[v[j]] = 1
	maxx = 0
	if len(s) == n:
		print(n - 1)
	else:
		for (key, value) in mp.items():
			maxx = max(maxx, value)
		print(n - maxx)