Problem:
 Score : 300 points    Problem Statement You are given a sequence of positive integers of length N , a = (a_1, a_2, ..., a_N) .
Your objective is to remove some of the elements in a so that a will be a good sequence .  Here, an sequence b is a good sequence when the following condition holds true:   For each element x in b , the value x occurs exactly x times in b .   For example, (3, 3, 3) , (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.  Find the minimum number of elements that needs to be removed so that a will be a good sequence.      Constraints  1 \leq N \leq 10^5  a_i is an integer.  1 \leq a_i \leq 10^9         Input Input is given from Standard Input in the following format:  N  a_1  a_2  ...  a_N       Output Print the minimum number of elements that needs to be removed so that a will be a good sequence.        Sample Input 1 4
3 3 3 3      Sample Output 1 1  We can, for example, remove one occurrence of 3 . Then, (3, 3, 3) is a good sequence.       Sample Input 2 5
2 4 1 4 2      Sample Output 2 2  We can, for example, remove two occurrences of 4 . Then, (2, 1, 2) is a good sequence.       Sample Input 3 6
1 2 2 3 3 3      Sample Output 3 0       Sample Input 4 1
1000000000      Sample Output 4 1  Remove one occurrence of 10^9 . Then, () is a good sequence.       Sample Input 5 8
2 7 1 8 2 8 1 8      Sample Output 5 5

Solution (Python):

import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
A = zz()
dic = defaultdict(int)
for a in A:
    dic[a] += 1
ans = 0
for key in dic:
    if (dic[key] >= key):
        
        ans += (dic[key]-key)
    else:
        ans += dic[key]
print(ans)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
d=dict()
for v in l:
    if v in d:
        d[v]+=1
    else:
        d[v]=1
c=0
for k, v in d.items():
    if k<=v:
        c+=v-k
    else:
        c+=v
print(c)

Solution (Python):
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
c_value = list(c.values())
c_key = list(c.keys())
cnt = 0

for i in range(len(c_key)):
    if c_key[i] > c_value[i]:
        cnt += c_value[i]
    elif c_value[i] > c_key[i]:
        cnt += c_value[i]- c_key[i]
print(cnt)

Solution (Python):
from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))

a = [i for i in a.items() if i[0]!=i[1]]
ans = 0

for i, j in a:
    if i>j:
        ans += j
    else:
        ans += j-i

print(ans)

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd





def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    d = defaultdict(int)
    ans = 0
    for e in a:
        if d[e] < e:
            d[e] += 1
        else:
            ans += 1

    for e in d:
        if d[e] != e:
            ans += d[e]
    print(ans)
        
    

    
    

t = 1

for case in range(1,t+1):
    ans = solve()


"""

2 3 4 4
3 4 4
2 3 4
2 3 4
2 4 4


"""

Solution (Python):
from collections import Counter


N = int(input())
a = list(map(int, input().split()))

ans = 0
for k, v in Counter(a).items():
    if k < v:
        ans += v - k
    elif k > v:
        ans += v

print(ans)

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
c = Counter(readInts())

ans = 0
for i in c:
	if c[i]-i>0:
		ans+=c[i]-i
	elif c[i]-i<0:
		ans+=c[i]

print(ans)

Solution (Python):
from collections import Counter

N = input()
A = list(map(int, input().split()))
counter = Counter(A)

ans = 0
for number, count in counter.items():
    if count < number:
        ans += count
    else:
        ans += count - number

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

dic = {}
for i in range(N):
    data = A[i]
    if data in dic:  dic[data] += 1
    else:  dic[data] = 1
        
ans = 0
for i in dic:
    if dic[i] > i:  ans += dic[i] - i
    elif dic[i] < i:  ans += dic[i]
print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

a.sort()

import collections
c = collections.Counter(a)

ans = 0
for i in c.most_common():
    if i[0] <= i[1]:
        ans += i[1] - i[0]
    else:
        ans += i[1]

print(ans)

Solution (Python):
N = int(input())
*A, = map(int, input().split())
dic = {}
ans = 0
for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1
for k, v in dic.items():
    if k == v:
        continue
    elif k > v:
        ans += v
    else:
        ans += v - k
print(ans)

