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 sys
from collections import Counter


n = int(input())

c = Counter(map(int, input().split()))

ans = 0

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

print(ans)

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

count = Counter(a)

cnt = 0
for i in count.items():
    if i[0] > i[1]:
        cnt += i[1]
    elif i[0] <= i[1]:
        cnt += i[1] - i[0]

print(cnt)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict 
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  
  
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  





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

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

Solution (Python):
from collections import Counter

n = int(input())
nums = Counter(map(int, input().split()))
cnt = 0
for key, value in nums.items():
    if key > value:
        cnt += value
    elif key < value:
        cnt += value - key
    else:
        continue
print(cnt)

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

cs = collections.Counter(a)


out=0
for key in cs:
    
    if cs[key] > key:
        out+= cs[key] - key
    elif cs[key] < key:
        out+= cs[key]
    

print(out)

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil

n = ni()
A = lma()
co = collections.Counter(A)
ans = 0
for num,cnt in co.items():
    if num<cnt:
        ans+=(cnt-num)
    if num>cnt:
        ans+=cnt
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')

from collections import deque, defaultdict





def solve():
    N = II()
    A = LI()
    dct = defaultdict(lambda: 0)

    for a in A:
        dct[a] += 1

    ans = 0
    for key, val in dct.items():
        if key == val:
            continue
        elif key < val:
            ans += val - key
        else:
            ans += val

    print(ans)


if __name__ == '__main__':
    solve()

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

b = set(a)
c = Counter(a)
ans = 0

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

Solution (Python):
import collections
N = int(input())
a = list(map(int,input().split()))
ans = 0
c = collections.Counter(a)
for i,j in zip(c.keys(),c.values()):
    if(j>i):
        ans += j-i
    elif(j==i):
        pass
    else:
        ans += j
print(ans)

Solution (Python):
n = len(input())
mp, res = {}, 0
for el in list(map(int, input().split())): mp[el] = mp.get(el, 0) + 1
for key in mp:
    val = mp[key]
    if key > val: res += val
    elif key < val: res += val - key
print(res)

Solution (Python):
n = int(input())
list_val = [int(val) for val in input().split()]
if len(list_val)<1:
  print(0)
dict_val = {}
count=0
for i in range(n):
  dict_val[list_val[i]] = dict_val.get(list_val[i],0)+1
for key, values in dict_val.items():
  if key>values:
    count+=values
  elif key<values:
    count+=values-key
print(count)

Solution (Python):
n = int(input())
arr = list(map(int,input().split()))
dicta={}
ans=0
for i in arr:
    dicta[i] = dicta.get(i,0)+1

for key,value in dicta.items():
    if key == value:
        continue
    elif key > value:
        ans+=value
    else:
        diff = abs(value-key)
        ans += diff

print(ans)

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
dic,cnt={},0
for i in arr:
    dic[i]=dic.get(i,0)+1
for i in dic:
    if dic[i]>i:
        cnt+=dic[i]-i
    elif dic[i]<i:
        cnt+=dic[i]
print(cnt)

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

d = defaultdict(int)

for i in A:
    d[i] += 1

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

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

d = defaultdict(int)

for i in A:
    d[i] += 1

ans = 0
for key in d:
    tmp = d[key]
    if tmp > key:
        ans += tmp - key
    elif tmp < key:
        ans += tmp
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
clear = 0
for k, v in dic.items():
  if k > v:
    clear += v
  else:
    clear += v-k
print(clear)

Solution (Python):
import collections

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

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

print(ans)

Solution (Python):
from collections import Counter

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

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

Solution (Python):
from collections import Counter
_, *lst = map(int, open(0).read().split())
c = Counter(lst)
res = 0
for i, j in c.items():
  if i == j:
    continue
  elif i > j:
    res += j
  else:
    res += j - i
print(res)

Solution (Python):

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

C = collections.Counter(A)
ans = 0
for v, c in C.items():
    if v > c:
        ans += c
    else:
        ans += c-v
print(ans)

Solution (Python):

import collections
import itertools as it
import math

 

n  = int(input())

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


