You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.

For instance, if we are given an array $[10, 20, 30, 40]$, we can permute it so that it becomes $[20, 40, 10, 30]$. Then on the first and the second positions the integers became larger ($20>10$, $40>20$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $2$. Read the note for the first example, there is one more demonstrative test case.

Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.


-----Input-----

The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array.


-----Output-----

Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.


-----Examples-----
Input
7
10 1 1 1 5 5 3

Output
4

Input
5
1 1 1 1 1

Output
0



-----Note-----

In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.

In the second sample, there is no way to increase any element with a permutation, so the answer is 0.

Difficulty: EASY
Tags: Combinatorics

Amortized analysis

Sorting

Mathematics

Data structures
Skill types: Data structures

Sorting

Amortized analysis

Starter code:

Solutions:
from collections import Counter as co
x = int(input())
y = list(map(int, input().split()))
print(x - max(co(y).values()))


n = int(input())
c = [int(x) for x in input().split(' ')]
c.sort()
i = 0
a = 0
for j in range(n):
	if c[i] < c[j]:
		a += 1
		i += 1
print(a)


n = int(input())
a = list(map(int, input().split()))
f = {}
ans = n - 1
for x in a:
	f[x] = f.get(x, 0) + 1
	ans = min(ans, n - f[x])
print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
r = 0
s = 0
m = 1
for i in range(1, n):
	if arr[i] < arr[i - 1]:
		s += m
		m = 1
	else:
		m += 1
	if s:
		s -= 1
		r += 1
print(r)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
(i, j) = (0, 1)
while i < n and j < n:
	if a[i] < a[j]:
		ans += 1
		i += 1
		j += 1
	else:
		j += 1
print(ans)


import sys
import math
import collections
inp = lambda : sys.stdin.readline()
m = 998244353
n = int(inp())
a = list(map(int, inp().split()))
a.sort()
p1 = n - 1
p2 = n - 2
ct = 0
while p2 >= 0:
	if a[p1] > a[p2]:
		p2 -= 1
		p1 -= 1
		ct += 1
		continue
	while p2 >= 0 and a[p1] <= a[p2]:
		p2 -= 1
	if p2 == -1:
		break
	p2 -= 1
	p1 -= 1
	ct += 1
print(ct)


input()
a = list(sorted(map(int, input().split())))
j = 0
for i in range(1, len(a)):
	if a[i] > a[j]:
		j += 1
print(j)


n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
d = 0
j = 0
m = 1
for i in range(1, len(a)):
	if a[i] == a[j]:
		m += 1
	else:
		if m > d:
			d = m
		m = 1
		j = i
if m > d:
	d = m
print(len(a) - d)


from collections import defaultdict, Counter, deque
read = lambda : list(map(int, input().split()))
getinfo = lambda grid: print(list(map(print, grid)))
p = lambda x: print(x, end=' ')
inf = float('inf')
mod = 10 ** 9 + 7
n = int(input())
a = read()
d = Counter(a)
v = sorted(d.keys(), reverse=True)
a.sort(reverse=True)
(res, j) = (0, 0)
for i in range(n):
	while j < len(v) and a[i] <= v[j]:
		j += 1
	if j >= len(v):
		break
	d[v[j]] -= 1
	res += 1
	if d[v[j]] == 0:
		j += 1
print(res)


import sys, heapq
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
val = min(arr)
q = []
for i in range(n):
	if arr[i] > val:
		heapq.heappush(q, arr[i])
arr.sort()
ans = 0
for i in range(n):
	while q:
		if q[0] > arr[i]:
			heapq.heappop(q)
			ans += 1
			break
		heapq.heappop(q)
print(ans)


n = int(input())
li = list(map(int, input().split(' ')))
li.sort()
ma = 1
count = 1
i = 0
while i < len(li) - 1:
	if li[i] == li[i + 1]:
		count += 1
		ma = max(ma, count)
	else:
		count = 1
	i += 1
print(n - ma)


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


from collections import Counter

def main():
	input()
	cnt = Counter(map(int, input().split()))
	(a, *rest) = sorted(cnt.keys())
	(pool, res) = (cnt[a], 0)
	for a in rest:
		c = cnt[a]
		if pool < c:
			res += pool
			pool = c
		else:
			res += c
	print(res)
main()


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


from collections import Counter
n = int(input())
print(n - max(Counter([int(x) for x in input().split()]).values()))


n = int(input())
A = list(map(int, input().split()))
A.sort()
A.append(0)
B = []
z = 0
k = 1
for i in range(1, n + 1):
	if A[i] == A[i - 1]:
		k += 1
	else:
		B.append(k)
		k = 1
n -= B[0]
for i in range(1, len(B)):
	a = B[i] - B[i - 1]
	if a >= 0:
		if a >= z:
			n -= a - z
			z = 0
		else:
			n -= 0
			z -= a
	else:
		n -= 0
		z += abs(a)
print(n)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
count = 0
(l, r) = (0, 1)
while l < n and r < n:
	if a[l] > a[r]:
		l += 1
		r += 1
		count += 1
	else:
		r += 1
print(count)


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


from collections import Counter

def pro(arr):
	dic = Counter(arr)
	lst = []
	for (i, j) in dic.items():
		lst.append((i, j))
	lst = sorted(lst, key=lambda x: (-x[1], x[0]))
	print(len(arr) - lst[0][1])
n = int(input())
arr = list(map(int, input().split()))
pro(arr)


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial
from collections import *
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
tup = lambda : map(int, sys.stdin.buffer.readline().split())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().strip('\n')

def grid(r, c):
	return [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
localsys = 0
start_time = time.time()
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
n = I()
ls = lint()
(d, mx) = (defaultdict(int), 0)
for i in ls:
	d[i] += 1
	mx = max(mx, d[i])
print(n - mx)
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


import sys
input = sys.stdin.readline
from math import log2, log, ceil

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

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

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

def upper_bound(a, x, lo=0):
	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:
		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:
			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):
	while x != link[x]:
		x = link[x]
	return x

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)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.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

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
a = int_array()
a.sort()
i = 0
j = 1
ans = 0
while i < n and j < n:
	if a[j] > a[i]:
		ans += 1
		i += 1
		j += 1
	else:
		j += 1