Solution (Python):
N = int(input())
A_LI = sorted(map(int, input().split()))
a_dict = {}
ans = 0
pre = None
for a in A_LI:
    if a not in a_dict:
        if pre in a_dict:
            
            if a_dict[pre] < pre:
                ans += a_dict[pre]
            else:
                ans += a_dict[pre] - pre
        pre = a
        a_dict[a] = 1
    else:
        a_dict[a] += 1

if a_dict[pre] < pre:
    ans += a_dict[pre]
else:
    ans += a_dict[pre] - pre
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))

from collections import Counter
A_=Counter(A)

A_key=list(A_.keys())
A_key.sort()

ans=0
for k in A_key:
    if k > A_[k]:
        ans += A_[k]
    else:
        ans += A_[k]-k
print(ans)

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
    if a[i] not in d:
        d[a[i]] = 1
    else:
        d[a[i]] += 1
ans = 0
for k, v in d.items():
    if k > v:
        
        ans += v
    elif k < v:
        
        ans += v - k
print(ans)

Solution (Python):

import collections
N = int(input())
A=  list(map(int,input().split()))

A.sort()

c = collections.Counter(A)
A_ = list(set(A))
ans = 0
for a in A_:
    
    if a > c[a]:
        ans += c[a]
    else:
        ans += c[a]-a
    
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
old = A[0]
a = 1
ans = 0
for i in range(1, N):
    cur = A[i]
    if cur == old:
        a += 1
    else:
        if old <= a:
            ans += a - old
        else:
            ans += a
        a = 1
    old = cur
if old <= a:
    ans += a - old
else:
    ans += a
print(ans)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate 

from collections import deque,defaultdict,Counter
import decimal
import re











import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
dic = Counter(A)
ans = 0
for k,v in dic.items():
    if k < v:
        ans += v - k
    elif k > v:
        ans += v
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
C = {}
for i in range(N):
    a = A[i]
    if a not in C:
        C[a] = 0
    C[a] += 1
cnt = 0
for a in C:
    if C[a]<a:
        cnt += C[a]
    else:
        cnt += C[a]-a
print(cnt)

Solution (Python):
from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
cnt = 0
for x,y in a.items():
    if x==y: continue
    if x>y: cnt += y
    else: cnt += y-x
print(cnt)

Solution (Python):
from collections import Counter
def solve():
  ans = 0
  N = int(input())
  A = list(map(int, input().split()))
  c = Counter(A)
  for k,v in c.items():
    if k<=v:
      ans += v-k
    else:
      ans += v
  return ans
print(solve())

Solution (Python):
import collections

N = int(input())
A = list(map(int,input().split()))

B = collections.Counter(A)


C = list(B.keys())


ans = 0
for c in C:
    if c != B[c] and B[c] > c:
        ans += B[c]-c
    elif c != B[c] and B[c] < c:
        ans += B[c]
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ans = 0

for i in c.keys():
    if c[i] < i:
        ans += c[i]
    elif c[i] > i:
        ans += c[i] - i
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
A = Counter(map(int, input().split()))
ans = 0
for i,j in A.items():
    if i < j:
        ans += j - i
    elif i >j:
        ans += j
print(ans)

Solution (Python):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

ri()
a = rl()
d = collections.Counter(a)
ans = 0
for k, v in d.items():
    if k <= v:
        ans += (v-k)
    else:
        ans += v
print(ans)

Solution (Python):
from collections import Counter


def main():
    n = int(input())
    As = list(map(int, input().split()))
    ans = 0
    for num, count in Counter(As).items():
        if count >= num:
            ans += (count - num)
        else:
            ans += count
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
d = c.most_common()

ans = 0
for i in range(len(d)):
  num = d[i][0]
  cnt = d[i][1]
  if num > cnt:
    ans += cnt
  elif num < cnt:
    ans += cnt-num
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

count = Counter(a)

ans = 0
for i in count.items():
  if i[1] < i[0]: ans += i[1]
  else: ans += abs(i[1]-i[0])
    
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
ans=0
for i in a:
    if i>n:
        ans+=1
    else:
        b[i-1]+=1
for i in range(n):
    if b[i]>i:
        ans+=b[i]-i-1
    else:
        ans+=b[i]
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

cnt = [0] * (n+1)
res = 0
for v in a:
    if v <= n:
        cnt[v] += 1
    else:
        res += 1

for i in range(1, n+1):
    if cnt[i] < i:
        res += cnt[i]
    else:
        res += cnt[i] - i

print(res)