c = collections.Counter(a)

ans = 0

for c_ in c.items():
    if c_[0] > c_[1]:
        ans += c_[1]
    elif c_[0] < c_[1]:
        ans += c_[1] - c_[0]

print(ans)

Solution (Python):
import collections
a = int(input())
ar = list(map(int,input().split(" ")))
br = collections.Counter(ar)
cr = set(ar)
count = 0
for r in cr:
    if br[r] < r:
        count += br[r]
    elif br[r] >= r:
        count += br[r] - r
print(count)

Solution (Python):
import collections
N=int(input())
a=list(map(int,input().split()))
b=collections.Counter(a)
c=list(set(a))
count=0
for i in range(0,len(c)):
    if b[c[i]]>=c[i]:
        count+=b[c[i]]-c[i]
    else:
        count+=b[c[i]]
print(count)

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

print(ans)

Solution (Python):



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


def main():
    d = {}
    for a in A:
        if a in d:
            d[a] += 1
        else:
            d[a] = 1
    
    ans = 0
    for key, value in d.items():
        if key > value:
            ans += value
        else:
            ans += value - key
    
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
hm={}
n=int(input())
ans=n
arr=[int(i) for i in input().split()]
for i in arr:
    hm[i]=hm.get(i,0)+1
for i in hm:
    if hm[i]!=i:
        if hm[i]>i:
            ans-=hm[i]-i
        else:
            ans-=hm[i]
print(n-ans)

Solution (Python):
import random, math
from copy import deepcopy as dc
from bisect import bisect_left, bisect_right




def solution(li):
	ma = {}
	for i in li:
		ma[i] = ma.get(i, 0) + 1
	s = 0
	for i in ma:
		if i != ma[i]:
			if ma[i] > i:
				s += ma[i] - i
			else:
				s += ma[i]
	return s



def input_test():
	
		n = int(input())
		
		
		li = list(map(int, input().strip().split(" ")))
		out = solution(li)
		print(out)


def test():
	pass


input_test()

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

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

cnt = {}

for x in a:
    if x not in cnt:
        cnt[x] = 1
    else:
        cnt[x] += 1

ans = 0

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

print(ans)

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

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

occ = {}
for i in range(n):
    if a[i] not in occ:
        occ[a[i]] = 0
    occ[a[i]] += 1

res = 0
for x in occ:
    if (occ[x] < x):
        res += occ[x]
    else:
        res += occ[x] - x

print(res)

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

Solution (Python):
import collections

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

c = collections.Counter(A)
cs = sorted(c.items(), key=lambda x:x[0])
cnt = 0
for i in range(len(cs)):
    if(cs[i][0] != cs[i][1]):
        if(cs[i][0] < cs[i][1]):
            cnt += cs[i][1]-cs[i][0]
        else:
            cnt += cs[i][1]
print(cnt)

Solution (Python):
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
cnt_dic=defaultdict(int)
for i in a:
  cnt_dic[i]+=1
cnt=0
for v in cnt_dic.keys():
  if cnt_dic[v]==v:
    pass
  else:
    if cnt_dic[v]<v:
      cnt+=cnt_dic[v]
    else:
      cnt+=(cnt_dic[v]-v)
print(cnt)

Solution (Python):
import sys
import math
from collections import Counter
get_string = lambda: sys.stdin.readline().strip()
get_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
get_int = lambda: int(sys.stdin.readline())



n=get_int()
a=get_list()
freq=Counter(a)
ans=0
for key,val in freq.items():
    if val>key:
        ans+=val-key
    elif key>val:
        ans+=val
print(ans)

Solution (Python):
len_nums = int(input())
nums = input().split()

dic = {}
for num in nums:
	if num in dic:
		dic[num] += 1
	else:
		dic[num] = 1

count_to_be_removed = 0
for key, value in dic.items():
	key = int(key)
	
	if key <= value:
		count_to_be_removed += value - key
	else:
		count_to_be_removed += value

print(count_to_be_removed)

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

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

ans = 0
for n, cnt in Counter(A).items():
    if cnt >= n:
        ans += cnt - n
    else:
        ans += cnt
