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


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    c = Counter(list(map(int, input().split())))

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


if __name__ == '__main__':
    main()

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

Ca = [0] * (N+1)

cnt = 0
for a in A:
  if a > N:
    cnt += 1
  else:
    Ca[a] += 1

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

print(cnt)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()
used = set()
cnt = defaultdict(int)

for a in aa:
	if cnt[a] == 0:
		used.add(a)
	cnt[a] += 1

ans = 0
for n in used:
	if cnt[n] > n:
		ans += cnt[n]-n
	elif cnt[n] < n:
		ans += cnt[n]

print(ans)

Solution (Python):
import itertools

n = int(input())
a = sorted(list(map(int,input().split())))
res = 0
g = itertools.groupby(a)

for k,v in g:
    l = len(list(v))
    if l>k:
        res += l-k
    elif l<k:
        res += l

print(res)

Solution (Python):
import collections
n = int(input())
a = [int(i) for i in input().split()]
A = collections.Counter(a)
ans = 0
for key in A.keys():
    if key <= A[key]:
        ans += A[key] - key
    else:
        ans += A[key]
print(ans)

Solution (Python):

"""
Created on Fri Aug 10 01:03:03 2018

@author: Yuki
"""


N = int(input())
A = sorted([int(i) for i in input().split()])
import collections


cnt_dict = collections.Counter(A)
res_cnt = 0
for key in cnt_dict.keys():
    if key == cnt_dict[key]:
        pass
    else:
        if key < cnt_dict[key]:
            res_cnt += cnt_dict[key] - key
        else:
            res_cnt += cnt_dict[key]
print(res_cnt)

Solution (Python):
import collections
_=input();num_dict=collections.Counter(map(int,input().split()))
count=0
for k in num_dict.items():
    if k[0]>k[1]:
        count+=k[1]
    elif k[0]<=k[1]:
        count+=k[1]-k[0]
print(count)

Solution (Python):
import bisect
n=int(input())
a = list(map(int,input().split()))
a.sort()
 
c = 0
d = 0 
 
while d <= n-1:
    s2 = bisect.bisect_right(a,a[d])
    s = s2-d
    if a[d] > s:
        c += s
    else:
        c += s-a[d]
    d = d + s
    
print(c)

Solution (Python):
from collections import Counter

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

cnt = Counter(A)

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

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

a_count = dict()
for a_i in a:
	if a_i not in a_count:
		a_count[a_i] = 0 
	a_count[a_i] += 1

sum_num = 0
for a_i in a_count:
	a_count_a_i = a_count[a_i]
	sum_num += a_count_a_i - a_i if a_i <= a_count_a_i else a_count_a_i
print(sum_num)

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

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

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

b = [0]*(10**5+1)
ans = 0

for x in a:
    if x <= 10**5:
        b[x] += 1
    else:
        ans +=1

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

print(ans)

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

d = {}

for i in a :
    if i in d.keys() :
        d[i] += 1
    else :
        d[i] = 1

tot = 0
for k in d.keys() :
    if d[k] < k :
        tot += d[k]
    elif d[k] > k :
        tot += d[k] - k
        
print(tot)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
d={}
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
ans=chk=0
for i in d:
    ans+=[d[i],d[i]-i][d[i]>=i] 
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 k, v in d.items():
    if k < v:
        ans += v - k
    elif k > v:
        ans += v
print(ans)

Solution (Python):

from collections import Counter

def main():
    n = int(input())
    a_list = list(map(int, input().split()))

    a_set = set(a_list)
    cnt = Counter(a_list)

    min_cnt = 0
    for i in a_set:
        if cnt[i] - i >= 0:
            min_cnt += cnt[i] - i
        else:
            min_cnt += cnt[i]

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

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

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

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))
    counter = {}
    ans = 0

    for i in a:
        if str(i) in counter.keys():
            counter[str(i)] += 1
        else:
            counter[str(i)] = 1
    for i, j in counter.items():
        if int(i) > j:
            ans += j
        else:
            ans += j - int(i)

    print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(int)
