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):
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 i in D:
  if D[i]>=i:
    ans += D[i]-i
  else:
    ans += D[i]
print(ans)

Solution (Python):
import collections

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

aa = collections.Counter(a).most_common()


for i,j in aa:
    if i > j:
        ans += j
    if i < j:
        ans += j-i
    
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 k < v:
        ans += v - k
    elif k > v:
        ans += v
print(ans)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
flag = [False] * n
res = 0

for i in range(n):
  if flag[i]:
    continue
  
  c = 0
  j = i
  
  while a[i] == a[j]:
    c += 1
    flag[j] = True
    j += 1
    if j == n:
      break
  
  if c == a[i] or c == 0:
    continue
  elif c < a[i]:
    res += c
  else:
    res += c - a[i]
    
print(res)

Solution (Python):
import collections as c

n = int(input())
s = list(map(int,input().split()))
s = c.Counter(s)
ans = 0
for i in s.items():
    a = i[0]
    b = i[1]
    if b<a:
        ans += b
    else:
        ans += b-a
print(ans)

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

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

ans = 0
for a in d:
    if d[a]>a:
        ans += d[a]-a
    elif d[a]<a:
        ans += d[a]
print(ans)

Solution (Python):
import math
from collections import Counter
from sys import exit
from itertools import product

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
a = li()

cnt = Counter(a)
ans = 0
for i,j in cnt.items():
    if i > j:
        ans += j
    else:
        ans += j - i
print(ans)

Solution (Python):



from math import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq














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


INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n = I()
Count = Counter(readInts())
ans = 0
for k,v in Count.items():
    if k < v:
        ans += v - k
    if v < k:
        ans += v
print(ans)

Solution (Python):
from collections import Counter

N, *A = map(int, open(0).read().split())
cnt = Counter(A)
ans = 0
for k, v in cnt.items():
    if k > v:
        ans += v
    else:
        ans += v - k
print(ans)

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

Solution (Python):
import collections

N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
C=collections.Counter(L)
D=list(C.keys())
E=list(C.values())
K=len(C)
ans=0
for i in range(K):
	if D[i]==E[i]:
		ans+=0
	if D[i]>E[i]:
		ans+=E[i]
	if D[i]<E[i]:
		ans+=(E[i]-D[i])
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
al = list(map(int, input().split()))
c = Counter(al)

ans = 0
for k, v in c.items():
    if k == v:
        continue
    elif k > v:
        ans += v
    else:
        ans += v-k

print(ans)

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

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())))

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

Solution (Python):
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 v < k:
        ans += v
    elif v > k:
        ans += (v-k)
print(ans)

Solution (Python):

"""
Created on Wed Sep 23 15:39:14 2020

@author: liang
"""

N = int(input())
A = [int(x) for x in input().split()]
d = [0]*N
ans = 0
for a in A:
    if a > N :
        ans += 1
    else:
        d[a-1] += 1

for i in range(N):
    if d[i] > 0:
        if d[i] > i+1:
            ans += d[i] - (i+1)
        if d[i] < i+1:
            ans += d[i]

print(ans)

Solution (Python):
import collections
n = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
ans = 0

for k,v in C.items():
  if k == v: continue
  elif k < v: ans += (v - k)
  else: ans += v

print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
*a, = map(int, input().split())
b = defaultdict(int)
for i in range(N):
    b[a[i]] += 1
ans = 0
for i, v in b.items():
    if i > b[i]:
        ans += b[i]
    elif i < b[i]:
        ans += b[i]-i
print(ans)

Solution (Python):

from collections import Counter
import sys
sys.setrecursionlimit(10**6)


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

c = Counter(a)

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

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

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

a=sorted(a)
l=a[0]
cnt=0

b=[]
for i in range(N):
    if a[i]==l:
        cnt+=1
    else:
        b.append([l,cnt])
        l=a[i]
        cnt=1
if cnt>0:
    b.append([l,cnt])

ans=0
for i in range(len(b)):
    if b[i][0]>b[i][1]:
        ans+=b[i][1]
    else:
        ans+=b[i][1]-b[i][0]

print(ans)

Solution (Python):
from collections import Counter

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