Solution (Python):
from collections import Counter


N = int(input())
res = sum([c - n if c >= n else c for n, c in Counter(list(map(int, input().split()))).most_common()])

print(res)

Solution (Python):
from collections import Counter


N = int(input())
A = Counter(list(map(int, input().split())))


res = 0
for n, c in A.most_common():
    if c >= n:
        res += c - n
    else:
        res += c

print(res)

Solution (Python):
from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
cnt = 0
for k, v in Counter(a).items():
    if k > v:
        cnt += v
    else:
        cnt += (v-k)
print(cnt)

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)
ans = 0
for k, v in c.items():
   if k < v:
      ans += v - k
   elif k > v:
      ans += v
print(ans)

Solution (Python):
from collections import Counter
n=int(input())
lst=list(map(int,input().split()))
c=Counter(lst)
c=c.most_common()
ans=0
for i in range(len(c)):
    if c[i][0]<c[i][1]:
        ans+=(c[i][1]-c[i][0])
    elif c[i][0]>c[i][1]:
        ans+=(c[i][1])
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
a = list(map(int, input().split()))

c = Counter(a)
ans = 0
for i in c.items():
    if i[0] > i[1]:
        ans += i[1]
    else:
        ans += i[1]-i[0]
print(ans)

Solution (Python):
N=int(input())
*A,=map(int,input().split())

from collections import*
C=Counter(A)
ans=0
for k,v in zip(C.keys(),C.values()):
    if k<=v:
        ans+=v-k
    else:
        ans+=v

print(ans)

Solution (Python):
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()
b = [0]*100010
ans = 0

for x in a:
        if (x<=1e5):
                b[x] += 1
        else:
                ans += 1
for i in range(100010):
        if (b[i]>=i):
                ans += b[i] - i
        else:
                ans += b[i]

print(ans)

Solution (Python):
N = int(input())
from collections import Counter
A = Counter(list(map(int,input().split())))
cnt = 0
for key,val in A.items():
   if val>=key: cnt += min(val-key,val)
   else: cnt += val
print(cnt)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
num1=a[0]
num2=1
ans=0
for i in range(n-1):
    if num1==a[i+1]:
        num2+=1
    else:
        if num2<num1:
            ans+=num2
        else:
            ans+=num2-num1
        num1=a[i+1]
        num2=1
if num2>1:
    if num2<num1:
        ans+=num2
    else:
        ans+=num2-num1
else:
    if num1>1:
        ans+=1
print(ans)

Solution (Python):
n, *aa = map(int, open(0).read().split())

from collections import Counter

ans = 0

for k, count in Counter(aa).items():
    if count<k:
        ans += count
    else:
        ans += count-k

print(ans)

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
l=list(Counter(lmp()).items())
ans=0
for q in l:
    if q[0]>q[1]:
        ans+=q[1]
    elif q[0]<q[1]:
        ans+=q[1]-q[0]
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
from collections import Counter
c = Counter(As)

ans = 0
for num, c in c.most_common():
    if c>num:
        ans += c-num
    elif c<num:
        ans += c

print(ans)

Solution (Python):
def examA():
    N = I()
    A = LI()
    D = defaultdict(int)
    for a in A:
        D[a] += 1
    ans = 0
    for key,d in D.items():
        if key>d:
            ans += d
        else:
            ans += d - key
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    N, A, B, C = LI()
    L = [I()for _ in range(N)]
    loop = (1<<(2*N))
    ans = inf
    for l in range(loop):
        cost = 0
        bamboo_A = 0
        bamboo_B = 0
        bamboo_C = 0
        for j in range(N):
            if l&(1<<(2*j))>0:
                if l&(1<<(2*j+1))>0:
                    cost += 10
                    bamboo_A += L[j]
                else:
                    cost += 10
                    bamboo_B += L[j]
            else:
                if l&(1<<(2*j+1))>0:
                    cost += 10
                    bamboo_C += L[j]
        if bamboo_A==0 or bamboo_B==0 or bamboo_C==0:
            continue
        cost += abs(A-bamboo_A) + abs(B-bamboo_B) + abs(C-bamboo_C) - 30
        ans = min(ans,cost)

    print(ans)
    return