print(ans)


def count_sort(mass, st):
	i = st
	while i < len(mass):
		if mass[i] != mass[st]:
			break
		i += 1
	return i - st
n = int(input())
a = [int(x) for x in input().split(' ')]
a.sort()
i = a.count(a[0])
left = i
res = n - left
while i < len(a):
	count = count_sort(a, i)
	i += count
	left -= count
	if left < 0:
		res += left
		left = 0
	left += count
print(res)


from math import factorial
from collections import Counter
n = int(input())
nums = list(map(int, input().split()))
nums.sort()
i = 0
for num in nums:
	if num > nums[i]:
		i += 1
print(i)


(m, n) = (int(input()), sorted(input().split()))
i = 0
for j in range(0, m):
	if n[j] > n[i]:
		i += 1
print(i)


n = int(input())
s = input().split()
dict1 = {}
for x in s:
	dict1[x] = dict1.get(x, 0) + 1
print(n - max(dict1.values()))


n = int(input())
A = [*sorted(map(int, input().split()))]
B = list(sorted(A))
(i, j, c) = (0, 0, 0)
while i < len(A) and j < len(B):
	if A[i] <= B[j]:
		i += 1
	else:
		i += 1
		j += 1
		c += 1
print(c)


n = int(input())
l = list(map(int, input().split()))
l.sort()
taken = [0] * n
c = 0
j = 0
for i in range(0, n):
	f = 0
	while j < n:
		if taken[j] == 0 and l[j] > l[i]:
			f = 1
			break
		else:
			j = j + 1
	if f == 1:
		taken[j] = 1
		c = c + 1
	else:
		break
print(c)


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


from sys import stdin
input = stdin.readline
from heapq import heapify, heappush, heappop, heappushpop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from bisect import bisect_left as bl, bisect_right as br
from itertools import combinations as c, permutations as p
from math import factorial as f, ceil, gcd, sqrt, log
mi = lambda : map(int, input().split())
ii = lambda : int(input())
li = lambda : list(map(int, input().split()))
mati = lambda r: [li() for _ in range(r)]
lcm = lambda a, b: a * b // gcd(a, b)