count = 0

for i, j in Counter(a).items():
    if j-i < 0:
        count += j
    else:
        count += min(j-i, j)

print(count)

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

count = 0
m = 0

for i in range(N):
  if count == 0:
    m = A[i]
    count += 1
  elif A[i] == m:
    count += 1
  else:
    if m > count:
      ans += count
    else:
      ans += count-m
    count = 1
    m = A[i]

if m > count:
  ans += count
else:
  ans += count-m

print(ans)

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

Solution (Python):
n = int(input())
dic = {}

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

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

ans = 0

for key in dic:
    if dic[key] != key:
        if dic[key] > key:
            ans += dic[key] - key
        else:
            ans += dic[key]

print(ans)

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

Solution (Python):





N = int(input())


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





dic = {}

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

ans = 0

for key in dic:
    if dic[key] != key:
        if dic[key] > key:
            ans += dic[key] - key
        else:
            ans += dic[key]

print(ans)

Solution (Python):

from collections import defaultdict

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

D = defaultdict(int)
for a in A:
  D[a] += 1

ans = 0
for a, x in D.items():
  if x >= a:
    ans += x-a
  else:
    ans += x

print(ans)

Solution (Python):
N=int(input())
a=list(map(int,input().strip().split()))
d={}

for n in range(N):
    if d.get(a[n])==None:
        d[a[n]]=1
    else:
        d[a[n]]+=1

cnt=0
for key in d.keys():
    if key>d[key]:
        cnt+=d[key]
    else:
        cnt+=d[key]-key

print(cnt)

Solution (Python):
from collections import Counter
from itertools import starmap
def main():
    N = input()
    A = list(map(int, input().split()))
    count = Counter(A)
    remove = lambda x,y: y-x if y >= x else y
    ans = sum(starmap(remove, count.items()))
    print(ans)

main()

Solution (Python):
def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    a_lst.sort()
    a_set_lst = list(set(a_lst))
    a_set_lst.sort()

    count_lst = []
    count = 1
    if n == 1:
        count_lst.append(count)
    else:
        for i in range(n - 1):
            a1 = a_lst[i]
            a2 = a_lst[i + 1]

            if a1 == a2:
                count += 1
                if i == n - 2:
                    count_lst.append(count)
            else:
                count_lst.append(count)
                count = 1
        if a_lst[-1] != a_lst[-2]:
            count_lst.append(count)

    minimum = 0
    for i in range(len(a_set_lst)):
        number = a_set_lst[i]
        count = count_lst[i]

        if count < number:
            minimum += count
        else:
            minimum += count - number

    print(minimum)


if __name__ == '__main__':
    main()

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

Solution (Python):
from collections import Counter

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

counter = Counter(A)

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


print(cnt)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
import collections
a = collections.Counter(a)
ans = 0
for i,j in a.items():
    if i>j:
        ans += j
    else:
        ans += abs(i-j)
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
d={}
dd={}
if len(A)==1:
    if A[0]==1:
        print(0)
    else:
        print(1)
else:
    for a in A:
        try:
            d[a]+=1
            dd[a]+=1
        except KeyError:
            d[a]=1
            dd[a]=1
        
        if dd[a]==a:
            d[a]=0
    print(sum(d.values()))

Solution (Python):
import collections
N = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
co = 0
for t , count in c.items():
    if t < count:
        co += count - t
    elif count < t:
        co += count
print(co)

Solution (Python):
N = int(input())
a = [int(s) for s in input().split()]
p = {}

for b in a:
    if b in p:
        p[b] += 1
    else:
        p[b] = 1

ans = 0
for k in p:
    if k > p[k]:
        ans += p[k]
    elif k < p[k]:
        ans += (p[k] - k)

print(ans)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
a.sort()
a.append(0)
i=0
ans=0
while i<N:
    x=a[i]
    count=0
    while a[i]==x:
        i+=1
        count+=1
    if count<x:
        ans+=count
    else:
        ans+=count-x
print(ans)

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

from collections import Counter
c = Counter(l)
ans = 0
for key in c:
    if key > c[key]:
        ans += c[key]
    else:
        ans += c[key] - key