for ele in a:
  d[ele] += 1
ans = 0
for k, v in d.items():
  if k!=v:
    t = float("INF")
    if v>k:
      t = v-k
    ans += min(t, v)
print(ans)

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

Solution (Python):
'''input
4
3 3 3 3
'''
from collections import Counter
n = input()
arr = map(int,raw_input().split())
c = Counter(arr)
ans = 0
for i in c:
	if c[i] < i:
		ans += c[i]
	else:
		ans += (c[i]-i)
print ans

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int,input().split()))

npA = np.sort(A)

ans = 0
while len(npA) > 0 and N >= npA[0]:
    i = np.min(npA)
    tmp = np.sum(npA == i)
    if tmp > i:
        ans += tmp - i
    elif tmp < i:
        ans += tmp
    npA = np.delete(npA, range(tmp))


print(ans + len(npA))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
dic = {}
for nums in A:
  if nums in dic:
    dic[nums] += 1
  else:
    dic[nums] = 1
a = list(dic.keys())
b = list(dic.values())
i = 0
ans = 0
while i < len(a):
  if a[i] > b[i]:
    ans += b[i]
    i += 1
  else:
    ans += b[i]-a[i]
    i += 1
print(ans)

Solution (Python):
def line_input(f, type):
    return f(map(type, input().split(" ")))

n = input()
a = line_input(tuple, int)

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

print(ans)

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

ans = 0
a_pre = a[0]
cnt = 1
for i in range(1, n):
    ai = a[i]
    if ai == a_pre:
        cnt += 1
    else:
        if cnt > a_pre:
            ans += cnt - a_pre
        if cnt < a_pre:
            ans += cnt
            
        cnt = 1
        a_pre = ai
        
    if i==n-1:
        if cnt > a_pre:
            ans += cnt - a_pre
        if cnt < a_pre:
            ans += cnt  

if len(a)==1 and a[0]!=1:
    ans = 1
print(ans)

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

arr = map(int,raw_input().split())

counter = collections.Counter(arr)

ans = 0 

for item in counter.items() :
	if item[0] == item[1]:
		next

	elif item[1] < item[0]:
		ans += item[1]

	else :
		ans += item[1]-item[0]

print ans

Solution (Python):

"""
Created on Fri Jun 22 10:08:31 2018

@author: Yuya
"""

N=int(input())

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


























count_a = [0]*100000
ans = 0

for i in range(N):
    if a[i]<100001:
        count_a[a[i]-1] += 1
    else:
        ans += 1


for i in range(100000):
    if i+1<count_a[i]:
        ans+=count_a[i]-i-1
    elif i+1>count_a[i]:
        ans+=count_a[i]

print(ans)

Solution (Python):
from collections import Counter
N = int(input())
a = list(map(int,input().split()))
C = Counter(a)
print(sum([(j-i if j>=i else j) for i,j in C.items()]))

Solution (Python):
from collections import Counter

_ = input()
xs = [int(x) for x in input().split()]
c = Counter(xs)

print(sum(v*(k > v) + max(v - k, 0) for k, v in c.items()))

Solution (Python):
from collections import defaultdict

N = int(input())
a = [int(x) for x in input().split()]

c = defaultdict(lambda: 0)
for a_i in a:
    c[a_i] += 1

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

Solution (Python):


from collections import Counter 

cnt = int(input())
input_list = [int(i) for i in input().split()]


num_dict = Counter(input_list)

ans = 0

for key, value in num_dict.items():
    
    if key < value:
        ans += value - key
    
    elif key == value:
        continue
    
    elif key > value:
        ans += value
print(ans)

Solution (Python):


cnt = int(input())
input_list = [int(i) for i in input().split()]

num_dict = {}

for num in input_list:
    
    if num in num_dict:
        num_dict[num] += 1
    
    else:
        num_dict[num] = 1

ans = 0

for key, value in num_dict.items():
    
    if key < value:
        ans += value - key
    
    elif key == value:
        continue
    
    elif key > value:
        ans += value
print(ans)

Solution (Python):


N=int(input())

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



