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

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

for i in range(N):
  count += 1
  if i == N-1 or a[i+1] != a[i]:
    if a[i] < count:
      ans += count - a[i]
    elif a[i] > count:
      ans += count
    count = 0
print(ans)

Solution (Python):
from collections import Counter


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


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


print(ans)

Solution (Python):



def main():
    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
        elif key < value:
            ans += value - key

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

Solution (Python):











import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    from collections import Counter
    N = I()
    a = LI()
    c = Counter(a)
    ans=0
    for i, j in c.items():
        if j - i < 0:
            ans += j
        else:
            ans += j - i
    print(ans)
if __name__ == '__main__':
    main()

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

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

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

print(cnt)

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

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

Solution (Python):
N = input()
d = dict()
for x in map(int, input().split()):
  if d.get(x) is None:
    d[x] = 0
  d[x] += 1

print(sum((d[x]-x if d[x]>=x else d[x]) for x in d))

Solution (Python):
from collections import Counter

N = int(input())
c = Counter(int(x) for x in input().split())

answer = 0

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

Solution (Python):
from collections import Counter

n = input()
arr = Counter(map(int, input().split()))
count = 0
for k, v in arr.items():
  if k > v:
    count += v
  if k < v:
    count += v-k
print(count)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  a=LI()

  a.sort()

  b=a[0]
  c=1
  sm=0
  for x in a[1:]:
    if b==x:
      c+=1
    else:
      if c==b:
        pass
      elif c>b:
        sm+=c-b
      else:
        sm+=c

      c=1
      b=x

  if c==b:
    pass
  elif c>b:
    sm+=c-b
  else:
    sm+=c

  return sm

print(main())

Solution (Python):
from collections import Counter

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

c = Counter(a)

cnt = 0
for i, x in c.items():
    if x > i:
        cnt += (x - i)
    elif x < i:
        cnt += x

print(cnt)

Solution (Python):
n = int(input())
arr = sorted(list(map(int, input().split())))+[0]

ans = 0
num = arr[0]
cnt = 0

for i in arr:
        if i == num: cnt += 1
        else:
                if cnt<num : dif = 1000000001
                else: dif = cnt-num
                ans += min(cnt, dif)
                cnt = 1
                num = i
print(ans)

Solution (Python):
import collections
N=int(input())
a=list(map(int,input().split()))
b=collections.Counter(a).most_common()
ans=0
for key,value in b:
    if key>value:
        ans+=value
    else:
        ans+=value-key
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
A = Counter(list(map(int, input().split()))).most_common()
ans = 0
for a in A:
    if a[0] < a[1]:
        ans += a[1] - a[0]
    elif a[0] > a[1]:
        ans += a[1]
print(ans)

Solution (Python):

import sys
from collections import Counter
INF = float("inf")


def solve(N: int, a: "List[int]"):
    counter = Counter(a)

    ans = 0
    for key in counter:
        if counter[key] < key:
            ans += counter[key]
        else:
            ans += counter[key]-key
    print(ans)
    return


a = []
for i in range(1, 10):
    a.extend([i]*3)

counter = Counter(a)


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):
n=int(input())
s=list(map(int,input().split()))
a={i:0 for i in set(s)}
for i in s:
	a[i]+=1
cnt=0
for k,v in a.items():
	cnt+=v-k if v>=k else v
print(cnt)

Solution (Python):
N = int(input())
a = sorted([int(x) for x in input().split()])
i,ans = 0,0
while i < N:
    if a[i] > N:
        ans += N-i
        break
    c = a.count(a[i])
    if c > a[i]:
        ans += c-a[i]
    elif c < a[i]:
        ans += c
    i += c

print(ans)

Solution (Python):
from collections import Counter
N, *a = map(int, open(0).read().split())
c = Counter(a)
print(sum(c[v] if v > c[v] else c[v] - v for v in c))

Solution (Python):
from collections import Counter
N, *a = map(int, open(0).read().split())
c = Counter(a)
ans = 0
for v in c:
  if v > c[v]:
    ans += c[v]
  else:
    ans += c[v] - v
print(ans)

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

cnt = [0]*(10**5)
c = 0

for i in a:
    if i <= 10**5:
        cnt[i-1] += 1
    else:
        c += 1



