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 Counter
n = int(input())
a = list(map(int, input().split()))

a = Counter(a)
cnt = 0
for k, v in a.items():
    if k == v:
        continue
    elif k > v:
        cnt += v
    else:
        cnt += v - k

print(cnt)

Solution (Python):
from collections import Counter

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

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

key = list(c.keys())


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

Solution (Python):
from collections import defaultdict

ans,n = 0,int(input())
a_list = list(map(int,input().split()))
a_dict = defaultdict(int)
for i in range(n):
    a_dict[a_list[i]]+=1
for key,value in a_dict.items():
    if value>key:
        ans += value-key
    elif value<key:
        ans += value
print(ans)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
dict={}
count=0
for i in a:
  if i not in dict:
    dict[i] = 1
    continue
  dict[i] += 1
for i,j in dict.items():
  if i > j:
    count += j
  elif i < j:
    count += j-i
print(count)

Solution (Python):
from collections import Counter
n = int(input())
ls = list(map(int,input().split()))
c = Counter(ls)
p = 0
for s,t in c.items():
    if s > t:
        p += t
    elif s < t:
        p += t - s
print(p)

Solution (Python):
from collections import Counter
n = int(input())
a_li = list(map(int,input().split()))
a_counter = Counter(a_li)
a_most = a_counter.most_common()
ans = 0
for s in a_most:
    dum = s[1] - s[0]
    if dum < 0:
        ans += s[1]
    elif dum > 0:
        ans += dum
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = []
c = {}
ans = 0
for i in range(n):
  if a[i] in c:
    c[a[i]] += 1
  else:
    c[a[i]] = 1
    b.append(a[i])
  
for i in range(len(b)):
  temp=c[b[i]]
  temp2=b[i] 
  if temp > temp2:
    ans += temp-temp2
  elif temp < temp2:
    ans += temp
  
  
print(ans)

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
from collections import Counter
ans = 0
for k,v in Counter(A).items():
    if v!=k and k>v:
        ans+=v
    elif v!=k and k<v:
        ans+=v-k
print(ans)

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

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

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

print(ans)

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

import collections
c = collections.Counter(A)
ans = 0
for k in c.keys():
    if c[k] > k:
        ans += c[k] - k
    elif c[k] < k:
        ans += c[k]
print(ans)

Solution (Python):
from collections import defaultdict

n = int(input())
as_ = map(int, input().strip().split())

d = defaultdict(int)

for a in as_:
    d[a] += 1

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

print(counts)

Solution (Python):

from collections import Counter
n = int(input())
nums = [int(i) for i in input().split()]
c = Counter(nums)


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

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

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

import collections

c = collections.Counter(al)

res = 0
temp =0
for i in range(1,n+1):
    if c[i] ==0:
        pass
    elif c[i] ==i:
        temp += c[i]
        pass
    else:
        temp += c[i]
        if c[i] >i:
            res += c[i]-i
        else :
            res +=c[i]

res += (n-temp)
print(res)

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

n = int(readline())
a = list(map(int, read().split()))

dic = {}
ans = 0

for i in range(n):
  ans += 1
  try:
    dic[a[i]] += 1
    if dic[a[i]] == a[i]:
      ans -= a[i]
  except KeyError:
    dic[a[i]] = 1
    if dic[a[i]] == a[i]:
      ans -= a[i]

print(ans)

Solution (Python):
from collections import Counter

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

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

print(cnt)

Solution (Python):
from collections import Counter

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

cnt = Counter(a)
ans = 0
for key, val in cnt.items():
    if val < key:
        ans += val
    else:
        ans += val - key

print(ans)

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

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

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

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

b = collections.Counter(a)

ans = 0

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

print(ans)

Solution (Python):
from collections import Counter

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

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

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

x = {}

for i in range(N):
    if a[i] in x:
        x[a[i]]=x[a[i]]+1
    else:
        x[a[i]]=1


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