def solve():
	n = ii()
	arr = li()
	arr.sort()
	d = {}
	for x in arr:
		if x not in d:
			d[x] = 1
		else:
			d[x] += 1
	p = max(d.values())
	print(n - p)
for _ in range(1):
	solve()


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
temp = [i for i in arr]
i = 0
j = 0
ans = 0
while i < n and j < n:
	while j < n and arr[j] <= arr[i]:
		j += 1
	if j == n:
		break
	ans += 1
	i += 1
	j += 1
print(ans)


n = int(input())
l = sorted(list(map(int, input().split())))
x = [1]
ans = 1
for i in range(1, n):
	if l[i] == l[i - 1]:
		ans += 1
	else:
		x.append(ans)
		ans = 1
	if i == n - 1 and l[i] == l[i - 1]:
		x.append(ans)
print(n - max(x))


import math
n = int(input())
lst = list(map(int, input().strip().split(' ')))
if n == 1:
	print(0)
else:
	lst.sort()
	i = 0
	j = 1
	c = 0
	while i < n and j < n:
		if lst[j] > lst[i]:
			i += 1
			j += 1
			c += 1
		else:
			j += 1
	print(c)


def main():
	t = 1
	for _ in range(t):
		n = int(input())
		tab = list(map(int, input().split()))
		inc = 0
		nb_dup = 0
		nb_pp = 0
		tab.sort()
		l = -1
		for x in range(n):
			if tab[x] == l:
				nb_dup += 1
			else:
				inc += 0
				nb_pp += nb_dup
				nb_dup = 1
			if nb_pp > 0:
				inc += 1
				nb_pp -= 1
			l = tab[x]
		print(inc)
main()


n = int(input())
a = [int(i) for i in input().split()]
d = {}
for i in a:
	d[i] = 0
for i in a:
	d[i] += 1
ans = n - max(d.values())
print(ans)


import math
n = int(input())
a = list(map(int, input().split()))
mydict = {}
for x in a:
	mydict[x] = mydict.get(x, 0) + 1
ans = n - max(mydict.values())
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
cnt = 0
(l, r) = (0, 1)
while r < n:
	if a[l] < a[r]:
		l += 1
		cnt += 1
	r += 1
print(cnt)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a = Counter(a)
b = sorted(a.keys())
s = a[b[0]]
ss = 0
for i in b[1:]:
	if s <= a[i]:
		ss += s
		s = a[i]
	else:
		ss += a[i]
print(ss)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
res = 0
cur = 0
for i in sorted(c.keys()):
	d = min(c[i], cur)
	cur -= d
	res += d
	cur += c[i]
print(res)


from bisect import bisect_left
from collections import defaultdict
al = defaultdict(int)
a = int(input())
z = list(map(int, input().split()))
z.sort()
l = 0
r = 0
count = 0
while l <= r and r < len(z):
	if z[r] > z[l]:
		count += 1
		l += 1
		r += 1
	else:
		r += 1
print(count)


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


n = int(input())
l = list(map(int, input().split()))
l.sort()
i = 0
c = 0
stack = []
k = 1
i = 0
while i < n - 1 and k < n:
	stack.append(l[i])
	if l[i] != l[i + 1]:
		if k <= i:
			k = i + 1
		while k < n and len(stack):
			stack.pop()
			c = c + 1
			k = k + 1
	i = i + 1
print(c)


(_, x, d) = (int(input()), 0, {})
for i in map(int, input().split()):
	try:
		d[i] += 1
	except:
		d[i] = 1
print(_ - max(d.values()))


3

def solve(N, A):
	A.sort()
	i = 0
	j = 0
	c = 0
	while j < N:
		while j < N and A[j] == A[i]:
			j += 1
		if j == N:
			break
		c += 1
		i += 1
		j += 1
	return c

def main():
	N = int(input())
	A = [int(e) for e in input().split(' ')]
	print(solve(N, A))

def __starting_point():
	main()
__starting_point()