print(ans)

Solution (Python):
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
AC=Counter(A)
ans=0
for i,e in AC.items():
    if i==e:
        continue
    elif i>e:
        ans+=e
    elif i<e:
        ans+=e-i
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 v >= k:
        ans += v-k
    else:
        ans += v

print(ans)

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

a.sort()

good_val = 0
total_cnt = 0
tmp_cnt = 0
over = 0
for i in range(n):
  if good_val == 0:
    good_val = a[i]

  if a[i] == good_val:
    tmp_cnt += 1
    if over == 0 and tmp_cnt == good_val:
      tmp_cnt = 0
      over = 1
    if i == n - 1:
      total_cnt += tmp_cnt
  else:
    total_cnt += tmp_cnt
    good_val = a[i]
    tmp_cnt = 1
    over = 0
    if i == n - 1:
      total_cnt += tmp_cnt

print(total_cnt)

Solution (Python):
N, = map(int, input().split())
A = map(int, input().split())
from collections import defaultdict
d = defaultdict(int)
for a in A:
    d[a] += 1
r = 0
for a in d:
    if a > d[a]:
        r += d[a]
    else:
        r += d[a]-a
print(r)

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

from collections import Counter
C = 0
mycounter = Counter(A)
for i, v in mycounter.items():
  if int(i) < int (v):
    C += int (v) - int(i)
  elif int(i) > int(v):
    C += int(v)

print(C)

Solution (Python):
from itertools import groupby

def main():
    N=int(input())
    A=list(map(int,input().split()))
    A.sort()
    X=groupby(A)
    s=0
    for key,group in X:
        t=len(list(group))
        if int(key)>t:
            s+=t
        else:
            s+=t-int(key)
    print(s)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

N = int(input())
A = Counter(map(int, input().split()))
ans = 0
for x, y in A.items():
    if x > y:
        ans += y
    elif x < y:
        ans += (y-x)
print(ans)

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

