There are n pictures delivered for the new exhibition. The i-th painting has beauty a_{i}. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.

We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1), such that a_{i} + 1 > a_{i}.


-----Input-----

The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.

The second line contains the sequence a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 1000), where a_{i} means the beauty of the i-th painting.


-----Output-----

Print one integer — the maximum possible number of neighbouring pairs, such that a_{i} + 1 > a_{i}, after the optimal rearrangement.


-----Examples-----
Input
5
20 30 10 50 40

Output
4

Input
4
200 100 100 200

Output
2



-----Note-----

In the first sample, the optimal order is: 10, 20, 30, 40, 50.

In the second sample, the optimal order is: 100, 200, 100, 200.

Source: codeforces | Difficulty: EASY
Tags: Sorting

Greedy algorithms


Solutions:
from sys import *
inp = lambda : stdin.readline()

def main():
	(n, y, an) = (int(inp()), 0, 0)
	l = [int(i) for i in inp().split()]
	a = [0 for i in range(1001)]
	for i in l:
		a[i] += 1
	ans = []
	while y < n:
		for i in range(1001):
			if a[i]:
				a[i] -= 1
				ans.append(i)
				y += 1
	for i in range(1, len(ans)):
		if ans[i] > ans[i - 1]:
			an += 1
	print(an)
main()


n = int(input())
A = input().split()
A = [int(x) for x in A]
X = []
while len(A) > 0:
	B = []
	for item in A:
		if item not in B:
			B.append(item)
			A[A.index(item)] = 0
	A = [x for x in A if x > 0]
	B.sort()
	for i in B:
		X.append(i)
k = 0
for i in range(len(X) - 1):
	if X[i] < X[i + 1]:
		k += 1
print(k)


n = int(input())
lst = list(map(int, input().strip().split(' ')))
lst.sort()
l = [[lst[0]]]
for i in range(1, n):
	j = 0
	while True:
		if j == len(l):
			l.append([lst[i]])
			break
		elif l[j][-1] != lst[i]:
			l[j].append(lst[i])
			break
		else:
			j += 1
s = 0
for i in range(len(l)):
	s += len(l[i]) - 1
print(s)


n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == n:
	print(n - 1)
else:
	t = 0
	while a:
		t += len(set(a)) - 1
		for x in set(a):
			a.remove(x)
	print(t)


from collections import defaultdict
n = int(input())
ar = list(map(int, input().split()))
ar.sort()
chk = defaultdict(lambda : 0)
ans = []
for i in range(0, n):
	if not chk[i]:
		ans.append(ar[i])
		cur = ar[i]
		chk[i] = 1
		for j in range(i + 1, n):
			if not chk[j] and ar[j] > cur:
				ans.append(ar[j])
				chk[j] = 1
				cur = ar[j]
(cur, anss) = (ar[0], 0)
for i in range(1, n):
	if ans[i] > cur:
		anss += 1
		cur = ans[i]
	else:
		cur = ans[i]
print(anss)


from collections import Counter as c
n = int(input())
l = list(input().split())
z = c(l)
z = z.values()
print(n - max(z))


n = int(input())
L = list(map(int, input().split()))
Count = [0] * 1001
for l in L:
	Count[l] += 1
ans = 0
ZeroOfCount = Count.count(0)
while ZeroOfCount < len(Count):
	min_val = float('inf')
	for c in Count:
		if c == 0:
			pass
		else:
			min_val = min(min_val, c)
	CountPerLine = 0
	for i in range(len(Count)):
		if Count[i] >= min_val:
			Count[i] -= min_val
			CountPerLine += 1
			if Count[i] == 0:
				ZeroOfCount += 1
	if CountPerLine > 1:
		ans += min_val * (CountPerLine - 1)
print(ans)


from collections import Counter

def paintings(n, A):
	F = Counter(A).most_common()
	p = 0
	k = 0
	while F:
		k += (len(F) - 1) * (F[-1][1] - p)
		p = F[-1][1]
		while F and F[-1][1] == p:
			F.pop()
	return k

def main():
	n = readint()
	A = readinti()
	print(paintings(n, A))
import sys

def readint():
	return int(input())

def readinti():
	return map(int, input().split())

def readintl():
	return list(readinti())

def readintll(k):
	return [readintl() for _ in range(k)]

def log(*args, **kwargs):
	print(*args, **kwargs, file=sys.stderr)
main()


input()
s = [[] for _ in range(1010)]

def add(el, t=0):
	if len(s[t]) == 0 or s[t][-1] != el:
		s[t].append(el)
	else:
		add(el, t + 1)
for i in sorted(map(int, input().split())):
	add(i)
print(sum(map(lambda n: max(0, len(n) - 1), s)))


n = int(input())
a = [int(x) for x in input().split()]
vis = [0] * 1005
ans = 0
for i in range(n):
	vis[a[i]] += 1
while n:
	num = 0
	for i in range(1, 1001):
		if vis[i]:
			vis[i] -= 1
			num += 1
			n -= 1
	ans += num - 1
print(ans)


n = int(input())
z = list(map(int, input().split()))
z.sort()
x = []
y = []
for i in range(1005):
	x.append(0)
	y.append(0)
for i in range(n):
	x[z[i]] += 1
	y[x[z[i]]] += 1
result = 0
for i in range(1005):
	if y[i] != 0:
		result += y[i] - 1
print(result)


def arr_inp():
	return [int(x) for x in input().split()]
(n, a, out) = (int(input()), arr_inp(), 0)
a_copy = a.copy()
while max(a_copy) > min(a_copy):
	(distinct, c) = ([], -1)
	for i in a:
		if i not in distinct:
			distinct.append(i)
			a_copy.remove(i)
			c += 1
	out += c
	a = a_copy.copy()
	if a_copy == []:
		break
print(out)


t = input
p = print
r = range
n = int(t())
a = list(map(int, t().split()))
from collections import Counter
s = Counter(a)
p(n - max(s.values()))


n = int(input())
a = input().split()
distinct = []
for p in a:
	assigned = False
	for i in range(len(distinct)):
		if p not in distinct[i]:
			distinct[i].append(p)
			assigned = True
			break
	if not assigned:
		distinct.append([p])
ans = 0
for sets in distinct:
	ans += len(sets) - 1
print(ans)


n = int(input())
a = (int(x) for x in input().split())
d = {}
maxvalue = 1
for x in a:
	d[x] = d.get(x, 0) + 1
	if d[x] > maxvalue:
		maxvalue = d[x]
print(n - maxvalue)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
b = set(a)
f = {}
for i in b:
	f[i] = a.count(i)
for (key, value) in f.items():
	continue
x = 0
y = 0
for i in f:
	x += min(y, f[i])
	y = max(y, f[i])
print(x)


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


import math, re, sys, string, operator, functools, fractions, collections
sys.setrecursionlimit(10 ** 7)
RI = lambda x=' ': list(map(int, input().split(x)))
RS = lambda x=' ': input().rstrip().split(x)
dX = [-1, 1, 0, 0, -1, 1, -1, 1]
dY = [0, 0, -1, 1, 1, -1, -1, 1]
mod = int(1000000000.0 + 7)
eps = 1e-06
pi = math.acos(-1.0)
MAX = 1010
n = RI()[0]
cnt = [0] * MAX
a = RI()
val = 0
for i in a:
	cnt[i] += 1
	val = max(cnt[i], val)
print(n - val)


n = int(input())
t = list(map(int, input().split()))
f = [[] for k in range(1001)]
u = 0
for j in range(n):
	for k in f:
		if t[j] not in k:
			k.append(t[j])
			break
for k in f:
	if len(k) > 0:
		u += len(k) - 1
	else:
		break
print(u)


n = int(input().strip())
d = {}
ans = 0
for i in input().strip().split():
	if i in d:
		d[i] = d[i] + 1
	else:
		d[i] = 1
while d:
	l = list(d.keys())
	for i in l:
		if d[i] == 1:
			del d[i]
		else:
			d[i] = d[i] - 1
	ans = ans + len(l) - 1
print(ans)


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
latest_added = -1
ans = []
anus = 0
while len(ans) != len(l):
	latest_added = -1
	for i in range(len(l)):
		if l[i] > latest_added and l[i] != latest_added:
			ans.append(l[i])
			latest_added = l[i]
			l[i] = -2
for i in range(1, len(ans)):
	if ans[i - 1] < ans[i]:
		anus += 1
print(anus)


n = int(input())
a = sorted([int(i) for i in input().split()], reverse=True)
res = []
d = {}
for i in a:
	try:
		d[i] += 1
	except KeyError:
		d[i] = 1
tmp = []
for i in range(max(d.values())):
	tmp.append([])
for i in d.keys():
	for j in range(d[i]):
		tmp[j].append(i)
for i in range(max(d.values())):
	res += sorted(tmp[i])
count = 0
for i in range(1, n):
	if res[i] > res[i - 1]:
		count += 1
print(count)


n = int(input())
a = list(map(int, input().split()))
a.sort()
b = []
for i in set(a):
	b.append(a.count(i))
k = 0
while len(b) > 1:
	k += len(b) - 1
	for i in range(len(b)):
		b[i] -= 1
	while b.count(0) > 0:
		b.remove(0)
print(k)


import math
from decimal import Decimal

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)
(n, a) = na()
d = {}
for i in a:
	d[i] = d.get(i, 0) + 1
print(n - max(d.values()))


n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
k = 0
while len(set(l)) > 1:
	t = 1
	r = k
	for i in range(n):
		if t == 1:
			if l[i] != 0:
				g = l[i]
				l[i] = 0
				t = 2
		elif l[i] > g:
			g = l[i]
			l[i] = 0
			k = k + 1
	if r == k:
		break