D={}
for i in range(N):
    if str(S[i]) in D:
        D[str(S[i])]+=1
    else:
        D.update({str(S[i]):1})

count=0
for i in D.keys():
    
    if D[i]<int(i):
        
        count+=D[i]
    elif D[i]>int(i):
        count+=D[i]-int(i)
    
print(count)

Solution (Python):
n = input()
arr = list(map(int, input().split()))
ar = [0 for i in range(100001)]
res = 0
for i in arr:
    if i > 100000:
        res += 1
    else:
        ar[i] += 1
for i in range(len(ar)):
    if ar[i] > i:
        res += ar[i] - i
    if ar[i] < i:
        res += ar[i]
print(res)

Solution (Python):
from collections import Counter

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

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

Solution (Python):
N = int(input())
S = sorted(list(map(int, input().split())))
stk = []
tmp = 0
res = 0
passed = 0
for e in S:
    if e <= passed:
        res += 1
        continue
    if tmp == 0:
        tmp = e
    if e == tmp:
        stk.append(e)
    else:
        res += len(stk)
        stk = [e]
        tmp = e
    if tmp == len(stk):
        stk = []
        passed = tmp
res += len(stk)
print(res)

Solution (Python):
N = int(input())
S = sorted(list(map(int, input().split())))
stk = []
tmp = 0
res = 0
passed = set()
for e in S:
    if e in passed:
        res += 1
        continue
    if tmp == 0:
        tmp = e
    if e == tmp:
        stk.append(e)
    else:
        res += len(stk)
        stk = [e]
        tmp = e
    if tmp == len(stk):
        stk = []
        passed.add(tmp)
res += len(stk)
print(res)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
distrib={}
for element in a:
    if element not in distrib:
        distrib[element] = 1
    else:
        distrib[element] += 1
ans = 0
for key in distrib:
    diff = distrib[key] - key
    if diff >= 0:
        ans += diff
    else:
        ans += distrib[key]
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
L = list(set(a))
res = 0
d = Counter()
d.update(a)
for i in L:
    X = d[i]
    if X < i:
        res += X
    
    else:
        res += X - i

print(res)

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

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

Solution (Python):
from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]

d = Counter(A).most_common()
d = d[::-1]

reCounter = 0

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

Solution (Python):
from collections import Counter

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

mycounter = Counter(A)
count = 0
for item in mycounter.items():
    if item[0] < item[1]:
        count += item[1] - item[0]
    elif item[1] < item[0]:
        count += item[1]

print(count)

Solution (Python):
n = int(input())
userIn = input().split()
a = [0 for i in range(2*n+1)]
deleteCounter = 0

for j in userIn:
    if int(j) > n:
        deleteCounter += 1
    else:
        a[int(j)] += 1

for j in range(n+1):
    if a[j] != 0:
        if a[j] >= j:
            deleteCounter += a[j] - j
        else:
            deleteCounter += a[j]

print(deleteCounter)

Solution (Python):
from collections import Counter as C

N = int(input())
S = list(int(i) for i in input().split())
count = 0

for key, value in C(S).items():
    if key < value:
        count += (value-key)
    elif key > value:
        count += value

print(count)

Solution (Python):
N = int(input())
S = list(int(i) for i in input().split())  
dict = {}
count = 0

for i in range(N):
    if S[i] not in dict:
        dict[S[i]] = 1
    else:
        dict[S[i]] += 1

for key, value in dict.items():
    if key < value:
        count += (value-key)
    elif key > value:
        count += value

print(count)

Solution (Python):
from collections import Counter

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

c = Counter(a)

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

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 v == 0:
        continue
    if k > v:
        cnt += v
    elif k < v:
        cnt += (v - k)
print(cnt)

Solution (Python):
N=int(input().strip())
A=list(map(int,input().split()))
d={}
for a in A:
    if a not in d:
        d[a]=0
    d[a]+=1
ct=0
for k,v in d.items():
    if k>v:
        ct+=v
    elif k<v:
        ct+=v-k
print(ct)