def examD():
    N = I()
    P = LI()
    O_ = [-1]*N
    start = P[0]-1
    for i in range(N):
        O_[P[i]-1] = i
    
    A = [1]*N
    B = [1]*N
    for i in range(start+1,N):
        cur = O_[i]-O_[i-1]
        if cur>0:
            A[i] = A[i-1] + (cur+1)
            B[i] = B[i-1] - 1
        else:
            A[i] = A[i-1] + 1
            B[i] = B[i-1] - (-cur+1)
    for i in range(start)[::-1]:
        cur = O_[i]-O_[i+1]
        if cur>0:
            B[i] = B[i+1] + (cur+1)
            A[i] = A[i+1] - 1
        else:
            B[i] = B[i+1] + 1
            A[i] = A[i+1] - (-cur+1)
    if A[0]<1:
        add = (1-A[0])
        for i in range(N):
            A[i] += add
    if B[-1]<1:
        add = (1-B[-1])
        for i in range(N):
            B[i] += add

    print(" ".join(map(str,A)))
    print(" ".join(map(str,B)))
    return

def examE():
    return

def examF():
    ans = 0
    print(ans)
    return


from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examA()

"""
9
7 3 9 1 8 4 5 6 2
"""

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
t={}
for i in range(n):
  if a[i] in t:
    t[a[i]]+=1
  else:
    t[a[i]]=1
ans=0
for i in t:
  if i>t[i]:
    ans+=t[i]
  else:
    ans+=t[i]-i
print(ans)

Solution (Python):
import math
import collections
import fractions
import itertools

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    c = collections.Counter(a)
    ans = 0
    for i in c:
        if c[i] >= i:
            ans += c[i] - i
        else:
            ans += c[i]
    print(ans)
    return 0

if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
C = {}
cnt = 0
for i in range(N):
    a = A[i]
    if a>N:
        cnt += 1
    else:
        if a not in C:
            C[a]=0
        C[a] += 1
for a in C:
    if a>C[a]:
        cnt += C[a]
    elif a<C[a]:
        cnt += C[a]-a
print(cnt)

Solution (Python):
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
dic = defaultdict(int)

for t in A:
  dic[t] += 1

ans = 0
for n,i in dic.items(): 
  if n > i:
    ans += i
  elif n < i:
    ans += (i-n)
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
ans = 0
for x,y in a.items():
    if y<x: ans += y
    else:ans += y-x
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = 0
for k, v in C.items():
  if v >= k:
    ans += v - k
  else:
    ans += v
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
lst = list(map(int, input().split()))
cntr = Counter(lst)
res = 0
for i in cntr:
  if cntr[i] >= i:
    res += (cntr[i] - i)
  else:
    res += cntr[i]
print(res)

Solution (Python):
n = int(input())
a = list(map(int, input().split())) + [10**18]
a = sorted(a)
c = 0
c_tmp = 1
num = a[0]
for i in range(1, n+1):
  if a[i] != num:
    if a[i-1] > c_tmp:
      c += c_tmp
    elif a[i-1] < c_tmp:
      c += c_tmp - a[i-1]
    c_tmp = 1
    num = a[i]
  else:
    c_tmp += 1
print(c)

Solution (Python):
import collections
n = int(input())
a = list(input().split())
cnt = collections.Counter(a)
c = 0
for key, value in cnt.items():
    while int(key) != value:
        value -= 1
        c += 1
        if value == 0:
            break
print(c)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
from collections import Counter
B=Counter(A)
ans=0
for k, v in B.items():
  if int(k)>v:
    ans+=v
  else:
    ans+=v-int(k)
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
ca = Counter(a)
ans = 0
for k, v in ca.items():
    if v < k:
        ans += v
    elif v > k:
        ans += v-k
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
D = Counter([int(a) for a in input().split()])

cnt = 0
for k, v in D.items():
    if k < v:
        cnt += v - k
    elif v < k:
        cnt += v
print(cnt)

Solution (Python):
from collections import Counter
n = int(input())
a=[int(i) for i in input().split()]
a = Counter(a)
cnt = 0
for key in a.keys():
    val = a[key]
    if key>val:
        cnt += val
    else:
        cnt += abs(val-key)
print(cnt)

Solution (Python):
import collections
N = int(input())
A =list(map(int,input().split()))
col_A = collections.Counter(A)
count = 0
for key,val in col_A.items():
    if key > val:
        count += val
    else:
        count += (val - key)
print(count)

Solution (Python):
N = int(input())
A = input().split()
A = [int(a) for a in A]