print(ans , flush=True)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = set(A)
d = {}
for a in A:
  d[a] = d.get(a, 0) + 1
ans = 0
for b in B:
  s = d[b]
  if s >= b:
    ans += (s - b)
  else:
    ans += s
print(ans)

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

ans=0
for i in C:
  j=C[i]
  if j>=i:
    ans+=j-i
  else:
    ans+=j
print(ans)

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

Solution (Python):
import collections
n=int(input())
a=list(map(int,input().split()))
d=collections.Counter(a)
ans=0
for key,value in d.items():
    if key > value:
        ans += value
    if value > key:
        ans += (value - key)
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 key > value:
        ans += value
    if value > key:
        ans += (value - key)
print(ans)

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N,A = ilint()
C = counter()
for a in A:
    C.add(a)
ans = 0
for k in C:
    ans += C[k] if C[k]<k else C[k]-k
print(ans)

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

Solution (Python):
from collections import Counter

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

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

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

from collections import defaultdict
dd = defaultdict(int)
for key in a:
    dd[key] += 1
for key in dd.keys():
    
    if dd[key]>=key:
        ans += dd[key]-key
    else:
        ans += dd[key]
print(ans)

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan2, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    li = LIST()
    A = defaultdict(int)
    for i in li:
        A[i] += 1
    cnt = 0
    for i in A.keys():
        if i < A[i]:
            cnt += A[i]-i
        elif i > A[i]:
            cnt += A[i]

    print(cnt)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
num_map = dict()
for i in range(n):
    if a[i] not in num_map:
        num_map[a[i]] = 1
    else:
        num_map[a[i]] += 1

res = 0
for key, value in num_map.items():
    if key <= value:
        res += value - key
    else:
        res += value

print(res)

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

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

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

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    a = i_list()
    dic = {}
    for i in a:
        dic[i] = dic.get(i,0) + 1
    ans = 0
    for i,k in dic.items():
        if i < k:
            ans += k-i
        elif i > k:
            ans += k
    print(ans)


if __name__=="__main__":
    main()

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

Solution (Python):
import collections
N = int(input())
lsA = list(map(int,input().split()))
counterA = collections.Counter(lsA)
ans = 0
for i in counterA.keys():
    if i == counterA[i]:
        continue
    if i < counterA[i]:
        ans += counterA[i]-i
    elif i > counterA[i]:
        ans += counterA[i]

print(ans)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]

dp=[0]*(n+2)
for i in a:
    if i>n:
        dp[-1]+=1
    else:
        dp[i]+=1

ans=dp[-1]
for i in range(1,n+1):
    if dp[i]>=i:
        ans+=dp[i]-i
    else:
        ans+=dp[i]
print(ans)

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

ans = 0

if N == 1 and a[0] != 1:
    print(1)
    exit()
elif N == 1 and a[0] == 1:
    print(0)
    exit()


for i in (a_counter.items()):
    key = (i[0])
    value = (i[1])

    if key == value:
        pass
    
    elif key < value:
        ans = ans + (value - key)
    else:
        ans = ans + (value) 

print(ans)

Solution (Python):
import sys
import math
from collections import Counter


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

C = Counter(A)
ans = 0

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

print(ans)

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

cnt = 0
for i in set(A):
  I = C[i]
  if I == i:
    continue
  elif I > i:
    cnt += I - i
  else :
    cnt += I
  
print(cnt)

Solution (Python):
N = input()
A = sorted([int(x) for x in input().split()])
import bisect as bs
ans = 0
f = lambda X, x: bs.bisect_right(X,x) - bs.bisect_left(X,x)
for a in set(A):
    cnt = f(A,a)
    if cnt < a:
        ans += cnt
    else:
        ans += cnt-a
print(ans)

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial

from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

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

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

ddict = defaultdict(lambda: 0)





n = I()
a = RI()

for i in range(n):
    ddict[a[i]] += 1

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

print(ans)

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