n = int(input())
arr = [int(c) for c in input().split()]
ans = 0
temp = sorted(arr)
arr.sort()
i = n - 1
curr = temp.pop()
while i >= 0:
	if arr[i] < curr:
		ans += 1
		curr = temp.pop()
		i -= 1
	else:
		i -= 1
print(ans)


from heapq import *
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
j = 0
for i in range(n):
	if a[i] > a[j]:
		j += 1
print(j)


n = int(input())
a = list(map(int, input().split()))
a.sort()
(i, j) = (0, 0)
res = 0
while i < n and j < n:
	while j < n and a[i] != a[j]:
		j += 1
		i += 1
		res += 1
	while j < n and a[i] == a[j]:
		j += 1
print(res)


def solution(n, num_array):
	if len(num_array) == 1:
		return 0
	num_array.sort()
	idx1 = 0
	idx2 = 1
	res = 0
	while idx2 < len(num_array):
		num1 = num_array[idx1]
		num2 = num_array[idx2]
		if num1 < num2:
			res += 1
			idx1 += 1
		idx2 += 1
	return res
n = input()
num_array = list(map(int, input().split()))
print(solution(n, num_array))


from collections import Counter
n = int(input())
List = [int(x) for x in input().split()]
Dict = Counter(List)
Max = 0
for i in Dict.keys():
	Max = max(Dict[i], Max)
print(n - Max)


n = int(input())
a = list(map(int, input().split()))
Mp = dict()
for e in a:
	if e in Mp:
		Mp[e] += 1
	else:
		Mp[e] = 1
mx = -1
for k in Mp:
	mx = max(mx, Mp[k])
print(n - mx)


from collections import Counter
length = int(input())
array = list(map(int, input().split()))
dic = Counter(array)
value_list = list(dic.values())
print(len(array) - max(value_list))


from sys import stdin as sin

def aint():
	return int(input())

def amap():
	return map(int, sin.readline().split())

def alist():
	return list(map(int, sin.readline().split()))

def astr():
	return input()
for _ in range(1):
	n = aint()
	l = alist()
	l.sort()
	ans = 0
	r = 1
	e = 1
	for i in range(1, n):
		r += 1
		if l[i] == l[i - 1]:
			e += 1
		else:
			e = 1
		if r - e > 0:
			ans += 1
			r -= 1
	print(ans)


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


from io import BytesIO, IOBase
import sys, os
inpl = lambda : list(map(int, input().split()))
inpm = lambda : map(int, input().split())
inpi = lambda : int(input())
inp = lambda : input()
(rev, ra, l) = (reversed, range, len)
P = print
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')
from bisect import bisect_left as bl
from bisect import bisect_right as br
import sys, operator, math, operator
from collections import Counter
import random
n = inpi()
li = inpl()
li.sort()
(c, ans) = (0, 0)
for i in ra(n):
	if li[c] < li[i]:
		c += 1
		ans += 1
P(ans)


n = int(input())
l = list(map(int, input().split()))
d = dict()
for i in range(n):
	try:
		d[l[i]]
	except:
		d[l[i]] = 1
	else:
		d[l[i]] += 1
x = max(d.values())
print(n - x)


n = int(input())
l = list(map(int, input().split()))
l.sort()
i = 0
c = 0
j = 0
while i < n and j < n:
	while j < n and l[i] == l[j]:
		j += 1
	if j >= n:
		break
	i += 1
	j += 1
	c += 1
print(c)


import sys
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def read():
	tc = 0
	if tc:
		input = sys.stdin.readline
	else:
		sys.stdin = open('input1.txt', 'r')
		sys.stdout = open('output1.txt', 'w')

def solve():
	n = ii()
	a = li()
	a.sort(reverse=True)
	i = 0
	j = 0
	ans = 0
	while i < n:
		while j < n and a[i] <= a[j]:
			j += 1
		if j == n:
			break
		if a[i] > a[j]:
			ans += 1
		i += 1
		j += 1
	print(ans)
solve()


n = int(input())
H = sorted(list(map(int, input().split())))
G = list(reversed(H))
counter = 0
i = 0
j = n - 1
while i < n and j >= 0:
	if G[j] > H[i]:
		counter += 1
		i += 1
	j -= 1