print(ans)

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

from collections import Counter

c = Counter(a)

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

print(cnt)

Solution (Python):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *

from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction



mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]






n=l()[0]
A=l()
d={}
for i in range(n):
    if A[i] not in d:
        d[A[i]]=0
    d[A[i]]+=1
ans=0
for k in d:
    if(d[k]<k):
        ans+=d[k]
    else:
        ans+=(d[k]-k)
print(ans)

Solution (Python):
from collections import Counter


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

Solution (Python):
from collections import Counter

N,*a = map(int, open(0).read().split())
c = Counter(a)
ans = 0
for x in c.items():
    if x[1] >= x[0]:
        ans += x[1] - x[0]
    else:
        ans += x[1]
print(ans)

Solution (Python):
import collections

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

ac = collections.Counter(a)
ans = 0

for i in s:
    if ac[i] < i:
        ans += ac[i]
    else:
        ans += ac[i] - i

print(ans)

Solution (Python):

n = int(input())
a = list(map(int,input().split()))
base = [0]*n
ans = 0

for i in range(n):
  if a[i] > n:
    ans += 1
  else:
    base[a[i]-1] += 1
    
for i in range(n):
  if base[i] == 0:
    continue
  elif base[i] == i+1:
    continue
  elif (base[i] < i+1) and (0 < base[i]):
    ans += base[i]
  elif i+1 < base[i]:
    ans += (base[i] - (i+1))
    
print(ans)

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

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

d = {}
ans = 0

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

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

print(ans)

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

for i in a:
  if i not in dict:
    dict[i] = 1
  else:
    dict[i] += 1
    
for k,v in dict.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()))

arr=collections.Counter(a)
ans=0
for i in arr:
    if i<=arr[i]:
        ans+=(arr[i]-i)
    else:
        ans+=arr[i]
print(ans)

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

Solution (Python):
from collections import Counter
n = int(input())
aaa = list(map(int, input().split()))
cnt_a = Counter(aaa)
ans = 0
for key in cnt_a.keys():
    value = cnt_a[key]
    if key > value:
        ans += value
    elif key < value:
        ans += value - key
    else:
        continue
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
c = Counter(input().split())
ans = 0
for q, w in c.items():
    q, w = int(q), int(w)
    ans += w - q if q < w else (w if q != w else 0)
print(ans)

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

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

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

from collections import Counter

z = Counter(a)

i,j,temp = (0,0,0)
for tu in z.items():
    i,j = tu
    if i>j:
        temp+=j
    elif i<j:
        temp+=j-i
    else:
        continue

print(temp)

Solution (Python):
from collections import Counter

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

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

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

num_count = {}
for num in a:
    if num in num_count:
        num_count[num] += 1
    else:
        num_count[num] = 1
ans = 0
for key in num_count:
    if key < num_count[key]:
        ans += num_count[key] - key
    elif key > num_count[key]:
        ans += num_count[key]
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7



N = INT()
a = LIST()

A = defaultdict(int)

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


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

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7



N = INT()
a = LIST()

A = Counter(a)

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

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7



N = INT()
a = LIST()

A = Counter(a)

ans = 0
for x in A:
	if x > A[x]:
		ans += A[x]
	else:
		ans += A[x] - x

print(ans)

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

print(ans)

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

count_num = dict()
for num in L:
  if num not in count_num:
    count_num[num] = 1
  else:
    count_num[num] += 1

removals = 0
for k, v in count_num.items():
  if k == v:
    continue
  elif k < v:
    removals += (v - k)
  else:
    removals += v

print(removals)

Solution (Python):
from collections import Counter

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

a_c = Counter(A)

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

Solution (Python):
from collections import Counter

N = int(input())
c = Counter(list(map(int, input().split())))
ans = 0
for k in c:
  ans += c[k] - k if k <= c[k] else c[k]

print(ans)

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