Solution (Python):
n = int(input())
b = {}
ans = 0
for i in input().split():
    i = int(i)
    if(i in b):
        b[i] += 1
    else:
        b[i] = 1
for c in b:
    if(c < b[c]):
        ans += b[c] - c
    elif(c > b[c]):
        ans += b[c]
print(ans)

Solution (Python):
MAX = 10**5
count = [0]*(MAX+1)
c = 0
N = int(input())
A = list(map(int,input().split()))
for a in A:
    if a > MAX:
        continue
    count[a] += 1
for i in range(1,N+1):
    if count[i] >= i:
        c += i
print(N-c)

Solution (Python):
import itertools
N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
summe = {k: len(list(g)) for k, g in itertools.groupby(A)}
cnt = 0
for k, v in summe.items():
    if k < v:
        cnt += v - k
    elif k > v:
        cnt += v
print(cnt)

Solution (Python):
n = int(input())
prog = list(map(int, input().split()))
prog.sort()
prog_dict = {}
ans = 0

for i in range(n):
    if prog[i] not in prog_dict:
        prog_dict[prog[i]] = 1
    else:
        prog_dict[prog[i]] += 1

keys = list(prog_dict.keys())
for i in range(len(prog_dict)):
    if keys[i] > prog_dict[keys[i]]:
        ans += prog_dict[keys[i]]
    else:
        ans += prog_dict[keys[i]] - keys[i]

print(ans)

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

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

Solution (Python):
import collections

n = int(input())
array = [int(x) for x in input().split()]
_dict = collections.Counter(array)

res = 0
for i, j in _dict.items():
    if i != j:
        if i > j:
            res += j
        else:
            res += abs(i-j)
print(res)

Solution (Python):

def inpl(): return map(int, input().split())
from collections import Counter

N = int(input())
A = Counter(inpl())
ans = 0

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

print(ans)

Solution (Python):
import os
import sys

n= map(int, input().split())
a = [x for x in map(int, input().split())]

d = {}
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i] = 1

ans = 0
for i in d.keys():
    if i > d[i]:
        ans = ans + d[i]
    if i <= d[i]:
        ans = ans + d[i] - i

print(ans)
exit(0)

Solution (Python):
from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]
c = Counter(a)
ck = list(c.keys())
cv = list(c.values())
ans = 0

for i in range(0,len(ck)):
    if ck[i]>cv[i]:
        ans += cv[i]
    elif ck[i]<cv[i]:
        ans += cv[i] - ck[i]
print(ans)

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

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

sort_dict = collections.Counter(a_list)
remove_counter = 0
for key, value in sort_dict.items():
    if value < key:
        remove_counter += value
    else:
        remove_counter += (value - key)     
print(remove_counter)

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

sort_dict = {}
for i in sort_a_list:
    if i not in sort_dict.keys():
        sort_dict[i] = [i]
    else:
        sort_dict[i].append(i)
        
remove_counter = 0
for key, value in sort_dict.items():
    if len(value) < key:
        remove_counter += len(value)
    elif len(value) == key:
        pass
    else:
        remove_counter +=(len(value) - key)
        
print(remove_counter)

Solution (Python):
n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0
now = l[0]
count = 1
if len(l) == 1:
  if now == 1:
    print(0)
  else:
    print(1)
else:
  for i in range(1, n):
    if l[i] == now:
      count += 1
    else:
      if count < now:
        ans += count
      elif count > now:
        ans += count-now
      
      now = l[i]
      count = 1
    
    if i == n-1:
      if count < now:
        ans += count
      elif count > now:
        ans += count-now

  print(ans)

Solution (Python):
from collections import Counter

N=int(input())
a=list(map(int,input().split()))
A=list(set(a))
ans=0
count = Counter(a)

for i in A:
    if count[i]>i:
        ans+=count[i]-i
    elif count[i]<i:
        ans+=count[i]

print(ans)

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

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

els = {}

for num in a:
    if num in els.keys():
        els[num] += 1
    else:
        els[num] = 1

total = 0

for k, v in els.items():
    total += v if int(k) > v else (v - int(k)) if int(k) < v else 0