print(counter)


n = int(input())
b = sorted(map(int, input().split()))
ans = 0
ind = -1
for i in range(n):
	if b[i] > b[0]:
		ind = i
		break
if ind == -1:
	print(0)
else:
	for i in range(n):
		if b[i] > b[ans]:
			ans += 1
	print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
temp = set(a)
s = list(temp)
s.sort()
mp = {i: 0 for i in s}
for i in a:
	mp[i] += 1
curr = 0
nxt = 1
ans = 0
mpc = mp.copy()
while nxt < len(s):
	if curr == nxt:
		nxt += 1
		continue
	mi = min(mp[s[curr]], mpc[s[nxt]])
	ans += mi
	mp[s[curr]] -= mi
	mpc[s[nxt]] -= mi
	if mp[s[curr]] <= 0:
		curr += 1
	if mpc[s[nxt]] <= 0:
		nxt += 1
print(ans)


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


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


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


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = 1
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)

def output(answer):
	stdout.write(str(answer) + '\n')
n = int(z())
arr = zzz()
d = {}
for i in arr:
	try:
		d[i]
	except:
		d[i] = 0
	d[i] += 1
mx = max(d.values())
print(n - mx)


n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
mi = b[::-1].index(min(a))
mi = n - mi
ans = 0
if a.count(min(a)) == n:
	print('0')
else:
	i = 0
	while i < n:
		if mi == n:
			print(ans)
			exit()
		elif b[i] < b[mi]:
			mi += 1
			ans += 1
			i += 1
		else:
			mi += 1


def Solve():
	n = int(input())
	list = input().split()
	arr = [0] * n
	for i in range(len(list)):
		arr[i] = int(list[i])
	arr.sort()
	j = 0
	for i in range(1, n):
		if arr[i] > arr[j]:
			j += 1
	print(j)
Solve()


n = int(input())
a = list(map(int, input().split()))
count = 0
dict = {}
for i in a:
	if i in dict:
		dict[i] += 1
	else:
		dict[i] = 1
maxi = 0
for i in dict:
	maxi = max(dict[i], maxi)
print(n - maxi)


from collections import *
n = int(input())
s = list(map(int, input().split()))
x = max(Counter(s).values())
print(n - x)


from collections import Counter

def most_frequent(List):
	occurence_count = Counter(List)
	return occurence_count.most_common(1)[0][0]
n = int(input())
a = list(map(int, input().split()))
print(n - a.count(most_frequent(a)))


n = int(input())
arr = sorted([int(a) for a in input().split()])
j = 0
for i in range(0, n):
	if arr[i] > arr[j]:
		j += 1
print(j)


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


n = int(input())
arr = list(sorted(map(int, input().split()), reverse=True))
idx = 0
for v in arr:
	if v < arr[idx]:
		idx += 1
print(idx)


(n, curr, mx, prev) = (int(input()), 1, 1, 0)
for i in sorted(map(int, input().split())):
	if i > prev:
		(mx, curr) = (max(mx, curr), 1)
	else:
		curr += 1
	prev = i
print(n - max(mx, curr))


n = int(input())
a = list(map(int, input().split()))
b = [i for i in a]
a.sort()
b.sort()
c = 0
j = 0
for i in b:
	if i > a[j]:
		c += 1
		j += 1
print(c)


def main():
	n = int(input())
	li = list(map(int, input().split()))
	li.sort()
	li.reverse()
	(i, j, count) = (0, 1, 0)
	while j < len(li):
		if li[j] < li[i]:
			j += 1
			i += 1
			count += 1
		else:
			j += 1
	print(count)
main()


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


from sys import stdin, stdout
from collections import Counter
import math
I = lambda : map(int, stdin.readline().split())
I1 = stdin.readline()
n = int(I1)
a = list(I())
print(n - max(Counter(a).values()))


n = int(input())
l1 = list(map(int, input().split()))
l2 = []
for i in l1:
	l2.append(i)
l2.sort()
ss = 0
for i in range(n):
	if l2[i] != l2[0]:
		ss = i
		break