print(k)


n = int(input())
x = input().split()
a = {}
m = 0
for i in x:
	if not i in a:
		a[i] = 1
	else:
		a[i] += 1
	m = max(m, a[i])
print(n - m)


n = int(input())
l = [int(i) for i in input().split()]
print(n - max((l.count(i) for i in l)))


def seq(a, new):
	global count
	for i in range(1, len(a)):
		if a[i] == a[i - 1]:
			new.append(a[i])
	if len(a) > 1:
		count += len(a) - len(new) - 1
	if len(new) == 0:
		return
	else:
		a = new[:]
		new = []
		seq(a, new)
n = int(input())
a = list(map(int, input().split()))
a.sort()
new = []
count = 0
seq(a, new)
print(count)


def lmap():
	return list(map(int, input().split()))

def mmap():
	return map(int, input().split())
n = int(input())
w = lmap()
dup = list(set(w))
ma = 0
for i in dup:
	cnt = w.count(i)
	if cnt > ma:
		ma = cnt
print(n - ma)


from collections import Counter

def read_input():
	N = int(input())
	A = [int(i) for i in input().strip().split()]
	return A

def solution(A):
	c = Counter(A)
	ans = 0
	stop = False
	while not stop:
		stop = True
		count = 0
		for key in c:
			if c[key]:
				count += 1
				stop = False
				c[key] -= 1
		if count:
			ans += count - 1
	return ans
A = read_input()
print(solution(A))


n = int(input())
a = [int(i) for i in input().split(' ')]
a.sort()
kq = 0
b = [0] * n
c = [0] * n
c[0] = a[0]
b[0] = 1
for i in range(1, n):
	ok = 0
	for j in range(n):
		if b[j] == 0 and a[j] > c[i - 1]:
			c[i] = a[j]
			b[j] = 1
			ok = 1
			break
	if ok == 0:
		for j in range(n):
			if b[j] == 0:
				c[i] = a[j]
				b[j] = 1
				break
for i in range(n - 1):
	if c[i] < c[i + 1]:
		kq = kq + 1
print(kq)


a = int(input())
l = [0 for i in range(1001)]
for i in input().split():
	l[int(i)] += 1
print(a - max(l))


n = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
while a:
	b = [a[0]]
	c = []
	for i in a[1:]:
		if i > b[-1]:
			b.append(i)
			ans += 1
		else:
			c.append(i)
	a = c
print(ans)


n = int(input())
a = [0] * 1001
for x in input().split():
	a[int(x)] += 1
count = 0
for i in range(n):
	flag = False
	for j in range(1, 1001):
		if a[j]:
			if flag:
				count += 1
			a[j] -= 1
			flag = True
print(count)


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr
from bisect import bisect_left as bl, bisect_right as br

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binarytodecimal(n):
	return int(n, 2)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def ceildiv(x, y):
	return (x + y - 1) // y

def di():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))
nn = int(input())
a = li()
a = get_frequency(a)
kk = list(a.values())
kk.sort()
n = len(kk)
ans = 0
for i in range(n):
	temp = kk[i]
	if temp:
		ans += temp * (n - i - 1)
		for j in range(i, n):
			kk[j] -= temp
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
r = [0 for i in range(0, 1001)]
f = [0 for i in range(0, 1001)]
b = [a[0]]
r[a[0]] = 1
f[a[0]] = 0
for i in range(1, n):
	r[a[i]] += 1
	if a[i] != a[i - 1]:
		f[a[i]] = i
		b.append(a[i])
s = r[a[0]]
c = 0
for i in range(1, len(b)):
	c += min(r[b[i]], s)
	s = max(r[b[i]], s)
print(c)


from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]
c = Counter(a)
print(n - c.most_common(1)[0][1])


import collections

def count(l):
	s = 0
	for i in range(len(l) - 1):
		if l[i] < l[i + 1]:
			s += 1
	return s

def repeatedList(l):
	r = []
	cnt = collections.Counter(l)
	for i in list(set(l)):
		if cnt[i] >= 2:
			r.extend([i] * (cnt[i] - 1))
	return r

def solve(a, n):
	global c
	c += count(sorted(list(set(a))))
	if len(repeatedList(a)) <= 1:
		return c
	return solve(repeatedList(a), n)
c = 0
N = int(input())
A = [int(i) for i in input().split()]
print(solve(A, N))


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in set(a):
	d[i] = a.count(i)
count = 0
while True:
	count1 = 0
	for i in d:
		if d[i] != 0:
			d[i] -= 1
			count1 += 1
	if count1 >= 2:
		count += count1 - 1
	if count1 == 0:
		break
print(count)


n = int(input())
a = list(map(int, input().split()))
a1 = sorted(a)
cnt = 0
for i in a1:
	if a1[cnt] < i:
		cnt += 1
print(cnt)


n = int(input())
m = map(int, input().split(' '))
d = {}
for i in m:
	if i not in d:
		d[i] = 0
	d[i] += 1
value_d = {}
for k in d:
	p = d[k]
	while p > 0:
		if p not in value_d:
			value_d[p] = 0
		value_d[p] += 1
		p -= 1
mx = max(value_d)
ans = 0
while mx > 0:
	ans += max(value_d[mx] - 1, 0)
	mx -= 1
print(ans)


from sys import stdin, stdout

def inp():
	return stdin.readline()

def out(s):
	return stdout.write(str(s))

def handle(a):
	tmp = []
	hc = a[:]
	for i in range(len(a)):
		if i == len(a) - 1:
			tmp.append(a[i])
			hc.remove(a[i])
			break
		elif a[i] != a[i + 1]:
			tmp.append(a[i])
			hc.remove(a[i])
	return (len(tmp) - 1, hc)
n = int(inp())
a = list(map(int, inp().split()))
a.sort()
ac = a[:]
ans = 0
while len(set(ac)) > 1:
	(t, ac) = handle(ac)
	ans += t
out(ans)


n = int(input())
a = list(map(int, input().split()))
c = dict()
ret = 0
for v in a:
	c[v] = c.get(v, 0) + 1
for i in range(1, n + 1):
	tmp = 0
	for v in c.values():
		tmp += v >= i
	if tmp == 0:
		break
	ret += tmp - 1
print(ret)


d = {}
m = int(input())
(x, y) = (1, 0)
l = []
for i in map(int, input().split()):
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
for i in d:
	l.append(i)
l.sort()
while x > 0:
	x = 0
	for i in l:
		if d[i] > 0:
			d[i] -= 1
			x += 1
	if x:
		y += x - 1
print(y)


(n, a, v) = (int(input()), sorted(map(int, input().split())), 0)
for ai in a:
	if ai > a[v]:
		v += 1
print(v)


import collections
n = int(input())
nums = list(map(int, input().split()))
cnt = collections.Counter(nums)
ans = 0
while cnt:
	minc = min(cnt.values())
	ans += minc * (len(cnt) - 1)
	keys = list(cnt.keys())
	for c in keys:
		cnt[c] -= minc
		if not cnt[c]:
			del cnt[c]
print(ans)


n = int(input())
a = list(map(int, input().split()))
freq = {}
table = [0] * 1001
for x in a:
	if x in freq:
		freq[x] += 1
		table[freq[x]] += 1
	else:
		freq[x] = 1
		table[1] += 1
ans = 0
for x in table:
	if x >= 2:
		ans += x - 1
print(ans)


from collections import defaultdict
(N, Count) = (int(input()), 0)
MyDict = defaultdict(int)
for i in list(map(int, input().split())):
	MyDict[i] += 1
Check = True
while Check:
	Check = False
	for i in MyDict.keys():
		if MyDict[i] > 0:
			Check = True
			MyDict[i] -= 1
			Count += 1
	Count -= 1
print(Count + 1)


from collections import Counter
n = int(input())
y = 0
z = 0
for i in range(1):
	x = [int(x) for x in input().split()]
	a = sorted(x)
	c = Counter(a).most_common(1)[0][1]
	print(n - c)


from collections import *
ans = 0
c = Counter()
n = int(input())
for x in input().split():
	c[int(x)] += 1
while len(c) > 1:
	ans += len(c) - 1
	for x in set(c):
		c[x] -= 1
		if c[x] == 0:
			del c[x]
print(ans)


n = int(input())
li = map(int, input().split())
h = {}
for i in li:
	if i in h:
		h[i] += 1
	else:
		h[i] = 1
li = []
for i in h:
	li.append(h[i])
li = sorted(li)
new = []
new.append(li[0])
for i in range(1, len(li) - 1):
	new.append(li[i] - li[i - 1])
ans = 0
if len(li) == 1:
	print(0)
	exit()
for i in range(len(new)):
	ans += new[i] * (len(new) - i)
print(ans)


n = int(input())
arr = [0 for i in range(1001)]
for i in input().split():
	arr[int(i)] += 1
print(n - max(arr))


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
if len(set(l)) == 1:
	print(0)
	exit(0)
v = Counter(l)
v2 = v.values()
v2 = sorted(v2)
r3 = sum(v2) - v2[-1]
print(r3)


def main():
	from collections import Counter
	(n, cnt) = (int(input()), Counter(map(int, input().split())))
	r = pool = 0
	for (_, y) in sorted(cnt.items()):
		t = min(y, pool)
		r += t
		pool += y - t
	print(r)
main()


n = int(input())
a = sorted([int(x) for x in input().split()])
c = dict()
for x in a:
	c[x] = c[x] + 1 if x in c else 1
uniq = sorted(c.keys())
C = 0
while n > 0:
	t = 0
	for u in uniq:
		if c[u] == 0:
			continue
		c[u] -= 1
		n -= 1
		t += 1
	C += t - 1
print(C)