def main():
    n = int(input())
    a = Counter(list(map(int, input().split())))
    
    ans = 0;
    for k, v in a.items():
        if k < v:
            ans += v - k
        elif k > v:
            ans += v
            
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import collections
n=int(input())
a=list(map(int,input().split()))
l=list(set(a))
m=collections.Counter(a)
ans=0
for i in range(len(l)):
    if m[l[i]]<l[i]:
        ans+=m[l[i]]
    else:
        ans+=m[l[i]]-l[i]
print(ans)

Solution (Python):
import collections
dic = collections.defaultdict(int)
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
	dic[a[i]] += 1
ans = 0
for key in dic.keys():
    if dic[key] >= key:
    	ans += (dic[key] - key)
    else:
        ans += dic[key]
print(ans)

Solution (Python):
import collections
dic = collections.defaultdict(int)
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
	dic[a[i]] += 1
ans = 0
for key in dic.keys():
    if dic[key] >= key:
      ans += (dic[key] - key)
    else:
        ans += dic[key]
print(ans)

Solution (Python):
import collections
dic = collections.defaultdict(int)
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
  dic[a[i]] += 1
ans = 0
for key in dic.keys():
    if dic[key] >= key:
      ans += (dic[key] - key)
    else:
        ans += dic[key]
print(ans)

Solution (Python):
N=int(input())

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

a.sort()
c=1
ans=0
for i in range(N-1):
    if a[i]==a[i+1]:
        c+=1
        if c>a[i]:
            ans+=1
    else:
        if c<a[i]:
            ans+=c
            c=1
        else:
            c=1
if c<a[N-1]:
    ans+=c

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
d = dict()
for i in range(N):
    if d.get(A[i]) is None:
        d[A[i]] = 1
    else:
        d[A[i]] += 1
ans = 0
for key, value in d.items():
    if key <= value:
        ans += value - key
    else:
        ans += value
print(ans)

Solution (Python):
n = int(input())

al = list(map(int, input().split()))

ans = 0
dic = {}
for a in al:
    dic[a] = dic.get(a, 0)+1

for k, v in dic.items():
    if k == v:
        pass
    elif k < v:
        ans += v-k
    else:
        ans += v
print(ans)

Solution (Python):
from collections import *
n=int(input())
l=list(map(int,input().split()))
d=defaultdict(int)
for i in l:
    d[i]+=1
c=0
for i in d:
    if(i!=d[i]):
        if(d[i]>i):
            c+=d[i]-i
        else:
            c+=d[i]
print(c)

Solution (Python):
import collections

def main():
    N = int(input())
    A = list(map(int, input().split()))
    c = collections.Counter(A)
    ans = 0
    for num, freq in c.items():
        if num < freq:
            ans += freq - num
        elif num > freq:
            ans += freq
    print(ans)


if __name__ == '__main__':
    main()

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

a_cnt = collections.Counter(a)

cnt = 0
for item in a_cnt.items():
    if item[0]<item[1]:
        cnt += item[1]-item[0]
    elif item[0]>item[1]:
        cnt += item[1]
print(cnt)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
from collections import Counter
counter = dict(Counter(A))
ans = 0
for num in set(A):
    if counter[num] >= num:
        ans += counter[num] - num
    else:
        ans += counter[num]
print(ans)

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

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

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

cnt = 0
for i, j in A.items():
    if i > j:
        cnt += j
    elif i < j:
        cnt += j-i
print(cnt)

Solution (Python):

import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

d = defaultdict(int)
for a in A:
    d[a] += 1
cnt = 0
for key, val in d.items():
    if key <= val:
        cnt += val - key
    else:
        cnt += val
print(cnt)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    A = LIST()

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

A_c = Counter(A)

ans = 0
for k, v in zip(A_c.keys(), A_c.values()):
    if k < v:
        ans += v - k
    elif k > v:
        ans += v
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ans = 0
dict = {}
for i in range(N):
    if A[i] in dict:
        dict[A[i]] += 1
    else:
        dict[A[i]] = 1

for x in dict:
    if x > dict[x]:
        ans += dict[x]
    else:
        ans += dict[x]-x
print(ans)

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

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

c = collections.Counter(A)

ans=0
for k,v in c.items():
    if k == v: continue
    if k < v: 
        ans+=v-k
    if v < k: 
        ans+=v
print(ans)

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

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