print(total)

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

els = {}

for num in a:
    if num in els.keys():
        els[num] += 1
    else:
        els[num] = 1

total = 0

for k, v in els.items():
    total += v if int(k) > v else (v - int(k)) if int(k) < v else 0

print(total)

Solution (Python):
from collections import Counter
N = int(input())
cnt = Counter(map(int, input().split()))
print(sum(v - k if v >= k else v for k, v in cnt.items()))

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

cnt = 0
for i in s:
    if c[i] < i:
        cnt += c[i]
    else:
        cnt += c[i]-i
print(cnt)

Solution (Python):
import collections as c

N = int(input())
a = [int(i) for i in input().split()]

d = c.Counter()
for i in a:
    d[i] += 1

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

print (ans)

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

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

anset = list(set(an))

andict = {}

for i in range(len(an)):
    if an[i] in andict:
        andict[an[i]] = andict[an[i]] + 1
    else:
        andict.update({an[i]:1})

counter = 0

for i ,j in andict.items():
    if i == j :
        None
    elif i > j:
        counter = counter + j
    elif i < j:
        counter = counter + j - i
    
        
print(counter)

Solution (Python):

from collections import Counter
N = int(input())
A = list(map(int,input().split()))
B = set(A)
C = Counter(A)
ans = 0

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

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
t, i, j = 0, 0, 1

a.sort()
while True:
    if i >= len(a):
        break

    if len(a) > 1:
        while a[i] == a[j]:
            j += 1

            if j == len(a):
                break

    if a[i] > j - i:
        t += j - i
    elif a[i] < j - i:
        t += j - i - a[i]

    i = j

print(t)

Solution (Python):
from collections import Counter
N = int(input())
A = Counter(list(map(int,input().split()))).most_common()
S = 0
for i,c in A:
    if i == c:
        continue
    elif i > c:
        S += c
    else:
        S += c-i
print(S)

Solution (Python):
from collections import Counter

def goodify(a):
    nums = Counter(a)
    bads = 0
    for k, v in nums.items():
        if v >= k:
            bads += v - k
        else:
            bads += v
    return bads


if __name__ == '__main__':
    _ = input()
    a = Counter(map(int, input().split()))
    print(goodify(a))

Solution (Python):
from collections import Counter

input()
A = map(int, input().split())
B = Counter(A)

count = 0
for key, value in B.items():
    count += value - key if value >= key else value

print(count)

Solution (Python):
from collections import Counter
n = int(input())
a = list(input().split())
counter = Counter(a)
count = 0
for name, cnt in counter.most_common():
    name = int(name)
    if name > cnt:
        count += cnt
    if name < cnt:
        count += cnt-name
print(count)

Solution (Python):
N = int(input())
As = map(int, input().split())
cnt = {}
for a in As:
    if a in cnt:
        cnt[a] += 1
    else:
        cnt[a] = 1
ret = 0
for i in set(cnt.keys()):
    if i < cnt[i]:
        ret += cnt[i] - i
    elif cnt[i] < i:
        ret += cnt[i]
print(ret)

Solution (Python):
N=int(input())
s,ans={},0
for i in list(map(int,input().split())):
    s[i]=s.get(i,0)+1
for c,v in s.items():
    if c<v:
        ans+=v-c
    if c>v:
        ans+=v
print(ans)

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

   a.sort()
   a.append(0)
   b = 0
   c = 0
   count = 0
   for a in a:
      if a != b:
         if b < c:
            count += c - b
         elif b > c:
            count += c
         b = a
         c = 1
      else:
         c += 1
   return count

print(main())

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

a_=Counter(a)
num=0
for key in a_.keys():
    if key>a_[key]:
        num+=a_[key]
    elif key<a_[key]:
        num+=a_[key]-key
    else:
        continue
print(num)

Solution (Python):
from collections import Counter

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

c = Counter(a)

result = 0
for num in c.keys():
    if num < c[num]:
        result += c[num] - num
    elif num > c[num]:  
        result += c[num]

print(result)