cnt = lambda s, x: s.count(x)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
dgl = lambda : list(map(int, input()))
il = lambda : list(map(int, input().split()))
n = ii()
l = sorted(il())
b = [0] * n
c = 0
for i in range(n):
	for j in range(i, n):
		if l[i] < l[j] and b[j] != 1:
			b[j] = 1
			c += 1
			break
print(c)


n = int(input())
ch = input()
a = ch.split()
t = {}
for i in range(n):
	a[i] = int(a[i])
	if a[i] in t.keys():
		t[a[i]] = t[a[i]] + 1
	else:
		t[a[i]] = 1
b = 0

def count(t, b):
	if len(t) == 0:
		return b
	l = list(t.keys())
	for j in l:
		t[j] = t[j] - 1
		if t[j] == 0:
			del t[j]
	return count(t, b + len(l) - 1)
print(count(t, b))


n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
while len(L) > 0:
	curr = L[0]
	Q = []
	for i in range(1, len(L)):
		if L[i] == curr:
			Q.append(curr)
		else:
			curr = L[i]
	ans += len(set(L)) - 1
	L = Q
print(ans)


from collections import *
n = int(input())
l = list(map(int, input().split()))
d = defaultdict(int)
for i in l:
	d[i] += 1
x = list(d.values())
print(n - max(x))


def main():
	n = int(input())
	L = [int(x) for x in input().split()]
	print(solver(L))

def solver(L):
	paintings = dict()
	for x in L:
		if x in paintings:
			paintings[x] += 1
		else:
			paintings[x] = 1
	count = 0
	while len(paintings) != 0:
		count += len(paintings) - 1
		paintings = {x: paintings[x] - 1 for x in paintings if paintings[x] >= 2}
	return count
main()


n = int(input())
pics = sorted(list(map(lambda x: int(x), input().split())))
joy = 0
last = pics[0]
a = 0
for i in range(0, len(pics)):
	temp = 1
	for j in range(0, len(pics)):
		if i != j and pics[i] == pics[j]:
			temp += 1
	a = max(a, temp)
print(len(pics) - a)


n = input()
a = input().split()
ans = 0
for x in a:
	ans = max(ans, a.count(x))
print(int(n) - ans)


a = int(input())
d = dict()
for i in map(int, input().split()):
	d[i] = d.get(i, 0) + 1
print(a - max(d.values()))


n = None
arr = None

def main():
	n = int(input())
	st = input().split(' ')
	arr = []
	done = []
	for e in st:
		arr.append(int(e))
		done.append(False)
	arr.sort()
	tot = 0
	good = False
	while not good:
		add = 0
		ind = -1
		for i in range(len(arr)):
			if not done[i]:
				if ind == -1:
					ind = i
					done[i] = True
				elif arr[i] > arr[ind]:
					add += 1
					ind = i
					done[i] = True
		tot += add
		if add == 0:
			good = True
	print(tot)
main()


from collections import Counter
a = list(map(int, [input(), input()][1].split()))
print(len(a) - Counter(a).most_common(1)[0][1])


def non_zero_min(arr):
	ans = 10 ** 10
	for i in arr:
		if i == 0:
			continue
		ans = min(ans, i)
	return ans
arr = [0] * 1005
n = input()
s = list(map(int, input().split()))
for i in s:
	arr[i] += 1
res = []
while True:
	k = non_zero_min(arr)
	if k == 10 ** 10:
		break
	for i in range(0, 1005):
		if arr[i] > 0:
			res.append(i)
			arr[i] -= 1
ans = 0
for i in range(len(res) - 1):
	if res[i + 1] > res[i]:
		ans += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
c = [0] * 1001
for ai in a:
	c[ai] += 1
ans = 0
for t in range(max(c)):
	was = False
	for i in range(1, 1001):
		if c[i] > 0:
			if was:
				ans += 1
			else:
				was = True
			c[i] -= 1
print(ans)


import sys
n = int(input())
l = list(map(int, sys.stdin.readline().split()))
s = set(l)
ans = 0
while len(s) >= 2:
	ans += len(s) - 1
	for i in s:
		l.remove(i)
	s = set(l)
print(ans)


def main():
	n = int(input())
	a = sorted([int(c) for c in input().split()])
	ans = 0
	while a:
		dup = []
		for i in range(len(a) - 1):
			if a[i + 1] == a[i]:
				dup.append(a[i + 1])
			else:
				ans += 1
		a = dup
	print(ans)
main()


from collections import Counter
n = int(input())
a = dict(Counter(map(int, input().split(' '))))
ans = 0
while len(a) > 0:
	ans += len(a) - 1
	a = dict(((k, v - 1) for (k, v) in a.items() if v > 1))
print(ans)


n = int(input())
lst = [0] * 1000
for i in input().split():
	lst[int(i) - 1] += 1
print(n - max(lst))


n = int(input())
line = map(int, input().split())
book = dict()
for it in line:
	book[it] = book.setdefault(it, 0) + 1
lv = max(book.values())
print(n - lv)


n = int(input())
a = list((int(v) for v in input().strip().split()))
joy = 0
while a:
	a.sort()
	b = []
	for i in range(1, len(a)):
		if a[i - 1] == a[i]:
			b.append(a[i])
		else:
			joy += 1
	a = b
print(joy)


n = int(input())
lst = list(map(int, input().split(' ')))
lst.sort()
(h, i) = (0, 0)
trav = []
while i < n - 1:
	if i in trav:
		i += 1
		continue
	j = i + 1
	s = lst[i]
	while j < n:
		if lst[j] > s and j not in trav:
			h += 1
			s = lst[j]
			trav.append(j)
		j += 1
	trav.append(i)
	i += 1
print(h)


from collections import Counter
n = int(input())
print(n - Counter(list(map(int, input().split()))).most_common(1)[0][1])


n = int(input())
l = [int(i) for i in input().split()]
m = 0
for i in range(n):
	m = max(m, l.count(l[i]))
print(n - m)


n = int(input())
l = sorted(list(map(int, input().split(' '))))
x = set(l)
m = 0
number = 0
ans = 0
for i in x:
	if l.count(i) > m:
		m = l.count(i)
		number = i
while l.count(number) != 0:
	for i in x:
		if i != number and l.count(i) != 0:
			ans += 1
			l.remove(i)
	l.remove(number)
print(ans)


import collections
n = int(input())
d = collections.defaultdict(int)
mas = [int(x) for x in input().split()]
mas.sort()
for i in mas:
	d[i] += 1
p = 0
for i in mas:
	p = max(p, d[i])
print(n - p)


n = int(input())
x = [0 for i in range(0, 1010)]
for i in map(int, input().split()):
	x[i] += 1
d = 0
for i in range(0, 1010):
	d = max(d, x[i])
print(n - d)


n = int(input())
ar = list(map(int, input().split()))
print(n - max((ar.count(x) for x in ar)))


n = int(input())
l_p = list(map(int, input().split()))
d_p = {}
for p in l_p:
	if p not in d_p:
		d_p[p] = 1
	else:
		d_p[p] += 1
t = 0
while len(d_p) != 0:
	t += len(d_p) - 1
	s_k = set()
	for k in d_p:
		d_p[k] -= 1
		s_k.add(k)
	for k in s_k:
		if d_p[k] == 0:
			del d_p[k]
print(t)


n = int(input())
li = list(map(int, input().split()))
res = 0
for i in li:
	tmp = li.count(i)
	res = max(tmp, res)
print(n - res)


n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in l:
	temp = l.count(i)
	ans = max(temp, ans)
print(n - ans)


picture_quantity = int(input())
picture_beauty_list = list(map(int, input().split()))
c = []
while len(picture_beauty_list) > 0:
	a = set(picture_beauty_list)
	b = list(a)
	b.sort()
	c += b
	for del_el in b:
		picture_beauty_list.remove(del_el)
	b = []
satisfied = 0
for i in range(len(c)):
	if i != len(c) - 1:
		if c[i] < c[i + 1]:
			satisfied += 1
print(satisfied)


n = int(input())
a = list(map(int, input().split()))
i = 1
j = 0
z = 0
k = 1
s = 1
se = 0
flag = False
flagEX = False
a.sort()
while s != 0:
	k = 0
	i = 1
	s = 0
	while i < n:
		if a[k] < a[i] and a[k] != 0 and (a[i] != 0):
			a[k] = 0
			k = i
			i += 1
			s += 1
		elif a[k] == 0:
			i += 1
			k += 1
		else:
			i += 1
	if a[k] != 0:
		a[k] = 0
	se += s
print(se)


from sys import *
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
n = int(input())
arr = int_arr()
arr.sort()
ct = 0
for ele in arr:
	if arr[ct] < ele:
		ct += 1
print(ct)


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
b = []
c = [0] * 2000
res = 0
for i in a:
	if c[i] == 0:
		b.append(i)
	c[i] += 1
n = len(b)
while n > 1:
	res += n - 1
	for i in range(len(b)):
		if c[b[i]] > 0:
			c[b[i]] -= 1
			if c[b[i]] == 0:
				n -= 1
print(res)


n = int(input().strip())
arr = list(map(int, input().strip().split()))
freq = [0] * 1001
for ele in arr:
	freq[ele] += 1
freq.sort()
print(n - freq[-1])


from collections import defaultdict
input()
xs = sorted(map(int, input().split()))
(run, counts) = (0, defaultdict(lambda : -1))
for (a, b) in zip(xs, xs[1:] + xs[-1:]):
	run += 1
	counts[run] += 1
	if a != b:
		run = 0
print(sum(counts.values()))


from sys import stdin, stdout
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
n = ii1()
arr = iia()
dub = {}
for i in arr:
	dub.setdefault(i, [0])[0] += 1