for i in range(10**5):
    if cnt[i] > i+1:
        c += cnt[i] - (i+1)
    
    elif cnt[i] < i+1:
        c += cnt[i]

print(c)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
ans = 0
idx = []
for i,x in enumerate(a):
    if x > 10**5:
        ans += 1
        idx += [i]
for i in reversed(idx):
    del a[i]

import sys
if len(a) == 0:
    print(ans)
    sys.exit()

counts = [0] * (10 ** 5 + 1)

for i in a:
    counts[i] += 1
    
for i in range(len(counts)):
    if counts[i] == 0:continue
    if counts[i] < i:
        ans += counts[i]
    elif counts[i] > i:
        ans += counts[i]-i
        
print(ans)

Solution (Python):

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

bucket = [0]*(1 + 10**5)

for a in an:
    if a < len(bucket):
        bucket[a] += 1
    else:
        bucket[0] += 1


ans = 0
for i in range(len(bucket)):
    if i == bucket[i]:
        continue

    ans += bucket[i] if i > bucket[i] else bucket[i] - i


print(ans)

Solution (Python):

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

bucket = [0]*(1 + 10**5)

for a in an:
    if a < len(bucket):
        bucket[a] += 1
    else:
        bucket[0] += 1


ans = 0
for i in range(len(bucket)):
    if i == bucket[i]:
        continue

    ans += bucket[i] if i > bucket[i] else bucket[i] - i


print(ans)

Solution (Python):
from collections import Counter


def main():
    N = int(input())
    c = Counter()
    for x in map(int, input().split()): c[x] += 1

    print(sum([v if v < k else v - k for k, v in c.items()]))


if __name__ == '__main__':
    main()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  N=int(input())
  l=LI()

  l.sort()
  l.append(inf)

  c=0
  a=l[0]
  cnt=1
  for x in l[1:]:
    if a==x:
      cnt+=1
    else:
      if a<cnt:
        c+=cnt-a
      elif a==cnt:
        pass
      else:
        c+=cnt
      a=x
      cnt=1

  print(c)

main()

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

r = 0
d = {}
pass_list = []
for a in A:
    if a in pass_list:
        r += 1
        continue
    r += 1
    if a in d:
        d[a] += 1
        if d[a] == a:
            r -= a
            pass_list.append(a)
    else:
        d[a] = 1
        if d[a] == a:
          r -= a
          pass_list.append(a)

print(r)

Solution (Python):
N = int(input())
numstr = input().split()
arr = [int(num) for num in numstr]

def main():
    dic = {}
    m = max(arr)
    for num in arr:
        if num in dic:
            dic[num] += 1
        else:
            dic[num] = 1
    n = 0
    for key in dic.keys():
        if dic[key] > key:
            n += dic[key] - key
        if dic[key] < key:
            n += dic[key]
    return n

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

Solution (Python):

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

now = a[0]
nowc = 1
ans = 0
for i in range(1, N):
    if now == a[i]:
        nowc += 1
    else:
        if nowc > now:
            ans += nowc - now
        elif nowc < now:
            ans += nowc
        now = a[i]
        nowc = 1

if nowc > now:
    ans += nowc - now
elif nowc < now:
    ans += nowc

print(ans)

Solution (Python):
from functools import reduce
import math
import collections
def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N = int(input())
    a = list(int(_) for _ in input().split())
    a.sort()
    d = collections.defaultdict(int)
    for a_i in a:
        d[a_i] +=1
    ans = 0
    for k,v in d.items():
        if v>k:
            ans += v - k
        elif v<k:
            ans += v
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

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

cnt_dict = Counter(A)
keys_lst = list(cnt_dict.keys())
values_lst = list(cnt_dict.values())

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

Solution (Python):
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
ans = 0
C = Counter(A)
for key,val in zip(C.keys(),C.values()):
	ans += val if key > val else val-key
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
    else:
        ans += value
print(ans)

Solution (Python):
import bisect

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

a.sort()
pullout = 0


for i in list(set(a)):
    numi = bisect.bisect_right(a,i) - bisect.bisect_left(a,i)
    
    if numi == 0 or numi == i:
        continue
    elif numi > i:
        pullout += numi - i
    elif numi < i:
        pullout += numi

print(pullout)