dic={}
for i in range(n):
    if dic.get(a[i])==None:
        dic[a[i]]=1
    else:
        dic[a[i]]+=1

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

Solution (Python):
from collections import Counter
def main():
    n = int(input())
    a = tuple(map(int, input().split()))
    ac = Counter(a)
    r = 0
    for ace in ac:
        if ac[ace] < ace:
            r += ac[ace]
        else:
            r += (ac[ace] - ace)
    print(r)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

n = int(input())

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

def thankyou():
    for k, v in a.items():
        if k > v:
            yield v
        else:
            yield v - k

print(sum(thankyou()))

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

ans = 0
c = {}
for i in s:
    if i not in c:
        c[i] = 1
    elif c[i] < i:
        c[i] += 1
    else:
        ans += 1

for k,v in c.items():
    if k != v:
        ans += v
print(ans)

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

import collections
c = collections.Counter(A)

A = sorted(set(A))

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

Solution (Python):
from collections import Counter
N=int(input())
A=Counter(list(map(int,input().split())))
ans=0
for key,value in A.items():
    if key<value:
        ans+=value-key
    elif key>value:
        ans+=value
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 Counter
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
n = ii()
A = iil()
c = Counter(A)

ans = 0

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

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

N = getN()
A = Counter(getList())

ans = 0
for i in A.items():
    if i[0] < i[1]:
        ans += i[1] - i[0]
    elif i[0] > i[1]:
        ans += i[1]
print(ans)

Solution (Python):
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    counter = Counter(A)
    ans = 0
    for a, c in counter.items():
        if c < a:
            ans += c
        else:
            ans += c - a
    print(ans)


if __name__ == '__main__':
    main()

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

c = Counter(a)
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()))

d = {}
for ai in a:
  if ai in d:
    d[ai] += 1
  else:
    d[ai] = 1
  
ans = 0
for key in d:
  if d[key] >= key:
    ans += (d[key] - key)
  else:
    ans += d[key]
print(ans)

Solution (Python):
from collections import Counter

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

ans = 0
for key in c:
  if c[key] >= key:
    ans += (c[key] - key)
  else:
    ans += c[key]
print(ans)

Solution (Python):
from collections import defaultdict

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

d = defaultdict(int)
for ai in a:
  d[ai] += 1
  
ans = 0
for key in d:
  if d[key] >= key:
    ans += (d[key] - key)
  else:
    ans += d[key]
print(ans)

Solution (Python):
import collections
def solve(n, a_list):

    counter = collections.Counter()

    for i in a_list:
        counter[i] += 1

    ans = sum([v-k if k < v else v for k, v in counter.items() if k != v])

    return ans

if __name__ == "__main__":
    n = int(input())
    a_list = [int(i) for i in input().split()]
    print(solve(n, a_list))

Solution (Python):



import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
cou=Counter(lis)
ans=0
for v in cou.keys():
    if cou[v]>=v:
        ans+=cou[v]-v
    else:
        ans+=cou[v]
print(ans)

Solution (Python):
n = int(input())
L = sorted(map(int, input().split()))
d = {}
for i in range(n):
    if L[i] not in d:
        d[L[i]] = 1
    else:
        d[L[i]] += 1
cnt = 0
for k, v in d.items():
    if k == v:
        continue
    else:
        if k > v:
            cnt += v
        else:
            cnt += v - k
print(cnt)

Solution (Python):
from collections import Counter

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

a = Counter(a)

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

print(ans)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n = n//a
    count += 1
  if a**count == n:
    return count
  else:
    return count+1





N = I()
A = IL()
d = DD(int)
for a in A:
  d[a] += 1
  
keys = [k for k in d]
ans = 0

for k in keys:
  if k > d[k]:
    ans += d[k]
  else:
    ans += d[k]-k