dub1 = {}
for i in dub:
	if dub[i][0] > 1:
		dub1[i] = [dub[i][0] - 1]
arr = sorted(list(set(arr)))
arr1 = []
while len(dub1):
	temp = {}
	for i in sorted(dub1):
		arr1.append(i)
		dub1[i][0] -= 1
		if dub1[i][0] > 0:
			temp[i] = dub1[i]
	dub1 = temp.copy()
arr += arr1
res = 0
for i in range(1, n):
	if arr[i] > arr[i - 1]:
		res += 1
print(res)


import collections, itertools, functools, math

def solve():
	n = int(input())
	a = map(int, input().split())
	cnt = collections.Counter(a)
	m = cnt.most_common(1)[0][1]
	return n - m
print(solve())


n = int(input())
if n >= 1 and n <= 1000:
	line_paintings = input()
	paintings = line_paintings.split()
	paintings = list(map(int, paintings))
	if len(paintings) >= 1 and len(paintings) <= 1000:
		tmp = 0
		cnt = 0
		values = []
		newOrder = []
		for i in range(max(paintings) + 1):
			values.append(paintings.count(i))
		while sum(values) > 0:
			for i in range(len(values)):
				if values[i] > 0:
					newOrder.append(i)
					values[i] -= 1
		for i in range(len(newOrder)):
			if i == 0:
				tmp = newOrder[i]
			else:
				if newOrder[i] > tmp:
					cnt += 1
				tmp = newOrder[i]
		print(cnt)


n = int(input())
a = list(map(int, input().split()))
b = [0] * 1001
for i in a:
	b[i] += 1
c = []
for i in b:
	if i:
		c.append(i)
c.sort()
d = 0
ans = 0
l = len(c) - 1
for i in range(l):
	ans += max(0, c[i] - d) * (l - i)
	d = c[i]
print(ans)


import bisect
from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
n = I()
a = LI()
d = Counter(a)
print(n - max(d.values()))


import sys
EPS = sys.float_info.epsilon
LENGTH = 10
matrix = [[] for i in range(LENGTH)]
array = [0] * 1001
ans = 0
n = int(input())
for val in map(int, input().split()):
	array[val] += 1
while True:
	ls = []
	for j in range(1, 1001):
		if array[j] > 0:
			ls.append(j)
	if len(ls) > 1:
		ans += len(ls) - 1
		for k in ls:
			array[k] -= 1
	else:
		break
print(ans)


input()
ans = 0
b = input().split()
while len(b):
	ans += len(set(b)) - 1
	for bb in set(b):
		b.remove(bb)
print(ans)


from collections import Counter
n = int(input())
val = list(map(int, input().split()))
cnt = Counter(val)
print(n - max(cnt.values()))


def find(l):
	t = []
	for i in l:
		f = False
		for x in t:
			if i not in x:
				x.append(i)
				f = True
				break
		if f == False:
			temp = []
			temp.append(i)
			t.append(temp)
	count = 0
	for i in t:
		count += len(i) - 1
	print(count)
a = input()
a = input().split()
find(a)


n = int(input())
arr = list(map(int, input().split()))
counting = [0] * 1003
for i in arr:
	counting[i] += 1
sum = 0
for i in range(0, 1005):
	back = 10000
	for j in range(0, 1001):
		if counting[j] != 0:
			counting[j] -= 1
			if j > back:
				sum += 1
			back = j
print(sum)


from collections import Counter
n = int(input())
l = dict(Counter(list(map(int, input().split()))))
op = max(l.values())
print(n - 1 - (op - 1))


c = [0 for i in range(1001)]
n = int(input())
a = map(int, input().split())
for x in a:
	c[x] += 1
answer = 0
while n > 0:
	count = 0
	for i in range(1001):
		if c[i] > 0:
			c[i] -= 1
			n -= 1
			count += 1
	answer += count - 1
print(answer)


from collections import Counter
input()
c = Counter([int(i) for i in input().split()])
k = [c[i] for i in c]
total = 0
while any([i > 0 for i in k]):
	q = 0
	for i in range(len(k)):
		if k[i]:
			q += 1
			k[i] -= 1
	if q > 0:
		total += q - 1
print(total)


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
c = Counter(l)
print(n - max(c.values()))


from collections import Counter
x = int(input())
a = list(map(int, input().split()))
s = 0
c = Counter(a)
a = list(set(a))
a.sort()
w = c[0]
for i in a:
	if c[i] > w:
		w = c[i]
s = x - w
print(s)


n = input()
a = [int(x) for x in input().split(' ')]
d = {}
for i in a:
	try:
		d[i] += 1
	except KeyError:
		d[i] = 1
ou = []
while d:
	keys = list(d.keys())
	keys.sort()
	for key in keys:
		ou.append(key)
		if d[key] > 1:
			d[key] -= 1
		else:
			d.pop(key)
last = 9999
r = 0
for x in ou:
	if x > last:
		r += 1
	last = x
print(r)


n = int(input())
count = [0] * 1001
c = [0] * 1001
pictures = list(map(int, input().split()))
for i in pictures:
	count[i] += 1
res = 0
while count != c:
	res -= 1
	for i in range(len(count)):
		if count[i] > 0:
			count[i] -= 1
			res += 1
print(res)


n = int(input())
pictures = list(map(int, input().split()))
indexes = [0 for i in range(max(pictures) + 1)]
for elem in pictures:
	indexes[elem] += 1

def sub(mass):
	count = -1
	for i in range(len(mass)):
		if mass[i] != 0:
			mass[i] -= 1
			count += 1
	return (mass, count)
seq = 0
while sum(indexes) != 0:
	tmp = 0
	for elem in indexes:
		if elem == 0:
			continue
		else:
			tmp += 1
	if tmp == 1:
		break
	(new_mass, count) = sub(indexes)
	indexes = new_mass
	seq += count
print(seq)


from collections import Counter
import string
import math
import sys
from fractions import Fraction
from itertools import product

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))