Solution (Python):
from collections import defaultdict

d=defaultdict(int)

N=input()
a=list(map(int,input().split(" ")))
ans=0
for z in a:
  d[z]+=1

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

print(ans)

Solution (Python):
from collections import Counter

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

c = Counter(a)

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

print(s)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
dic = {}
for i in range(N):
  if dic.get(A[i]) is None: 
    dic[A[i]] = 1
  else:
    dic[A[i]] += 1

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

Solution (Python):
N=int(input())
list=list(map(int,input().split()))
while len(list) != 0and max(list) > len(list):
    list = [i for i in list if i < len(list)]

set = set(list)
cnt=0
for i in set:
    c=list.count(i)
    if c > i:
        cnt +=c-i
    elif c < i:
        cnt +=c
print(N-len(list)+cnt)

Solution (Python):
N=int(input())
list=list(map(int,input().split()))
while len(list) != 0and max(list) > len(list):
    list = [i for i in list if i < len(list)]

set = set(list)
cnt=0
for i in set:
    c=list.count(i)
    if c > i:
        cnt +=c-i
    elif c < i:
        cnt +=c
print(N-len(list)+cnt)

Solution (Python):
from collections import Counter

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

ans = 0
for num, freq in Counter(a).items():
    ans += freq- num if freq >= num else freq

print(ans)

Solution (Python):
from collections import Counter

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

ca = Counter(a)

ans = 0
for num, freq in ca.items():
    ans += freq- num if freq >= num else freq

print(ans)

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

m = {}
for a in A:
	if not a in m:
		m[a] = 1
	else:
		m[a] += 1

c = 0
for k in m:
	if k < m[k]:
		c += m[k] - k
	elif m[k] < k:
		c += m[k]

print(c)

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

Solution (Python):
import collections


def main():
    _ = int(input())
    a = map(int, input().split())
    c = collections.Counter(a)
    ans = 0
    for i, j in c.items():
        if i > j:
            ans += j
        else:
            ans += j - i
    print(ans)


main()

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

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

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

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

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

from collections import Counter

b = Counter(a)

counter = 0
for key in b.keys():
    if b[key] < key:
        counter += b[key]
    elif b[key] > key:
        counter += b[key] - key
print(counter)

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

Solution (Python):
from collections import Counter

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

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

Solution (Python):
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter

def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)


"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
n = ip()                                     

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









a.sort()
cnum = a[0]
ct = 1
s = 0
if n==1:
    if a[0] != 1:
        print(1)
        j(-1)
    else :
        print(0)
        j(-1)
for i in range(1,n):
    if a[i] != cnum:
        if ct != cnum:
            if ct > cnum:
                s+=ct-cnum
            else : s+=ct
        ct = 1
        cnum = a[i]
    else:
        ct+=1
if ct != cnum:
    if ct > cnum:
        s += ct - cnum
    else:
        s += ct
print(s)

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

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

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

ans = 0
for i in set(a):
  if i <= n:
    c = a.count(i)
    if c >= i:
      ans += i
print(n - ans)

Solution (Python):
import collections

N = int(input())

if N == 1:
  print(1 if int(input()) != 1 else 0)
  exit()

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

b = list(collections.Counter(a).items())

c = 0
for i in b:
  if i[1] - i[0] < 0:
    c += i[1]
  else:
    c += i[1] - i[0]

print(c)

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()

    cnt = {}
    for i in a:
        if i in cnt:
            cnt[i] += 1
        else:
            cnt[i] = 1
    
    ans = 0
    for k,v in cnt.items():
        if k!= v:
            if k>v:
                ans += v
            else:
                ans += v - k 
    
    print(ans)


solve()

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

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

Solution (Python):
from collections import Counter

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

print(sum([v-k if v>=k else v for k,v in a.items()]))

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]
nums = {}
ans = 0
for i in a:
    if(i in nums):
        nums[i] += 1
    else:
        nums[i] = 1
for x in nums:
    if(x > nums[x]):
        ans += nums[x]
    elif(x == nums[x]):
        pass
    else:
        ans += nums[x]-x
print(ans)

Solution (Python):
import sys
import bisect
import math
input = sys.stdin.readline

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

m = {}
for v in l:
    if m.get(v) != None:
        m[v] += 1
    else:
        m[v] = 1
        