print(ans)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())

    def string():
        return sys.stdin.readline().rstrip()

    def map_int():
        return [int(x) for x in Scanner.string().split()]

    def string_list(n):
        return [input() for i in range(n)]

    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]

    def int_cols_list(n):
        return [int(input()) for i in range(n)]


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

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

    def roundUp(a, b):
        return -(-a // b)

    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    def toLowerMultiple(a, x):
        return (a // x) * x

    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    
    N = Scanner.int()
    A = Scanner.map_int()
    M = Counter(A)
    ans = 0
    for k, v in M.items():
        if k == v:
            continue
        if k < v:
            ans += v-k
        else:
            ans += v
    print(ans)
    return


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter

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

a = Counter(A)

con = 0

for num in a.keys():
  time = a[num]
  if time > num:
    con += (time - num)
  elif num > time:
    con += time

print(con)

Solution (Python):
from collections import Counter

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

c = Counter(A)
ans = 0
for x in c.keys():
    if c[x] >= x:
        ans += c[x] - x
    else:
        ans += c[x]
print(ans)

Solution (Python):
from collections import defaultdict as dd
n=int(input())
a=[int(i) for i in input().split()]
d=dd(int)
for i in a:
    d[i]+=1

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

Solution (Python):

import sys
import collections


def solve(N: int, a):
    c = collections.Counter(a)
    z = 0
    for k, v in c.items():
        if v - k < 0:
            z += v
        else:
            z += v - k
    print(z)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(N, a)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

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

main()

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

cn = 1
for i in range(n):
    if(a[i]==a[i+1]):
        cn += 1
    else:
        b.append((a[i],cn))
        cn = 1
        
b.sort(key = lambda x : (x[0],x[1]))

sn = 0

for i in range(len(b)):
    if(b[i][1]-b[i][0]<0):
        sn += b[i][1]
    elif(b[i][1]-b[i][0]>0):
        sn += b[i][1]-b[i][0]
        
print(sn)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
c=list(set(b))
c.sort()
kosuu_list=[]
kosuu=1
for i in range(len(b)-1):
    
    
    if b[i]==b[i+1]:
        kosuu+=1
    else:
        kosuu_list.append(kosuu)
        kosuu=1
kosuu_list.append(b.count(b[-1]))

count=0

for i in range(len(c)):
    if kosuu_list[i]==c[i]:
        count+=0
    elif kosuu_list[i]>=c[i]:
        count+=kosuu_list[i]-c[i]
    else:
        count+=kosuu_list[i]
print(count)

Solution (Python):
from collections import Counter


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


if __name__ == '__main__':
    main()

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

Solution (Python):
import collections

n = int(input())
a = list(map(int, input().split()))
ac = collections.Counter(a)
ans = 0
for i in ac.items():
    if i[0] != i[1]:
        if i[1] > i[0]:
            ans += i[1] - i[0]
        else:
            ans += i[1]
print(ans)

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

for i in range(N):
    if not A[i] in dic:
        dic[A[i]] = 0
    dic[A[i]] += 1

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

Solution (Python):


import sys
import math

n=int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

numlist={}

for i in range(0,n):
	if(hoge[i] in numlist):
		numlist[hoge[i]]+=1
	else:
		numlist[hoge[i]]=1

total=0

for i in numlist:
	if(i in numlist):
		
		if(i>numlist[i]):
			total+=numlist[i]
		else:
			total+=numlist[i]-i




print(total)

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

counts = {}
for a in A:
    if a not in counts:
        counts[a] = 1
    else:
        counts[a] += 1
    
ans = 0
for key,val in counts.items():
    if val > key:
        ans += val - key
    if val < key:
        ans += val

print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
dic = defaultdict(int)
for a in A:
    dic[a] += 1

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

Solution (Python):

import sys

input = sys.stdin.readline

from collections import Counter


def main():
    n = int(input())
    cnt = Counter(list(map(int, input().rstrip().split())))
    ans = 0
    for i, j in cnt.items():
        if i > j:
            ans += j
        elif i < j:
            ans += j - i
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    cnt = {}
    for i in lst:
        if i not in cnt:
            cnt[i] = 0
        cnt[i] += 1
    ans = 0
    for i, j in cnt.items():
        if i > j:
            ans += j
        elif i < j:
            ans += j - i
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
N = int(input())
As = Counter(list(map(int,input().split())))
ans = 0
for x,y in As.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()))

D = {}

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

ans = 0

for a in D :
    if D[a] < a :
        ans += D[a]
    else :
        ans += (D[a] - a)

print(ans)

Solution (Python):
import collections

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

c = collections.Counter(a)

for k, v in c.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()))
a_set = set(a)
ans = 0

from collections import Counter
x_count = Counter(a)

for i in a_set:
    if i != x_count[i]:
        if i < x_count[i]:
            ans += abs(x_count[i] - i)
        elif i > x_count[i]:
            ans += x_count[i]
        
print(ans)

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

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

Solution (Python):
from collections import defaultdict

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

counts = defaultdict(int)
for a in As:
    counts[a] += 1

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

print(total)

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

dic = {}
for a in A:
    dic[a] = dic.get(a,0)+1
    
ans = 0
for k in dic:
    if dic[k]>k:
        ans += dic[k]-k
    elif dic[k]<k:
        ans += dic[k]
print(ans)

Solution (Python):
N = int(input())
a = [int(_) for _ in input().split()]
List = [0]*(10**5+1)
ans = 0

for i in a:
    if i > 10**5:
        ans += 1
    else:
        List[i] += 1

for i in range(1, 10**5+1):
    if List[i] >= i:
        ans += List[i] - i
    else:
        ans += List[i]

print(ans)

Solution (Python):
from collections import Counter
n=int(input())
a=tuple([int(i) for i in input().split()])
cnt=dict(Counter(a))
ans=0
for i,j in zip(cnt.keys(),cnt.values()):
    if i>j:
        ans+=j
    elif i!=j:
        ans+=j-i
print(ans)

Solution (Python):
n,*a=map(int,open(0).read().split())
d={}
for i in a:d[i]=d.get(i,0)+1
print(sum(d[i]-i*(d[i]>=i)for i in d))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
import collections
a=collections.Counter(A)
ans=0
for i in a.items():
        if(i[0]!=i[1]):
                ans+=i[1] if(i[1]<i[0]) else (i[1]-i[0])