Solution (Python):
input()
d = {}
for x in input().split():
    x = int(x)
    d[x] = d.get(x, 0) + 1
c = 0
for k, v in d.items():
    if k > v: c += v
    elif k < v: c += (v - k)
print(c)

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

ans=0
for i in dict.keys():
  count=dict[i]
  if count>i:
    ans+=count-i
  elif count<i:
    ans+=count

print(ans)

Solution (Python):
from collections import defaultdict
n=int(input())
arr=list(map(int,input().split()))
dd=defaultdict(int)
for a in arr:
    dd[a]+=1
ans=0
for key in dd.keys():
    if key>dd[key]:
        ans+=dd[key]
    elif key<dd[key]:
        ans+=dd[key]-key
print(ans)

Solution (Python):
input()
r = {}
for i in map(int, input().split()):
    a = r.get(i, 0)
    r[i] = a + 1

print(sum(v - (k if v >= k else 0) for k, v in r.items()))

Solution (Python):





if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    count = 0

    from collections import Counter
    counted_a = Counter(a)

    for x in counted_a:
        if counted_a[x] >= x:
            count += counted_a[x] - x
        else:
            count += counted_a[x]

    print(count)

Solution (Python):





if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    count = 0

    from collections import Counter
    counted_a = Counter(a)

    for x in counted_a:
            if counted_a[x] >= x:
                count += counted_a[x] - x
            else:
                count += counted_a[x]

    print(count)

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]
b = [0] * (N + 1)
ans = 0
for i in range(N):
    if a[i] <= N:
        b[a[i]] += 1
    else:
        ans += 1

for i in range(N + 1):
    if b[i] < i:
        ans += b[i]
    else:
        ans+= b[i] - i
print(ans)

Solution (Python):
import math
import sys

def getinputdata():

    
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

n = arr_data[0][0]
arr = arr_data[1]



hash01={}

for v in arr:
    
    cnt =hash01.get(int(v),0)+1
    hash01[int(v)] = cnt
    


cnt=0

for k,v in hash01.items():
    

    
    if(k>v):
        
        cnt+=v
        
    elif(k<v):
        
        cnt+=v-k
        
print(cnt)

Solution (Python):
from collections import Counter

N = int(input())
A = [int(s) for s in input().split()]

count = Counter(A)

ans = 0
for n, c in count.items():
    if n > c:
        ans += c
    elif n < c:
        ans += c - n

print(ans)

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
a = na()

dic = {}

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

ans = 0
for key,value in dic.items():
    if key > value:
        ans += value
    else:
        ans += (value - key)

print(ans)

Solution (Python):
from collections import Counter

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

counter = Counter(a)

cnt = 0
for num , how_many in counter.most_common():
    if num > how_many:
        cnt += how_many
    elif num < how_many:
        cnt += how_many - num

print(cnt)

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

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

count = collections.Counter()

for i in a:
    count[i] += 1

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

Solution (Python):
import collections

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

count = collections.Counter()

for a in A:
    count[a] += 1
    
ans = 0

for num, c in count.items():
    if num < c:
        ans += c - num
    elif num > c:
        ans += c
    else:
        continue
        
print(ans)

Solution (Python):
from collections import Counter

n = int(raw_input())
c = Counter(map(int, raw_input().split()))
s = 0
for k,v in c.items():
    if v < k:
        s += v
    else:
        s += v - k
print s

Solution (Python):
N = int(input())
tmp = input().split()
dict = {}

for n in range(N):
    if tmp[n] in dict:
        dict[tmp[n]] += 1
    else:
        dict[tmp[n]] = 1
count = 0
for k,v in dict.items():
    if int(k) ==v:
        continue
    elif int(k) > v:
        count +=v
    else:
        count += (v-int(k))
print(count)

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

num_list = {}
for i in a:
    if i in num_list:
        num_list[i] += 1
    else:
        num_list[i] = 1


count_rem = 0
for i in num_list:
    if i > num_list[i]:
        count_rem += num_list[i]
    elif i < num_list[i]:
        count_rem += num_list[i] - i

print(count_rem)