c = 0
for num, count in m.items():
    if num > count:
        c += count
    elif num < count:
        c += count - num
        
print(c)

Solution (Python):

from collections import defaultdict

def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def submit():
    n, alist = read_input()

    occurs = defaultdict(int)
    for a in alist:
        occurs[a] += 1

    el = 0
    for k in occurs.keys():
        if occurs[k] < k:
            el += occurs[k]
        elif k < occurs[k]:
            el += occurs[k] - k

    print(el)

if __name__ == '__main__':
    submit()

Solution (Python):
from collections import Counter
from sys import exit, stdin
N = int(stdin.readline().rstrip())
A = Counter(int(_) for _ in stdin.readline().rstrip().split())
ans = []
for k, v in A.items():
    if k-v > 0:
        ans.append(v)
    elif k-v < 0:
        ans.append(abs(k-v))
print(sum(ans))

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


N = int(input())
a_list = list(map(int, input().split()))
a_list_unique = list(set(a_list))
a_cnt = Counter(a_list)
cnt = 0
for i in a_list_unique:
    a_dict = a_cnt[i]
    if i <= a_dict:
        cnt +=  a_dict - i
    else:
        cnt += a_dict
print(cnt)

Solution (Python):
from collections import Counter

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

num = Counter(a).most_common()

for i, j in num:
    if j >= i:
        sum += j - i
    else:
        sum += j

print(sum)

Solution (Python):
N = input()

cnt = 0
strdit = {}
for i in input().split():
    i = int(i)
    if i not in strdit.keys():
        strdit[i] = 0
    strdit[i] += 1

for i in strdit.keys():
    if i > strdit[i]:
        cnt += strdit[i]
    else:
        cnt += strdit[i] - i

print(cnt)

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

Solution (Python):
from collections import Counter

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

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

ans = 0
num = [0] * int(2e5)
for i in a:
    if i < 2e5:
        num[i] += 1
    else:
        ans += 1


for i in range(len(num)):
    if num[i] == 0:
        continue
    else:
        if num[i] < i:
            ans += num[i]
        elif num[i] > i:
            ans += num[i] - i

print(ans)

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

cnt = {}
for b in a:
    cnt[b] = cnt.get(b,0)+1
ans = 0
for key,val in cnt.items():
    if key <= val:
        ans += val - key
    else:
        ans += val
print(ans)

Solution (Python):


import sys
import math



N = int(input())
An = list(map(int, sys.stdin.readline().rstrip().split()))

Bn = {}
for a in An:
  if a not in Bn:
    Bn[a] = 1
  else:
    Bn[a] += 1

ans = 0
for b in Bn:
  if Bn[b] < b:
    ans += Bn[b]
  else:
    ans += Bn[b] - b

print(ans)

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

a.sort()

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

Solution (Python):
from collections import Counter
inf = 10**10


N = int(input())
a = list(map(int,input().split()))
c = Counter(a)
ans = 0
for i,j in c.items():
    if j>=i:
        ans += j-i
    else:
        ans += j
print(ans)

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

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

from collections import defaultdict
cnt=defaultdict(int)
M=0
for a in map(int,input().split()):
    cnt[a]+=1
    M=max(a,M)
ans=0
for i in cnt.keys():
    if cnt[i]>i:
        ans+=cnt[i]-i
    elif cnt[i]<i:
        ans+=cnt[i]
print(ans)

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

appeared = dict()

for a in A:
    if a in appeared.keys():
        appeared[a] += 1
    else:
        appeared[a] = 1

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

print(ans)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
ans=0
aa=list(set(a))
dict={}
for s in aa:
    dict[s]=0
for l in a:
    dict[l]+=1
for i in dict.items():
    num=i[0]
    amount=i[1]
    """                                                           
    cnt=a.count(i)                                                
    if cnt>i:                                                     
        ans+=cnt-i                                                
    elif cnt<i:                                                   
        ans+=cnt                                                  
    """
    if amount>num:
        ans+=amount-num
    elif amount<num:
        ans+=amount
print(str(ans))

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

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
S=set(L)
ans=0
dict={}

for s in S:
    dict[s]=0

for l in L:
    dict[l]+=1