D = {}

for a in A:
    D[a] = D.get(a, 0) + 1

cnt = 0
for k, v in D.items():
    if k < v:
        cnt += v - k
    elif v < k:
        cnt += v
print(cnt)

Solution (Python):
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
cnt = 0
for k, v in C.items():
    if k <= v:
        cnt += v - k
    else:
        cnt += v
print(cnt)

Solution (Python):
from collections import defaultdict
N = int(input())
a = list(map(int,input().split()))
dic = defaultdict(int)
for x in a:
    dic[x] += 1
ans = 0
for x,c in dic.items():
    if c < x:
        ans += c
    elif c > x:
        ans += c-x
print(ans)

Solution (Python):
import sys
import math
import numpy as np
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
L = l()
c = Counter(L)
ans = 0
for i,v in c.items():
    if i > v:
        ans += v
    if i < v:
        ans += v-i
print(ans)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
a.sort()
a.append(0)
ans=0
b=a[0]
c=0
for i in range(N+1):
  if b!=a[i]:
    if c<b:
      ans+=c
    b=a[i]
    c=1
  else:
    if c==b:
      ans+=1
    else:
      c+=1
print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))



def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


from collections import Counter
N = a_int()
A = ints()


cnt = Counter(A)
ans = 0
for k, v in cnt.items():
    if k < v:
        ans += v - k
    if k > v:
        ans += v
print(ans)

Solution (Python):
import collections

n = int(input())
A = list(map(int,input().split()))

cnt = collections.Counter(A)

ans = 0
for key, value in cnt.items():
    if value < key:
        ans += value
    elif key < value:
        ans += value-key
        
print(ans)

Solution (Python):
import collections
n=int(input())
c=collections.Counter(list(map(int,input().split()))).most_common()
a=0
for i in c:
 if i[0]>i[1]:a+=i[1]
 else:a+=i[1]-i[0]
print(a)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[0]*(n+2)
for i in range(n):
    if a[i]>n:
        b[n+1]+=1
    else:
        b[a[i]]+=1
sm=0
for i in range(1,n+1):
    if b[i]>i:
        sm+=b[i]-i
    elif b[i]<i:
        sm+=b[i]

sm+=b[n+1]
print(sm)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import Counter

n, *a = map(int, read().split())

c = Counter(a)
ans =0
for k, v in c.items():
    if v >= k:
        ans += v - k
    elif v < k:
        ans += v
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
d=dict()
for i in range(n):
    if a[i] not in d:
        d[a[i]]=1
    else:
        d[a[i]]+=1
ans=0
for key in d:
    if key<=d[key]:
        ans+=d[key]-key
    else:
        ans+=d[key]
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(10**5+1)]
ans=0
for i in range(n):
    if a[i]>10**5:
        ans+=1
    else:
        l[a[i]]+=1
for i in range(10**5+1):
    if 0<l[i]<i:
        ans+=l[i]
    if i<l[i]:
        t=l[i]-i
        ans+=t
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

from collections import Counter

dic = Counter(a)

ans = 0
for i, j in dic.items():
    if i <= j:
        ans += j - i
    else:
        ans += j

print(ans)

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))

from collections import Counter
c = Counter(a)
ans = 0
for k,v in c.items():
    if k>v:
        ans += v
    elif k<v:
        ans += (v-k)
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

dic = Counter(a)

ans = 0

for i, j in dic.items():
    if i < j:
        ans += j-i
    if i > j:
        ans += j

print(ans)

Solution (Python):
from collections import Counter

N = int(input())
As = list(map(int, input().split()))

rlt = 0
dic = Counter(As)

for k in dic:
  if dic[k] < k:
    rlt += dic[k]
  elif dic[k] > k:
    rlt += dic[k] - k
    
print(rlt)

Solution (Python):
from collections import Counter

n = int(input())
d = Counter(list(map(int, input().split())))
ans = 0
for x, y in d.items():
    if x > y:
        ans += y
    else:
        ans += y-x
print(ans)

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(set(a))
count = 0
z = 0
for i in b:
    if i > n:
        count += n-z
        break
    else:
        j = a.count(i)
        if j < i:
            count += j
            z += j
        else:
            count += j-i
            z += j
print(count)

Solution (Python):
from collections import Counter
n=int(input())
a=Counter(list(map(int,input().split())))
cnt=0
for i,j in a.most_common():
  if i<=j:cnt+=j-i
  else:cnt+=j