ans = 0
x = 0
while 1:
	if ss == n:
		break
	if l2[x] < l2[ss]:
		x += 1
		ans += 1
	ss += 1
print(ans)


def go():
	n = int(input())
	a = sorted([int(i) for i in input().split(' ')])
	total = i = j = 0
	while j < n:
		if a[i] == a[j]:
			j += 1
		else:
			break
	while j < n:
		if a[i] < a[j]:
			total += 1
			i += 1
		j += 1
	return total
print(go())


def readints():
	return [int(x) for x in input().strip().split()]

def main():
	n = readints()[0]
	a = sorted(readints())
	marker = 0
	for i in range(n):
		if a[i] > a[0]:
			break
		marker += 1
	ans = 0
	for i in range(n):
		while marker < n:
			if a[i] < a[marker]:
				ans += 1
				marker += 1
				break
			marker += 1
	print(ans)

def __starting_point():
	main()
__starting_point()


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


import sys
from collections import deque, defaultdict
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def main():
	n = ii()
	arr = sorted(li())
	i = 0
	j = 1
	if n == 1:
		print(0)
	else:
		cnt = 0
		while j < n:
			if arr[i] < arr[j]:
				cnt += 1
				i += 1
			j += 1
		print(cnt)
main()


def outLarge(length):
	temp = [int(i) for i in input().split()]
	temp = sorted(temp)
	(count, l, r) = (0, 0, 1)
	while r < length:
		if temp[l] < temp[r]:
			count += 1
			l += 1
			r += 1
		else:
			r += 1
	return count
length = int(input())
print(outLarge(length))


from collections import defaultdict, Counter
from heapq import heappop, heappush
from collections import deque
n = int(input())
l = list(map(int, input().split()))
c = Counter(l)
s = []
for i in c:
	s.append([i, c[i]])
s.sort()
if len(s) == 1:
	print(0)
else:
	ans = 0
	q = deque()
	for (i, j) in s:
		if not q:
			for k in range(j):
				q.append(i)
		elif i > q[0]:
			p = 0
			while q and p < j:
				q.popleft()
				p += 1
				ans += 1
			p = 0
			while p < j:
				q.append(i)
				p += 1
	print(ans)


n = int(input())
a = [int(i) for i in input().split()]
fr = [0 for i in range(n)]
a.sort()
mx = a[0]
fr[0] = 1
idx = 0
for i in a[1:]:
	if i > mx:
		mx = i
		idx += 1
		fr[idx] = 1
	else:
		fr[idx] += 1
lt = [0 for i in range(0, idx + 1)]
res = 0
done = 0
for i in range(1, idx + 1):
	lt[i] = lt[i - 1] + fr[i - 1]
	res += max(min(lt[i] - done, fr[i]), 0)
	done += max(min(lt[i] - done, fr[i]), 0)
print(res)


import collections
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
deq = collections.deque([a[0]])
for a_i in a[1:]:
	if deq[0] > a_i:
		deq.popleft()
	deq.append(a_i)
print(n - len(deq))


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

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))
testcases = 1
for _ in range(testcases):
	n = vary(1)
	num = array_int()
	ct = makedict(num)
	print(n - max(ct.values()))


n = int(input())
z = list(map(int, input().split()))
from collections import Counter
c = Counter(z)
tofill = 0
ans = 0
for val in sorted(c):
	if tofill > 0:
		upd = min(tofill, c[val])
		ans += upd
		tofill -= upd
	tofill += c[val]
print(ans)


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


import sys
from collections import defaultdict
input = sys.stdin.readline
n = int(input())
lis = list(map(int, input().split()))
c = 0
lis.sort(reverse=True)
j = 0
for i in range(n):
	while j < n and lis[i] <= lis[j]:
		j += 1
	if j < n:
		c += 1
		j += 1
	else:
		break
print(c)


n = int(input())
arr = [int(t) for t in input().split()]
arr.sort()
nx = 0
i = 0
res = 0
while i < n:
	j = i
	while j < n and arr[i] == arr[j]:
		j += 1
	nx = max(nx, j)
	t = min(j - i, n - nx)
	nx += t
	nx = min(nx, n)
	res += t
	i = j
print(res)