for d in dict.items():
    num=d[0]
    amount=d[1]

    if amount>num:
        ans+=amount-num
    elif amount<num:
        ans+=amount

print(ans)

Solution (Python):
from collections import Counter as ct

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

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

print(ans)

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

Solution (Python):
import collections
N=int(input())
a=[int(i) for i in input().split()]
kosulist=collections.Counter(a)
ans=0
for num,kosu in kosulist.items():
    if kosu>=num:
        ans+=kosu-num
    else:
        ans+=kosu
print(ans)

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

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


checked = []
ans = 0
cnt_a = {}
for i in a:
  if i in cnt_a:
    cnt_a[i] += 1
  else:
    cnt_a[i] = 1

for k in cnt_a.keys():
  if cnt_a[k] >= k:
    ans += cnt_a[k] - k
  else:
    ans += cnt_a[k]
    
print(ans)

Solution (Python):



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

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

cnt = 0

for keys, vals in dict.items():
    if keys > vals:
        cnt += vals
    elif keys < vals:
        cnt += vals - keys

print(cnt)

Solution (Python):
from collections import*;n,*a=map(int,open(0).read().split());print(sum(v-k*(v>=k)for k,v in Counter(a).items()))

Solution (Python):
from collections import Counter
n=int(input())
ans=0
for i in Counter(list(map(int,input().split()))).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 MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n = II()
l = list(Counter(LI()).items())
ans = 0
for num in l:
    if num[0] < num[1]:
        ans += num[1]-num[0]
    elif num[0] > num[1]:
        ans += num[1]
    else:  
        pass
print(ans)

Solution (Python):
def ecount(X):
  c,ans=1,[[],[]]
  for i in range(len(X)-1):
    if X[i]==X[i+1]:c+=1
    else:
      ans[1].append(c);c=1;ans[0].append(X[i])
  ans[1].append(c)
  ans[0].append(X[-1])
  return ans
n=int(input())
a=ecount(sorted(list(map(int,input().split()))))
ans=0
for i in range(len(a[0])):
  if a[0][i]<=a[1][i]:ans+=a[1][i]-a[0][i]
  else:ans+=a[1][i]
print(ans)

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

dict = {}
for i in range(N):
    if a_n[i] in dict:
        dict[a_n[i]] += 1
    else:
        dict[a_n[i]] = 1

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
ctr=1
ln=[]
for i in range(n-1):
    if a[i]==a[i+1]:
        ctr+=1
    elif a[i]!=a[i+1]:
        ln.append([a[i],ctr])
        ctr=1
ln.append([a[n-1],ctr])
ans=0
for k in range(len(ln)):
    if ln[k][0]>ln[k][1]:
        ans+=ln[k][1]
    else:
        ans+=ln[k][1]-ln[k][0]
print(ans)

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

a.sort()
a.append(a[-1] + 1)

c = 0
m = 0

for i in range(0, n):
    c += 1
    if a[i] != a[i + 1]:
        if c < a[i]:
            m += c
        else:
            m += c - a[i]
        c = 0

print(m)

Solution (Python):
from collections import Counter
N = int(input())
an = list(map(int,input().split()))
at = tuple(Counter(an).items())
ans = 0
for a in at:
    if a[0] > a[1]:
        ans += a[1]
    elif a[0] < a[1]:
        ans += (a[1] - a[0])
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()
N=ni()
A=na()
A.sort()
dic={}
ans=0
for i in A:
    if(i in dic):
        dic[i]+=1
    else:
        dic[i]=1
for key, value in dic.items():
    if(key==value):
        continue
    elif(key>value):
        ans+=value
    else:
        ans+=value-key


print(ans)

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

from collections import Counter
counter = Counter(an)

c = 0
for a, n in counter.most_common():
    if n > a:
        c += (n-a)
    elif n < a:
        c += n
print(c)

Solution (Python):


def io_generator():
	return input()



def main(io):
	n=int(io())
	l=list(map(int, io().split()))
	di={}
	for i in l:
		try:
			di[i] = di[i]+1
		except:
			di[i] = 1
	
	c=0
	for k in di.keys():
		c += di[k] if di[k] < k else di[k] - k
	
	return c



if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

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

dict = {}
for a in A:
  if(a in dict): dict[a] += 1
  else: dict[a] = 1

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