def printDivisors(n):
	divisors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				divisors.append(i)
			else:
				divisors.extend((i, n // i))
		i = i + 1
	return divisors

def countTotalBits(num):
	binary = bin(num)[2:]
	return len(binary)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
mod = 10 ** 9 + 7

def comp(x):
	return x[1]

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	primes = []
	for p in range(2, n + 1):
		if prime[p]:
			primes.append(p * p)

def binary_search(arr, x):
	low = 0
	high = len(arr) - 1
	mid = 0
	while low <= high:
		mid = (high + low) // 2
		if arr[mid] < x:
			low = mid + 1
		elif arr[mid] > x:
			high = mid - 1
		else:
			return mid
	return -1

def lcm(a, b):
	return a * b // math.gcd(a, b)

def primeFactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n = n // i
	if n > 2:
		factors.append(n)
	return factors
mod = 10 ** 9 + 7
testCases = 1
for _ in range(testCases):
	n = vary(1)
	num = array_int()
	ct = makedict(num)
	mini = -1
	for i in ct:
		mini = max(mini, ct[i])
	print(n - mini)


def func(arr):
	temp = []
	ans = 0
	while True:
		arr = sorted(arr)
		x = 0
		for i in range(1, len(arr)):
			if arr[i] == arr[i - 1]:
				temp.append(arr[i])
				x += 1
		ans = ans + len(arr) - 1 - x
		arr = temp
		temp = []
		if len(arr) == 0:
			return ans
p = input()
arr = list(map(int, input().split()))
print(func(arr))


n = int(input())
seq = input().split()
dic = {}
vec = {}
res = 0
for i in seq:
	i = int(i)
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
for key in dic:
	for i in range(dic[key]):
		if i < len(vec):
			vec[i] += 1
		else:
			vec[i] = 1
for key in vec:
	if vec[key] > 0:
		res += vec[key] - 1
print(res)


def main():
	input()
	nums = map(int, input().split())
	nums = sorted(nums)
	length = len(nums)
	count = 0
	last_num = nums[0]
	for i in range(length):
		if nums[i] is None:
			continue
		last_num = nums[i]
		for j in range(i + 1, length):
			if nums[j] is None:
				continue
			if nums[j] > last_num:
				count += 1
				last_num = nums[j]
				nums[j] = None
	print(count)
main()


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
c = Counter(l)
s = list(set(l))
s.sort()
cn = 0
while True:
	for i in range(len(s)):
		if c[s[i]] != 0:
			c[s[i]] -= 1
			cn += 1
	cn -= 1
	k = list(set(c.values()))
	if len(k) == 1 and k[0] == 0:
		break
print(cn)


n = input()
li = list(map(int, input().split(' ')))
li.sort()
l1 = [1]
j = 0
number = 0
f = True
sum = 0
for i in range(len(li) - 1):
	if li[i + 1] == li[i]:
		l1[j] += 1
	else:
		j += 1
		l1.append(1)
while 1:
	for i in range(len(l1)):
		if l1[i] > 0:
			number += 1
			l1[i] -= 1
			f = False
	if f:
		break
	f = True
	sum += number - 1
	number = 0
print(sum)


d = {}
for x in [*open(0)][1].split():
	d[x] = d.get(x, 0) + 1
ret = 0
while 1:
	k = len(d.keys())
	if k < 1:
		break
	x = min(d.values())
	for v in [*d.keys()]:
		if d[v] == x:
			d.pop(v)
		else:
			d[v] -= x
	ret += (k - 1) * x
print(ret)


n = int(input())
S = [int(x) for x in input().split()]
S.sort()
T = [S[0]]
t = 0
check = True
S[0] = 0
total = 1
while total < len(S):
	for j in range(1, len(S)):
		if S[j] > T[-1]:
			T.append(S[j])
			S[j] = 0
			total += 1
			t += 1
			break
	else:
		for i in range(len(S)):
			if S[i] != 0:
				T.append(S[i])
				S[i] = 0
				total += 1
				break
print(t)


from _operator import le
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
prev = arr[0]
count = 0
tcount = -1
while 0 == 0:
	tcount = -1
	prev = -1
	for i in range(0, n):
		if prev != arr[i] and arr[i] != -1:
			prev = arr[i]
			arr[i] = -1
			tcount += 1
	if tcount == -1:
		break
	count += tcount
print(count)


import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
n = inp()
a = inlist()
count = defaultdict(lambda : 0)
for i in a:
	count[i] += 1
keys = sorted(count.keys())
res = 0
while sum(count.values()) > 0:
	prev = 1001
	for k in keys:
		if count[k] > 0:
			if k > prev:
				res += 1
			prev = k
			count[k] -= 1
print(res)


import sys
from collections import Counter
input = sys.stdin.readline
n = int(input())
a = dict(Counter(sorted(input().split())))
ans = 0
f = 0
for val in a:
	ans += min(f, a[val])
	f += max(a[val] - f, 0)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
res = 0
while len(arr) > 0:
	res += len(set(arr)) - 1
	for i in set(arr):
		arr.remove(i)
print(res)


N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
A = [(a, True) for a in A]
happiness = 0
uses_left = N
while True:
	last_a = None
	for i in range(len(A)):
		(a, usable) = A[i]
		if not usable:
			continue
		if last_a is None:
			last_a = a
			A[i] = (a, False)
			uses_left -= 1
			continue
		if last_a < a:
			happiness += 1
			A[i] = (a, False)
			uses_left -= 1
			last_a = a
			continue
	if uses_left == 0:
		break
print(happiness)


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(0)
else:
	di = defaultdict(int)
	for i in range(n):
		k = a.count(a[i])
		di[a[i]] = k
	li = list(di.values())
	li.sort()
	ans = 0
	while len(li) > 1:
		if li[0] == 0:
			li.remove(li[0])
		else:
			ans += len(li) - 1
			for i in range(len(li)):
				li[i] -= 1
	print(ans)


from collections import Counter
n = int(input())
draws = list(map(int, input().split()))
draws.sort()
draw_count = Counter(draws)
count_sum = sum(draw_count.values()) - max(draw_count.values())
print(count_sum)


n = int(input())
beauty = [int(i) for i in input().split()]
qtdBeauty = [0] * 1001
for a in beauty:
	qtdBeauty[a] += 1
beauty = sorted(set(beauty))
res = 0
flag = True
while flag:
	flag = False
	moreHappy = False
	for a in beauty:
		if qtdBeauty[a] > 0:
			qtdBeauty[a] -= 1
			if not moreHappy:
				moreHappy = True
			else:
				res += 1
			flag = True
print(res)


n = int(input())
l = list(map(int, input().split()))
from collections import Counter
tmp = Counter(l)
print(n - max((tmp[i] for i in tmp)))


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
b = set(a)
f = {}
for i in b:
	f[i] = a.count(i)
x = 0
y = 0
for i in f:
	x += min(y, f[i])
	y = max(y, f[i])
print(x)


import sys, threading, os.path
import string
import collections, heapq, math, bisect, operator
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)

def main():
	if os.path.exists('in.txt'):
		input = open('in.txt', 'r')
	else:
		input = sys.stdin
	n = int(input.readline())
	data = list(map(int, input.readline().split()))
	lis = [0 for i in range(1001)]
	for x in data:
		lis[x] += 1
	sol = 0
	for i in range(1001):
		first = False
		for j in range(1001):
			if lis[j] > 0:
				lis[j] -= 1
				if first:
					sol += 1
				else:
					first = True
	output = sol
	if os.path.exists('out.txt'):
		open('out.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


n = int(input())
a = [int(i) for i in input().split()]
d = dict()
for i in a:
	d[i] = d.get(i, 0) + 1
k = len(d)
l = sorted(list(d.values()))
curr = 0
ans = 0
i = 0
maxi = l[-1]
while curr < maxi:
	ans += (k - i - 1) * (l[i] - curr)
	curr = l[i]
	i += 1
print(ans)


input()
l = list(map(int, input().split()))
l = sorted(l)
count = 0
for i in l:
	if l[count] < i:
		count += 1
print(count)


numbber = int(input())
array = input().split()
nArray = []
for i in array:
	nArray.append(int(i))
nArray.sort()
list = []
while len(nArray) != 0:
	buffer = []
	for i in nArray:
		if i not in buffer:
			buffer.append(i)
	for i in buffer:
		nArray.remove(i)
	list.append(buffer)
count = 0
for i in list:
	count += len(i) - 1
print(count)


(n, a, v) = (int(input()), sorted(list(map(int, input().split()))), 0)
for elem in a:
	if elem > a[v]:
		v += 1
print(v)


n = int(input())
a = list(map(int, input().split()))
c = []
for i in a:
	c.append(a.count(i))
print(n - max(c))


n = int(input())
x = [int(z) for z in input().split()]
x.sort()
y = []
cur = x[0]
curs = 1
i = 1
y = []
while i < n:
	r = x[i]
	if r == cur:
		curs += 1
	else:
		d = [cur] * curs
		y += [d]
		curs = 1
		cur = r
	i += 1
y += [[cur] * curs]
res = 0
while len(y) > 1:
	u = []
	for h in y:
		h.pop()
		if h != []:
			u += [h]
	res += len(y) - 1
	y = u[:]
print(res)


from collections import Counter
input()
c = Counter(input().split())
(A, n) = (set(c), 0)
while len(A) > 1:
	for a in A:
		c[a] -= 1
	(A, n) = (A - set((a for a in A if c[a] == 0)), n + len(A) - 1)
print(n)


n = int(input())
a = [int(i) for i in input().split()]
d = {}
for i in a:
	d[i] = d.setdefault(i, 0) + 1
x = len(d) - 1
b = sorted([i for i in d], key=lambda x: d[x])
ans = 0
for i in range(len(b)):
	if b[i] in d:
		ans += x * d[b[i]]
		t = d[b[i]]
		for j in range(i, len(b)):
			d[b[j]] -= t
			if d[b[j]] <= 0:
				d.pop(b[j])
	x -= 1
print(ans)


from collections import Counter
t = int(input())
l = list(map(int, input().split()))
l.sort()
c = Counter(l)
l1 = list(c)
h = 1
cc = 0
while h > 0:
	h = 0
	for i in l1:
		if c[i] > 0:
			c[i] -= 1
			h += 1
	if h > 0:
		cc += h - 1
print(cc)


n = int(input())
line = map(int, input().split())
book = dict()
for it in line:
	book[it] = book.setdefault(it, 0) + 1
note = dict()
for v in book.values():
	note[v] = note.setdefault(v, 0) + 1
res = 0
end = max(note.keys())
lv = 0
while lv < end:
	for (k, v) in note.items():
		if k > lv:
			res += v
	res -= 1
	lv += 1
print(res)


n = int(input())
ans = 0
from collections import Counter
c = Counter([int(x) for x in input().split()])
while sum(c.values()) > 0:
	l = (+c).keys()
	ans += len(l) - 1
	for x in l:
		c[x] -= 1
print(ans)


n = int(input())
ll = list(map(int, input().split()))
l = [0] * 1001
for i in range(n):
	l[ll[i]] += 1
l = sorted(l)
ans = 0
k = 0
h = 0
for i in range(1001):
	if l[i] != k:
		ans += (l[i] - k) * (1000 - i)
		k = l[i]
print(ans)


(n, xs) = (int(input()), sorted(map(int, input().split())))
(run, count) = (1, 0)
for (a, b) in zip(xs, xs[1:] + xs[-1:]):
	count = max(run, count)
	run = run + 1 if a == b else 1
print(n - count)


n = input()
l = [int(i) for i in input().split()]
l.sort()
c = 0
while len(l) > 1:
	t = []
	x = l[0]
	for i in range(1, len(l)):
		if l[i] > x:
			x = l[i]
			c += 1
		else:
			t.append(l[i])
	l = t[:]
print(c)


from sys import stdin
from collections import Counter as c
n = int(input())
print(n - max(c(list(stdin.readline().split())).values()))


n = input()
beauty = list(map(int, input().split(' ')))
beatyDict = {}
for item in beauty:
	if beatyDict.get(item):
		beatyDict[item] += 1
	else:
		beatyDict[item] = 1
score = 0
for iteration in range(max(beatyDict.values())):
	k = 0
	for item in beatyDict:
		if beatyDict[item] != 0:
			beatyDict[item] -= 1
			k += 1
	score += k - 1
print(score)


def f():
	input()
	a = list(map(int, input().split(' ')))
	f = 1001 * [0]
	for i in a:
		f[i] += 1
	f = [i for i in f if i > 0]
	r = 0
	while len(f) > 1:
		r += len(f) - 1
		f = [i - 1 for i in f if i > 1]
	print(r)
f()


x = int(input())
nums = list(map(int, input().split()))
lista = [0] * (max(nums) + 1)
for i in range(x):
	lista[nums[i]] += 1
print(x - max(lista))


n = int(input())
beu = [int(z) for z in input().split()]
beud = {}
for i in range(n):
	try:
		beud[beu[i]] += 1
	except KeyError:
		beud[beu[i]] = 1
pos = n
ans = 0
while pos > 0:
	pos = 0
	for i in beud.keys():
		if beud[i] > 0:
			pos += 1
		beud[i] -= 1
	if pos != 0:
		ans += pos - 1
print(ans)


n = int(input())
pics = sorted(list(map(lambda x: int(x), input().split())))
unpaired = []
pairs = 0
ix = -1
cur = prev = -1
for i in pics:
	if i > cur:
		ix += 1
		prev = cur
		cur = i
		unpaired.append(0)
	unpaired[ix] += 1
	if ix > 0:
		if unpaired[ix - 1] > 0:
			pairs += 1
			unpaired[ix - 1] -= 1
		else:
			for j in reversed(range(0, ix)):
				if unpaired[j] > 0:
					pairs += 1
					unpaired[j] -= 1
					break
print(pairs)


from sys import stdin
try:
	while True:
		total_paints = int(input())
		paints_beauties = list(map(int, input().split(' ', total_paints)))
		frequency = {}
		max_frequency = 0
		for b in paints_beauties:
			frequency[b] = frequency.get(b, 0) + 1
		max_frequency = max(frequency.values())
		total_jumps = total_paints - max_frequency
		print(total_jumps)
except EOFError:
	pass


read = lambda : list(map(int, input().split()))
n = int(input())
a = list(read())
wasr = [False] * n
wasl = [False] * n
cnt = 0
inf = 10 ** 9
for i in range(n):
	if wasl[i]:
		continue
	wasl[i] = True
	cur = a[i]
	Min = inf
	ind = -1
	for j in range(n):
		if wasr[j]:
			continue
		if cur < a[j] < Min:
			Min = a[j]
			ind = j
	if ind != -1:
		wasr[ind] = True
		cnt += 1
print(cnt)


from collections import Counter
n = int(input())
D = Counter((int(x) for x in input().split()))
print(n - D.most_common(1)[0][1])


from collections import Counter
(n, a) = (int(input()), map(int, input().split()))
li = list(Counter(a).values())
print(sum(li) - max(li))


N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
	d[a] = d.get(a, 0) + 1
keys = list(d.keys())
keys.sort()
ans = 0
while True:
	tmp = 0
	for key in keys:
		if d[key] != 0:
			tmp += 1
			d[key] -= 1
	if tmp == 0:
		break
	ans += tmp - 1
print(ans)


from collections import Counter
import sys
n = int(sys.stdin.readline().strip())
arr = sys.stdin.readline().rstrip().split(' ')
dict1 = Counter(arr)
i = 0
j = 0
count = 0
arr.sort()
while i < len(arr) and j < len(arr):
	if arr[i] == arr[j]:
		j += 1
	elif arr[i] < arr[j]:
		i += 1
		j += 1
		count += 1
	else:
		pass
print(count)


n = int(input())
l = list(map(int, input().split()))
print(n - max((l.count(i) for i in l)))


from collections import *
n = int(input())
d = Counter()
for x in map(int, input().split()):
	d[x] += 1
ans = 0
while len(d) > 1:
	ans += len(d) - 1
	d -= Counter({x: 1 for x in d})
print(ans)


from sys import stdin
n = int(stdin.readline().rstrip())
l = list(map(int, stdin.readline().rstrip().split(' ')))
l.sort()

def ad(l, c):
	el = []
	if l[0] == l[-1]:
		return ([], c)
	else:
		for i in range(1, len(l)):
			if l[i] > l[i - 1]:
				c += 1
			else:
				el.append(l[i])
		if el:
			(el, c) = ad(el, c)
	return (el, c)
(el, a) = ad(l, 0)
print(a)


n = int(input())
x = [0] * 1001
l = list(map(int, input().split()))
for i in l:
	x[i] += 1
maior = max(x)
print(n - maior)


n = int(input())
pictures = list(map(int, input().split()))
d = dict()
for i in pictures:
	d[i] = 0
for i in pictures:
	d[i] += 1
a = sorted(d.values())
i = 1
r = 0
l = len(a) - 1
s = 0
while i < len(a):
	c = i
	while i < len(a) and a[i] == a[i - 1]:
		i += 1
	s += l * (a[i - 1] - r)
	l -= i - c + 1
	r = a[i - 1]
	i += 1
print(s)


class Node(object):

	def __init__(self, v):
		self.val = v
		self.next = None
n = int(input().strip())
arr = list(map(int, input().strip().split()))
arr.sort(reverse=True)
if len(arr) < 1:
	print(0)
	exit()
sentinel = Node(0)
node = Node(arr[0])
sentinel.next = node
for i in range(1, n):
	node = Node(arr[i])
	node.next = sentinel.next
	sentinel.next = node
count = 0
prev = sentinel
while sentinel.next != None and sentinel.next.next != None:
	prev = sentinel
	cur = sentinel.next
	while cur.next != None:
		if cur.val < cur.next.val:
			count += 1
			prev.next = cur.next
			cur = cur.next
		else:
			prev = prev.next
			cur = cur.next
	prev.next = None
print(count)


import re
import sys
import os

def getSrcData():
	f = sys.stdin
	buf = f.read()
	result = []
	if buf:
		buf = buf.split('\n')
		result = buf[1].split(' ')
		result = [int(x) for x in result]
		result.sort()
	return result

def analyze(srcData):
	result = [{}]
	for elem in srcData:
		flag = 0
		for seq in result:
			if not elem in seq:
				seq[elem] = 1
				flag = 1
				break
		if flag == 0:
			result.append({elem: 1})
	return result

def getScore(analyzeData):
	result = 0
	for seq in analyzeData:
		result += len(seq) - 1 if len(seq) != 0 else 0
	return result

def saveResult(resultScore):
	f = sys.stdout
	f.write(str(resultScore) + '\n')
	f.flush()

def run():
	srcData = getSrcData()
	analyzeData = analyze(srcData)
	resultScore = getScore(analyzeData)
	saveResult(resultScore)
run()


n = int(input())
a = sorted(list(map(int, input().split())))
c = [0] * 1001
for x in a:
	c[x] += 1
ans = n
for i in range(0, n):
	ans = min(ans, n - c[a[i]])
print(ans)


a = int(input())
s = input().split()
for i in range(a):
	s[i] = int(s[i])
s = sorted(s)
count = 0

def changing(s):
	mat = []
	sat = []
	count = -1
	for i in s:
		if i in mat:
			sat.append(i)
		else:
			mat.append(i)
			count += 1
	sat.append(count)
	return sat
while True:
	obtained = changing(s)
	if len(obtained) == 1:
		count += int(obtained[0])
		break
	count += int(obtained[-1])
	s = obtained[0:len(obtained) - 1]
print(count)


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	res = 0
	for i in range(0, n - 1):
		x = arr[i]
		if x != -1:
			for j in range(i + 1, n):
				if arr[j] > x:
					x = arr[j]
					arr[j] = -1
					res += 1
	print(res)
main()


class A(object):

	def __init__(self):
		self.AC()

	def GetData(self):
		self.m_N = int(input())
		self.m_X = [int(x) for x in input().split()]

	def AC(self):
		self.GetData()
		ans = 0
		while self.m_X:
			self.m_Y = []
			for x in self.m_X:
				if x not in self.m_Y:
					self.m_Y.append(x)
			ans += len(self.m_Y) - 1
			for x in self.m_Y:
				self.m_X.remove(x)
		print(ans)
A()


import sys
n = int(input())
a = list(map(int, input().split()))
print(n - max((a.count(i) for i in a)))


from collections import defaultdict
n = int(input())
A = [int(x) for x in input().split()]
D = defaultdict(int)
for a in A:
	D[a] += 1
S = set(D.keys())
ans = len(S) - 1
while S:
	for k in D:
		D[k] -= 1
		if D[k] <= 0 and k in S:
			S.remove(k)
	ans += len(S) - 1
print(ans + 1)


n = int(input())
lst = [int(i) for i in input().split()]
lst.sort()
no_repeat = 0
aux = []
dic = {}
temp = 0
for i in range(1, len(lst)):
	temp = lst[i]
	if temp == lst[i - 1]:
		if temp not in dic:
			dic[temp] = 1
		else:
			dic[temp] += 1
	else:
		no_repeat += 1
keys = []

def getMin(dic):
	Min = 10000000000
	for key in dic:
		if dic[key] < Min:
			Min = dic[key]
	return Min
while len(dic) > 1:
	Min = getMin(dic)
	length = len(dic)
	no_repeat += (length - 1) * Min
	for key in dic:
		dic[key] -= Min
		if dic[key] == 0:
			keys.append(key)
	for i in range(0, len(keys)):
		del dic[keys[i]]
	keys.clear()
print(no_repeat)


n = int(input())
l = sorted(map(int, input().split()))
d = {}
for x in l:
	d[x] = d.get(x, 0) + 1
ans = 0
while len(d) > 1:
	ans += len(d) - 1
	for x in list(d.keys()):
		d[x] -= 1
		if d[x] == 0:
			del d[x]
print(ans)


import sys
n = sys.stdin.readline()
nums = sys.stdin.readline().rstrip('\n').split()
ans = 0
while len(nums) > 0:
	uniq = set(nums)
	ans = ans + len(uniq) - 1
	new_nums = []
	for i in range(len(nums)):
		if nums[i] in uniq:
			uniq.remove(nums[i])
		else:
			new_nums.append(nums[i])
	nums = new_nums
sys.stdout.write(str(ans) + '\n')


n = int(input())
v = [int(y) for y in input().split()]
v.sort()
ans = 0
for i in range(n):
	if v[i] != -1:
		aux = v[i]
		for k in range(i + 1, n):
			if v[k] > aux:
				ans += 1
				aux = v[k]
				v[k] = -1
print(ans)


n = input()
A = list(map(int, input().split()))
MAX_SIZE = 1010
cnt = [0] * MAX_SIZE
for i in A:
	cnt[i] += 1
answer = 0
while True:
	c = 0
	for i in range(MAX_SIZE):
		if cnt[i] > 0:
			cnt[i] -= 1
			c += 1
	if c > 1:
		answer += c - 1
	else:
		break
print(answer)


size = 1001
n = int(input())
a = [0] * size
ans = 0
num = map(int, input().split())
for b in num:
	a[b] += 1
while a.count(0) != size:
	cnt = 0
	for i in range(size):
		if a[i]:
			cnt += 1
			a[i] -= 1
	ans += cnt - 1
print(ans)


from sys import stdin
inFile = stdin
tokens = []
tokens_next = 0

def next_str():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = inFile.readline().split()
		tokens_next = 0
	tokens_next += 1
	return tokens[tokens_next - 1]

def nextInt():
	return int(next_str())
n = nextInt()
a = [nextInt() for i in range(n)]
res = 0
while a:
	s = set(a)
	res += len(s) - 1
	for i in s:
		a.remove(i)
print(res)


n = int(input())
x = list(map(int, input().split()))
cnt = 0
x.sort()
for i in range(1, n):
	if cnt < len(x[:x.index(x[i])]):
		cnt += 1
print(cnt)


from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]
c = Counter(a)
a = list(set(a))
a.sort()
l = []
while len(l) != n:
	for e in a:
		if c[e] > 0:
			c[e] -= 1
			l.append(e)
ans = 0
for i in range(len(l) - 1):
	if l[i + 1] > l[i]:
		ans += 1
print(ans)


n = int(input())
lst = list(map(int, input().split()))
lst.sort()
x = []
for i in range(n):
	x.append(True)
count = 0
for i in range(len(lst)):
	if lst[i] > lst[count]:
		count += 1
print(count)


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p + p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
from bisect import bisect_left

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	print(n - max((a.count(x) for x in a)))
for _ in range(1):
	solve()


n = int(input())
l = list(map(int, input().split()))
output = 0
while len(l) > 0:
	tmp = list(set(l))
	output += len(tmp) - 1
	[l.remove(x) for x in tmp]
print(output)


n = int(input())
painting = [int(x) for x in input().split()]
nums = {}
appearance = {}
for i in range(n):
	if nums.get(painting[i]) == None:
		nums[painting[i]] = 1
	else:
		nums[painting[i]] += 1
for n in nums.keys():
	tmp = nums[n]
	while tmp > 0:
		if appearance.get(tmp) == None:
			appearance[tmp] = 1
		else:
			appearance[tmp] += 1
		tmp -= 1
res = 0
for a in appearance.keys():
	res += appearance[a] - 1
print(res)


n = int(input())
s = [int(i) for i in input().split()]
a = []
cnt = 0
d = {}
ans = 0
for i in s:
	if i not in d:
		d[i] = 1
	else:
		d[i] += 1
for i in d:
	a.append(d[i] * [i])
s = []
a.sort()
while a:
	cnt = 0
	for i in range(len(a)):
		if a[i] == []:
			cnt += 1
		else:
			s.append(a[i].pop(0))
	if cnt == len(a):
		break
for i in range(n - 1):
	if s[i + 1] > s[i]:
		ans += 1
print(ans)


n = int(input())
l = input().split(' ')
l1 = []
for i in range(n):
	l1.append(l.count(l[i]))
print(n - max(l1))


num = int(input())
l = sorted(list(map(int, input().split())))
n = 0
while l:
	a = [l[0]]
	k = []
	for i in range(1, len(l)):
		if l[i] != l[i - 1]:
			a.append(l[i])
		else:
			k.append(l[i])
	if len(a) != 0:
		n += len(a) - 1
	l = [i for i in k]
print(n)


from collections import *
n = int(input())
l = list(map(int, input().split()))
c = Counter()
for x in l:
	c[x] += 1
ans = 0
while len(c) > 1:
	ans += len(c) - 1
	b = Counter({x: 1 for x in c})
	c -= b
print(ans)


n = int(input())
vetor = list(map(int, input().split()))
lista_set = [set()]
for num in vetor:
	flag = True
	for i in range(len(lista_set)):
		if num not in lista_set[i]:
			lista_set[i].add(num)
			flag = False
			break
	if flag:
		lista_set.append(set([num]))
somatorio = sum(list(map(lambda lista: len(lista) - 1, lista_set)))
print(somatorio)


n = int(input())
a = sorted(map(int, input().split()))
ans = 0
i = 0
b = []
while i < n:
	count = 0
	j = i
	while j < n and a[i] == a[j]:
		count += 1
		j += 1
	b.append(count)
	i = j
m = len(b)
i = m - 1
while i >= 0:
	j = i + 1
	me = b[i]
	other = 0
	while j < m:
		take = min(me, b[j])
		other += take
		me -= take
		b[j] -= take
		j += 1
	ans += other
	i -= 1
print(ans)


(n, a) = (input(), [0] * 1001)
for i in map(int, input().split()):
	a[i] += 1
a.sort()
(q, w, r) = (len(a), 0, 0)
for i in a:
	w += (q - 1) * (i - r)
	q -= 1
	r = i
print(w)


def find_the_most_beatiful(a):
	n = len(a)
	result = []
	while n > 0:
		a = sorted(a)
		value = -100500
		for i in range(len(a)):
			if a[i] > value and a[i] > 0:
				value = a[i]
				result += [a[i]]
				a[i] = -1
				n -= 1
	number = 0
	for i in range(1, len(result)):
		if result[i] > result[i - 1]:
			number += 1
	return number
n = int(input())
items = list(map(int, input().split()))
print(find_the_most_beatiful(items))


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
r = 0
for i in b:
	r = max(r, b[i])
print(n - r)


n = int(input())
p = list(map(int, input().split()))
p.sort()
q = [0] * n
count = 0
for i in range(n):
	a = p[i]
	res = n - 1 - p[::-1].index(a)
	while res + 1 < n and q[res + 1] == -1:
		res += 1
	if res + 1 < n:
		count += 1
		q[res + 1] = -1
print(count)


n = int(input())
beauty = sorted([int(x) for x in input().split()])
beauty_ = list(set(beauty))
nums = []
output = 0
for i in beauty_:
	num = 0
	for j in beauty:
		if j == i:
			num = num + 1
		if j > i:
			break
	nums.append(num)
nums.sort()
nums = [0] + nums
for i in range(1, len(nums)):
	output += (nums[i] - nums[i - 1]) * (len(beauty_) - i)
print(output)


def main():
	tmp = input()
	numbers = list(map(int, input().split()))
	numbers.sort()
	max_occr = 0
	count_occr = [0] * 2000
	for i in range(0, len(numbers)):
		count_occr[numbers[i]] = count_occr[numbers[i]] + 1
		max_occr = max(count_occr[numbers[i]], max_occr)
	print(len(numbers) - max_occr)
main()


from collections import Counter
n = int(input())
x = list(map(int, input().split()))
x.sort()
cnt = Counter(x)
z = sorted(cnt, key=lambda k: cnt[k])
if len(z) == 1:
	k = 1
else:
	k = cnt[z[-2]]
for i in range(n):
	if cnt[x[i]] > k:
		cnt[x[i]] -= 1
		x[i] = -1
z = []
for i in x:
	if i != -1:
		z.append(i)
i = 1
p = z[0]
while i < len(z):
	if len(z) == 1:
		break
	if z[i] == p:
		z[i] = -1
		z.append(p)
	else:
		p = z[i]
	i += 1
y = []
for i in z:
	if i != -1:
		y.append(i)
c = 0
for i in range(1, len(y)):
	if y[i] > y[i - 1]:
		c += 1
print(c)


n = int(input())
A = list(map(int, input().split()))
A.sort()
for i in range(n):
	A[i] = [A[i], 0]
answer = 0
per2 = -float('infinity')
per = 0
for i in range(n - 1):
	if A[i][1] == 0:
		A[i][1] = 1
		per = A[i][0]
		for j in range(i + 1, n):
			if A[j][1] == 0:
				if A[j][0] > per:
					per = A[j][0]
					A[j][1] = 1
					answer += 1
print(answer)


n = int(input())
nums = list(map(int, input().split()))
nums.sort()
cnt = 0
for i in range(n):
	if nums[i] > nums[cnt]:
		cnt += 1
print(cnt)


n = int(input())
lst = list(map(int, input().split()))
d = {}
for (i, x) in enumerate(lst):
	if d.get(x) == None:
		d[x] = 0
	d[x] += 1
lst = list(d.values())
lst.sort()
length = len(lst)
(k, res) = (0, 0)
for (i, x) in enumerate(lst):
	res += (x - k) * (length - i - 1)
	k = x
print(res)


n = int(input())
a = list(map(int, input().split()))
a.sort()
mark = []
for i in range(0, n):
	mark.append(0)
b = []
for i in range(0, n):
	if mark[i] == 0:
		b.append(a[i])
		mark[i] = 1
		last = a[i]
		for j in range(i + 1, n):
			if a[j] > last and mark[j] == 0:
				b.append(a[j])
				mark[j] = 1
				last = a[j]
res = 0
for i in range(0, n - 1):
	if b[i] < b[i + 1]:
		res += 1
print(res)


n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
w = 0
for i in b:
	if b[w] < i:
		w += 1
print(w)


def clear(L):
	if sum(L) != 0:
		return True
	return False
n = int(input())
ans = 0
L = [0 for i in range(1001)]
l = list(map(int, input().split()))
for i in range(n):
	L[l[i]] += 1
while clear(L):
	count = 0
	for i in range(1, 1001):
		if L[i] > 0:
			count += 1
			L[i] -= 1
	ans += count - 1
print(ans)


from sys import stdin
a = int(stdin.readline())
A = stdin.readline().split()
MAX = 0
for k in A:
	MAX = max(MAX, A.count(k))
print(a - MAX)


input()
paintings = [int(i) for i in input().split()]
paintings.sort()
current = paintings.pop(0)
wonders = 0
while paintings:
	if current >= paintings[-1]:
		current = paintings.pop(0)
		continue
	for i in range(len(paintings)):
		if paintings[i] > current:
			wonders += 1
			current = paintings.pop(i)
			break
print(wonders)


import functools
import math
import sys
n = int(input())
a = list(map(int, input().split()))
ans = 0
a.sort()
while len(a) > 1:
	t = []
	for i in range(1, len(a)):
		if a[i] > a[i - 1]:
			ans += 1
		else:
			t.append(a[i])
	a = t
print(ans)


from math import *
from sys import *
from queue import *
n = int(input())
s = [int(z) for z in input().split()]
d = dict()
for i in s:
	if not d.get(i):
		d[i] = 0
	d[i] += 1
res = 0
h = n
while h:
	cur = []
	for i in range(1001):
		if d.get(i, 0):
			d[i] -= 1
			cur.append(i)
			h -= 1
	assert cur != []
	cur.sort()
	res += len(cur) - 1
print(res)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
freq = [0] * 1001
for i in range(0, 1001):
	freq[i] += a.count(i)
ans = 0
n = 0
while freq != [0] * 1001:
	n = 0
	for i in range(0, 1001):
		if freq[i] > 0:
			freq[i] -= 1
			n += 1
	ans += n - 1
print(ans)


def most_frequent(List):
	return max(set(List), key=List.count)
n = int(input())
l = list(map(int, input().split()))
m = set(l)
h = [0] * len(m)
print(n - 1 - (l.count(most_frequent(l)) - 1))


from collections import Counter
INF = 99999999
n = int(input())
a = list(map(int, input().split()))
cnt = [0] * 1010
for ax in a:
	cnt[ax] += 1
num = len(set(a))
sm = 0
while num > 1:
	mi = INF
	for x in cnt:
		if x > 0:
			mi = min(mi, x)
	if mi == INF:
		break
	sm += (num - 1) * mi
	for i in range(len(cnt)):
		if cnt[i] - mi == 0:
			num -= 1
		cnt[i] = max(cnt[i] - mi, 0)
print(sm)


from collections import Counter
print(int(input()) - max(Counter(input().split()).values()))


a = int(input())
d = dict()
for i in map(int, input().split()):
	d[i] = d.get(i, 0) + 1
z = sorted(d.values())
il = len(z)
s = 0
p = 0
for i in range(il - 1):
	s += (z[i] - p) * (il - i) - (z[i] - p)
	p = z[i]
print(s)


n = int(input())
a = list(map(int, input().split()))
li = max(a)
s = [0] * li
for i in range(n):
	s[a[i] - 1] += 1
s.sort()
c = 0
while s != [0] * li:
	for i in range(li):
		if s[i] > 0:
			c += 1
			s[i] -= 1
	c -= 1
print(c)


n = int(input())
b = []
a = list(map(int, input().split()))
for i in set(a):
	b.append(i)
d = []
c = []
count = 0
b.sort()
for i in b:
	c.append(a.count(i))
while c.count(0) != len(c):
	if sum(c) == 0:
		break
	else:
		for i in range(len(c)):
			if c[i] > 0:
				d.append(b[i])
				c[i] -= 1
for i in range(len(d) - 1):
	if d[i] < d[i + 1]:
		count += 1
print(count)


n = int(input())
A = [int(a) for a in input().split()]
A.sort()
last = A[0]
c = 0
aux = 0
for i in range(n):
	a = A[i]
	if a == last:
		aux += 1
	else:
		aux = 1
		last = A[i]
	c = max(c, aux)
print(n - c)


n = int(input().strip())
arr = list(map(int, input().strip().split()))
freq = [0] * 1001
for ele in arr:
	freq[ele] += 1
new = []
while any(freq):
	for i in range(1, 1001):
		if freq[i]:
			new.append(i)
			freq[i] -= 1
c = 0
for i in range(n - 1):
	if new[i] < new[i + 1]:
		c += 1
print(c)


from collections import Counter
n = int(input())
arr = [int(z) for z in input().split()]
c = Counter(arr)
ans = 0
for p in list(arr):
	ans = max(ans, c[p])
print(n - ans)


from collections import Counter
__author__ = 'aste'

def main():
	n = int(input())
	a = map(int, input().split())
	c = Counter(a)
	res = 0
	prev = 0
	for i in range(0, n):
		min_a = 1001
		max_a = 1001
		for (k, v) in c.items():
			if v == 0:
				continue
			if k < min_a:
				min_a = k
			if prev < k < max_a:
				max_a = k
		if max_a != 1001:
			c[max_a] -= 1
			res += 1
			prev = max_a
		else:
			c[min_a] -= 1
			prev = min_a
	print(res - 1)
main()


def main():
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for e in a:
		if e not in d:
			d[e] = 0
		d[e] += 1
	res = 0
	can_go = True
	while can_go:
		c = 0
		can_go = False
		for e in d:
			if d[e] != 0:
				d[e] -= 1
				c += 1
				can_go = True
		res += c - 1 if c > 1 else 0
	print(res)
main()


n = int(input())
a = [int(x) for x in input().split()]
b = {}
for x in a:
	if x in b:
		b[x] += 1
	else:
		b[x] = 1
summa = 0
while len(b) > 0:
	count = 0
	c = b.copy()
	for x in b:
		c[x] -= 1
		if c[x] == 0:
			c.pop(x)
		count += 1
	b = c.copy()
	summa += count - 1
print(summa)


n = int(input())
l = list(map(int, input().split()))
l.sort()
temp = []
i = 0
while i != n:
	a = l.count(l[i])
	if a > 1:
		temp.append(a - 1)
		i += a
	else:
		i += 1
temp.sort()
x = set(l)
if len(temp) == 0:
	print(n - 1)
else:
	print(len(x) - 1 + sum(temp) - temp[len(temp) - 1])


n = int(input())
a = sorted([int(i) for i in input().split()])
used = [False] * n
c = 0
while True:
	rep = False
	prev = None
	for (i, ai) in enumerate(a):
		if used[i]:
			continue
		rep = True
		if prev == ai:
			continue
		if prev is None or ai > prev:
			if prev is not None:
				c += 1
			prev = ai
			used[i] = True
	if not rep:
		break
print(c)


def f(a):
	if len(a) == 0:
		return 0
	r = []
	i = 0
	while i < len(a) - 1:
		if a[i] == a[i + 1]:
			r.append(a[i])
			i += 1
		else:
			i += 1
	return len(a) - len(r) + f(r) - 1
n = int(input())
a = list(map(int, input().split()))
a.sort()
print(f(a))


from collections import Counter
input()
a = map(int, input().split())
b = Counter(a)
b = list(b.values())
print(sum(b) - max(b))


n = int(input())
a = sorted(list(map(int, input().split())))
vis = [False for i in range(n)]
for i in range(n):
	for j in range(i + 1, n):
		if i == j:
			continue
		if a[i] < a[j] and (not vis[j]):
			vis[j] = True
			break
print(sum([fact for fact in vis]))


n = int(input())
L = [int(s) for s in input().split()]

def maximum(L):
	if len(L) <= 1:
		return 0
	if len(L) == 2:
		if L[0] == L[1]:
			return 0
		else:
			return 1
	r = 0
	while len(L) != 0:
		r += len(set(L)) - 1
		for i in set(L):
			L.remove(i)
	return r
print(maximum(L))


from collections import Counter

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	beauty = 0
	count = Counter(arr)
	values = list(count.values())
	while len(values) > 1:
		m = min(values)
		beauty += (len(values) - 1) * m
		for num in range(len(values)):
			values[num] = values[num] - m
		if max(values) == 0:
			values = []
		else:
			while min(values) == 0:
				values.remove(0)
	print(beauty)
main()


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
uni = [arr[0]]
unil = 0
count = [0]
for i in arr:
	if i == uni[unil]:
		count[unil] += 1
	else:
		uni.append(i)
		count.append(1)
		unil += 1
unil += 1
zero = 0
ans = 0
while unil > 1:
	p = min(count)
	i = 0
	while i < unil:
		if i != unil - 1:
			ans += p
		count[i] -= p
		if count[i] == 0:
			count.pop(i)
			unil -= 1
		else:
			i += 1
print(ans)


def prob():
	n = int(input())
	l = [int(x) for x in input().split()]
	print(n - max((l.count(i) for i in l)))
t = 1
for _ in range(0, t):
	prob()


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
u = [False] * n
uc = 0
b = []
while uc < n:
	p = -1
	for i in range(n):
		if not u[i] and a[i] != p:
			b += [a[i]]
			u[i] = True
			uc += 1
			p = a[i]
c = 0
for i in range(1, n):
	if b[i] > b[i - 1]:
		c += 1
print(c)


n = int(input())
arr = sorted(list(map(int, input().split())))
t = 0
i = 0
j = 0
while i < len(arr) and j < len(arr):
	if arr[i] < arr[j]:
		i += 1
		t += 1
		j += 1
	elif arr[i] == arr[j]:
		j += 1
print(t)


n = int(input())
lis = [*map(int, input().split())]
ans = [0] * 1001
a = []
b = c = d = 0
w = e = r = 0
for i in lis:
	ans[i] += 1
for i in ans:
	if i != 0:
		a.append(i)
a.sort()
b = len(a)
for i in range(b):
	d += (b - 1 - i) * (a[i] - r)
	r = a[i]
print(d)


import collections
n = int(input())
arr = list(map(int, input().split()))
cs = collections.Counter(arr)
ans = 0
while cs:
	ans += len(cs) - 1
	for k in list(cs.keys()):
		cs[k] -= 1
		if not cs[k]:
			del cs[k]
print(ans)