print(cnt)

Solution (Python):
from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
ans = 0
for i in a:
  if i > a[i]:
    ans += a[i]
  elif i < a[i]:
    ans += a[i]-i
print(ans)

Solution (Python):
import sys
from collections import Counter
input = sys.stdin.readline



def main():
    N = int(input().strip())
    a_list = [int(n) for n in input().strip().split()]
    count = Counter(a_list)
    ans = 0
    for k, v in count.items():
        if v == k:
            continue
        elif v > k:
            ans += v - k
        else:
            ans += v
    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):
from _collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
a_max = max(a)
l = defaultdict(int)
count = 0
for i in range(n):
    l[a[i]] += 1
    count += 1
    if l[a[i]] == a[i]:
        count -= a[i]
print(count)

Solution (Python):
from collections import Counter
n = int(input())
A = Counter(list(map(int,input().split())))
keys,counts = zip(*A.most_common())
total = 0
for key,count in zip(keys,counts):
    if key > count:
        total += count
    else:
        total += count-key
print(total)

Solution (Python):
from collections import Counter, defaultdict
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
a = LI()
c = Counter(a)
ans = 0
for i, count in c.items():
    if count == i:
        continue
    elif count > i:
        ans += count - i
    else:
        ans += count
print(ans)

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    d = defaultdict(int)
    for a in ipt().split():
        d[int(a)] += 1

    ans = 0
    for dk,dv in d.items():
        if dk > dv:
            ans += dv
        elif dk < dv:
            ans += (dv-dk)
    print(ans)
    return

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
ans = 0

for i, j in d.items():
    if i > j:
        ans += j
    elif i < j:
        ans += j - i

print(ans)

Solution (Python):
from collections import Counter
N = int(input())
a = [int(i) for i in input().split()]

ans = 0
m = Counter(a)
for x, y in m.items():
    if x == y:
        continue
    elif x < y:
        ans += abs(y-x)
    else:
        ans += y
print(ans)

Solution (Python):
from collections import defaultdict

n = int(input())
a_list = [int(x) for x in input().split()]

d = defaultdict(int)
for a in a_list:
    d[a] += 1

ans = 0
for i, c in d.items():
    ans += c - i if c >= i else c
print(ans)

Solution (Python):
n=int(input())
a=[int(x) for x in input().rstrip().split()]
dic={}
minus=0
for i in a:
  if i not in dic:
    dic[i]=1
  else:
    dic[i]+=1

for i in dic:
  v=dic[i]
  if i==v:
    continue
  elif i<v:
    minus+=v-i
  else:
    minus+=v

print(minus)

Solution (Python):
n = int(input())
A = tuple(map(int, input().split()))

d = dict()
for a in A:
    d.setdefault(a, 0)
    d[a] += 1

c = 0
for i, count in d.items():
    rem = count - i
    if rem < 0:
        c += count
    else:
        c += rem
print(c)

Solution (Python):
def resolve():
    from collections import defaultdict
    N = int(input())
    A = [int(i) for i in input().split()]
    dic = defaultdict(int)
    for a in A:
        dic[a] += 1
    ans = 0
    for k, v in dic.items():
        if k <= v:
            ans += v - k
        else:
            ans += v
    print(ans)


resolve()

Solution (Python):
from collections import Counter

N = int(input())
A = list(map(int,input().split()))

C = Counter(A)

ans = 0
for x,c in C.items():
  t = c
  if c >= x:
    t = min(t,c-x)
  ans += t
  
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
a = list(input().split())
seq = [int(a[i]) for i in range(N)]
Cons = Counter(seq)

num = list(Cons.items())
count = 0

for i in range(len(num)):
    dif = int(num[i][1]) - int(num[i][0])
    count += (dif if dif >= 0 else int(num[i][1]))

print(count)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
old = A[0]
ans = 0
a = 1
for i in range(1, N):
  if A[i] == old: 
    a += 1
  else:
    if old > a:
      ans += a
    elif old < a:
      ans += a - old
    old = A[i]
    a = 1
if old > a:
  ans += a
elif old < a:
  ans += a - old
print(ans)

Solution (Python):

import collections
N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
ans = 0
for i,v in C.items():
    
    if i!=v:
        if i<v:
            ans += v-i
        else:
            ans += v
print(ans)