P(ans)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
A = a.sort()
array = list(set(a))
array.sort()
sum = 0
n = 0
for i in range(len(array)):
    cnt = 0
    for j in range(n,len(a)):
        if array[i] == a[j]:
            cnt += 1
        else:
            break
    n += cnt
    if cnt >= array[i]:
        sum += cnt - array[i]
    else:
        sum += cnt
print(sum)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split())) 
s = 0
A = Counter(a)
l = len(A)


for key, value in A.items():
    if key <= value:
        s+= value - key
    else:
        s += value

print(s)

Solution (Python):
from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]
A = Counter(a)
ans = 0
for x in A:
    if x < A[x]:
        ans += A[x]-x
    elif A[x] != x:
        ans += A[x]
print(ans)

Solution (Python):
import collections
n=int(input())
a=list(map(int,input().split()))
a=collections.Counter(a)
values,counts=zip(*a.most_common())
l=len(values)
ans=0
for i in range(0,len(values)):
  if counts[i]<values[i]:
    ans=ans+counts[i]
  elif counts[i]>values[i]:
    ans=ans+counts[i]-values[i]
print(ans)

Solution (Python):
from collections import defaultdict
def main():
    N = int(input())
    a = [int(i) for i in input().split()]
    dd = defaultdict(int)
    res=0

    for i in a:
        dd[i]+=1 
    for i in dd.keys():
        if dd[i]<i:
            res += dd[i]
        elif dd[i]>i:
            res += dd[i]-i 
            dd[i] = i 
    print(res)
            



if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter

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

a_c = Counter(a_input)
ans = 0
for k,v in a_c.items():
    if k>v:
        ans+=v
    else:
        ans+=(v-k)
print(ans)

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

Solution (Python):
import collections
n=int(input())
A=list(map(int,input().split()))
a=collections.Counter(A)
key,value=zip(*a.most_common())
cnt=0
for i in range(len(key)):
  if key[i]>value[i]:
    cnt+=value[i]
  elif key[i]<value[i]:
    cnt+=value[i]-key[i]
print(cnt)

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

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

A = Counter(A).most_common()
for key,val in A:
  if val >= key:
    ans += val - key
  else:
    ans += val
print(ans)

Solution (Python):
import collections

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

for item in c.items():
    x = item[0] 
    y = item[1] 

    if x < y:
        ans += y-x

    if x > y:
        ans += y

print(ans)

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

a_map=defaultdict(int)
for i in a:
    a_map[i] += 1
print(sum([cnt-i if i < cnt else cnt for i, cnt in a_map.items() if i != cnt]))

Solution (Python):
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
c = Counter(a)
nums = 0
for key, value in c.items():
    if key == value:
        pass
    elif key > value:
        nums += value
    else:
        nums += value - key
print(nums)

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

d = {}

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

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

print(ans)

Solution (Python):
from collections import Counter
N = int(input())
a = Counter(list(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):
import collections


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

a.sort()

aSet = set(a)

c = collections.Counter(a)

count = 0

for i in aSet:
    if c[i] > i:
        count = count + c[i] - i
    elif c[i] < i:
        count = count + c[i]


print(count)

Solution (Python):
N = int(input())
A = sorted(list(map(int, input().split())))
ans = 0
before_num = A[0]
num_count = 1
A.append(-1)

for num in A[1:]:
    if num == before_num:
        num_count += 1
    else:
        if num_count >= before_num:
            ans += num_count - before_num
        else:
            ans += num_count
        num_count = 1
        before_num = num

print(ans)

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

c = dict()
for a in A:
    if a not in c:
        c[a] = 1
    else:
        c[a] += 1

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

Solution (Python):
import collections
N = int(input())
A = [int(x) for x in input().split()]
c = collections.Counter(A)

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

Solution (Python):
import collections

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

c = collections.Counter(numbers)

output = 0

for k, v in c.items():
    if k > v:
        output += v
    elif v > k:
        diff = v - k
        output += diff

print(output)