print(ans)

Solution (Python):
import collections
n=int(input())
a=list(map(int,input().split()))
c=collections.Counter(a)
k=0
for s,t in c.items():
    if t<s:
        k+=t
    else:
        k+=t-s
print(k)

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

Solution (Python):
import collections

n = int(input())
a = collections.Counter(list(map(int, input().split()))).most_common()
ans = 0
for i, j in a:
    if i > j:
        ans += j
    if i < j:
        ans += j - i
print(ans)

Solution (Python):
import collections

n = int(input())
a = collections.Counter(list(map(int, input().split()))).most_common()
ans = 0
for i, j in a:
    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 i, v in C.items():
    if v > i:
        ans += v-i
    elif v < i:
        ans += v

print(ans)

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

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

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

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

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

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

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

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

Solution (Python):
import collections

N = int(input())
A = input().split(' ')
counter_A = collections.Counter(A)

ans = 0
for k, v in counter_A.items():
    if int(k) <= v:
        ans += v - int(k)
    else:
        ans += v
print(ans)

Solution (Python):
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
Ca=dict(Counter(A))
Dk=Ca.keys()
a=0
for i in Dk:
    if i>Ca[i]:
        a+=Ca[i]
    elif i<Ca[i]:
        a+=Ca[i]-i
print(a)

Solution (Python):
import collections 
def inpl(): return [int(i) for i in input().split()]

N= int(input())
A = collections.Counter(inpl())
ans = 0
for i in A.keys():
    if i > A[i]:
        ans += A[i]
    else:
        ans += A[i] - i
print(ans)

Solution (Python):
from collections import defaultdict
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

n = getN()
nums = getlist()

kazu = defaultdict(int)
for i in nums:
    kazu[i] += 1

ans = 0
for x in kazu.keys():
    if kazu[x] >= x:
        ans += kazu[x] - x
    else:
        ans += kazu[x]

print(ans)

Solution (Python):
from collections import defaultdict
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

n = getN()
nums = getlist()

kazu = defaultdict(int)
for i in nums:
    kazu[i] += 1

ans = 0
for x in kazu.keys():
    if kazu[x] >= x:
        ans += kazu[x] - x
    else:
        ans += kazu[x]

print(ans)

Solution (Python):
from collections import Counter as C

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

res = 0
d = (dict(c))
for k in list(c):
    
    if d[k]<k:
        res += d[k]
    else:
        res += d[k] - k
print(res)

Solution (Python):
from collections import Counter as C

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

res = 0
d = (dict(c))
for k in list(c):
    
    if d[k]<k:
        res += d[k]
    else:
        res += d[k] - k
print(res)

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

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

cnt = Counter(a)

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

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

for i in range(N):
    if (a[i] in nlis)==False:
        nlis[a[i]]=1
    else:
        nlis[a[i]]+=1
ans=0
for i in nlis:
    if nlis[i]<i:
        ans+=nlis[i]
    else:
        ans+=abs(nlis[i]-i)
    
print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().strip().split()))
a.sort()
i = 0
j = 1
ans = 0

for i in range(N-1):
	if a[i] == a[i+1]:
		j += 1
	else:
		if j >= a[i]:
			ans += j - a[i]
		else:
			ans += j
		j = 1
if a[N-1] != a[N-2]:
	if a[N-1] != 1:
		ans += 1
else:
	if j >= a[i]:
		ans += j - a[i]
	else:
		ans += j
print(ans)

Solution (Python):
import collections
N=int(input())
A=[int(a) for a in input().split()]
c=collections.Counter(A)
ans=0
for k,v in c.items():
  if k>v:
    ans+=v
  else:
    ans+=v-k
print(ans)

Solution (Python):


import collections


input()


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


count_res = 0


count = collections.Counter(a)


for k, v in count.items():


    if (k>v) :
        count_res += v




    elif (k<v) :
        count_res += (v-k)
        

print(count_res)