import sys
inf = float('inf')
ip = lambda : sys.stdin.readline()
split = lambda : ip().split(' ')
ip1 = lambda : map(int, split())
arr = lambda : list(ip1())
arr1 = lambda n: [arr() for _ in range(n)]
n = int(ip())
a = arr()
a.sort()
(i, j) = (n - 1, n - 2)
ans = 0
while j >= 0 and i >= 0:
	if a[j] != a[i]:
		j -= 1
		ans += 1
	else:
		if j == 0:
			break
		while j >= 0 and a[j] == a[i]:
			j -= 1
		if j >= 0:
			ans += 1
			j -= 1
	i -= 1
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
i = 0
j = 1
while i < n and j < n:
	if a[i] < a[j]:
		i += 1
		j += 1
	else:
		j += 1
print(i)


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


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n = ii()
l = sorted(il())
i = 0
j = 0
c = 0
while i < n and j < n:
	if l[j] > l[i]:
		i += 1
		c += 1
	j += 1
print(c)


from collections import Counter

def perestanovka(lst):
	c = Counter(lst).most_common(2)
	return len(lst) - max(c, key=lambda elem: elem[1])[1]
n = int(input())
a = [int(i) for i in input().split()]
print(perestanovka(a))


n = int(input())
l = list(map(int, input().split()))
l.sort()
i = 1
a = l[0]
maxe = 0
conter = 1
while i < n:
	if l[i] == a:
		conter += 1
	else:
		maxe = max(conter, maxe)
		conter = 1
		a = l[i]
	i += 1
maxe = max(conter, maxe)
print(n - maxe)


n = int(input())
l = sorted(list(map(int, input().split())))
(i, j, c) = (0, 1, 0)
while j != n:
	if l[j] > l[i]:
		c += 1
		i += 1
	j += 1
print(c)


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


from bisect import bisect_left, bisect_right
import os
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque, defaultdict
import math
import heapq
import re

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
LOW = 'abcdefghijklmnopqrstuvwxyz'
UP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def sieve(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
	return prime

def main():
	n = iin()
	l = ain()
	l.sort()
	ans = 0
	d = deque([l[-1]])
	for i in range(n - 2, -1, -1):
		if d[0] > l[i]:
			ans += 1
			d.popleft()
			d.append(l[i])
		else:
			d.append(l[i])
	print(ans)
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')
if os.getcwd() == 'D:\\code':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


x = int(input())
a = list(map(int, input().split()))
a.sort()
j = 0
i = 0
k = 0
while i < x and j < x:
	if a[i] < a[j]:
		i += 1
		j += 1
		k += 1
	else:
		j += 1
print(k)


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


I = lambda : map(int, input().rstrip().split())
n = int(input())
a = list(sorted(I()))
t = 0
j = n - 1
for i in range(n - 2, -1, -1):
	if a[i] < a[j]:
		t += 1
		j -= 1
print(t)


from sys import stdin, stdout
from collections import Counter
n = int(stdin.readline().strip())
arr = [int(num) for num in stdin.readline().strip().split()]
counts = Counter(arr)
arr = sorted(counts.keys())
(l, r, count, cur) = (0, 1, 0, counts[arr[1]] if 1 < len(arr) else 0)
while l < r and r < n:
	if cur > counts.get(arr[l]):
		count += counts.get(arr[l])
		cur -= counts.get(arr[l])
		counts[arr[l]] = 0
		l += 1
		if l == r:
			r += 1
			cur = counts[arr[r]] if r < len(arr) else 0
	else:
		count += cur
		counts[arr[l]] = counts[arr[l]] - cur
		if counts[arr[l]] == 0:
			l += 1
		r += 1
		cur = counts[arr[r]] if r < len(arr) else 0
stdout.write(f'{count}')


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = sorted(list(set(a)))
d = Counter(a)
(ans, domi) = (0, 0)
for i in range(1, len(b)):
	w = d[b[i - 1]] - d[b[i]]
	if w > 0:
		domi += w
	elif w < 0:
		z = min(domi, abs(w))
		ans += z
		domi -= z
	ans += min(d[b[i - 1]], d[b[i]])
print(ans)