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 = Counter([int(i) for i in input().split()])
total = 0

for num, cnt in dict(A).items():
    total += cnt if cnt-num < 0 else cnt-num
print(total)

Solution (Python):
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

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

ans = 0
for i in cnt:
    if i[0] < i[1]:
        ans += i[1] - i[0]
    elif i[0] == i[1]:
        continue
    else:
        ans += i[1]
print(ans)

Solution (Python):
from collections import Counter 

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

    ans = 0

    count_dict = Counter(num_list)

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

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n = int(input())
    numbers = sorted(list(map(int, input().split())))
    now = numbers[0]
    count = 0
    answer = 0
    for i in range(n):
        if now == numbers[i] and not i == n - 1:
            count += 1
        elif now < numbers[i] or i == n - 1:
            if i == n - 1:
                count += 1
            if count > now:
                answer += count - now
            elif now > count:
                answer += count
            now = numbers[i]
            count = 1
    print(answer)


if __name__ == '__main__':
    main()

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

Solution (Python):
from collections import Counter

_ = input()
a = list(map(int, input().split()))
counter = Counter(a)

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

print(ans)

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

n = len(a)
a.sort()
a.append(0)
ans = 0
i = 0

while i < n:
    cnt = 1
    while a[i] == a[i+1]:
        cnt += 1
        i += 1
    if cnt >= a[i]:
        ans += cnt - a[i]
    else:
        ans += cnt
    i += 1
print(ans)

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

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

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

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

Solution (Python):
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
c = Counter(A)
print(sum(v - k if k <= v else v for k, v in c.items()))

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

Solution (Python):
from collections import Counter

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    counter = Counter(A)
    ret = 0
    for k,v in counter.items():
        ret += v-k if v-k>=0 else v
        
    print(ret)
    
solve()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
a2=sorted(a)
now=a2[0]
ren=1
for i in range(1,n):
    if now!=a2[i]:
        if ren<now:
            ans+=ren
        elif now<ren:
            ans+=(ren-now)
        now=a2[i]
        ren=1
        continue
    ren+=1
if ren<now:
    ans+=ren
elif now<ren:
    ans+=(ren-now)
print(ans)

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

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

print(ans)

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

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

ans = 0
for i in d:
	if i<=d[i]:
		ans += d[i]-i
	else:
		ans += d[i]
print(ans)

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

from collections import defaultdict
d = defaultdict(int)

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

ans = 0
for t in set(a):
  cnt = d[t]

  if t > cnt:
    ans += cnt
  else:
    ans += (cnt - t)

print(ans)

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

n = len(a)
a.sort()
a.append(0)
ans = 0
i = 0
while i < n:
    cnt = 1
    while a[i] == a[i+1]:
        cnt += 1
        i += 1
    if cnt >= a[i]:
        ans += cnt - a[i]
    else:
        ans += cnt
    i += 1
print(ans)

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

a.sort()
cnt = 1
ans = 0
for i in range(len(a)-1):
    if a[i] == a[i+1]:
        cnt += 1
        continue

    if cnt >= a[i]:
        ans += cnt - a[i]
    else:
        ans += cnt
    cnt = 1
if cnt >= a[-1]:
    ans += cnt - a[-1]
else:
    ans += cnt
print(ans)

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

b = [0 for _ in range(n+1)]

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

for i in range(n+1):
    if b[i] > i: ans += b[i] - i
    if b[i] < i: ans += b[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):
n = int(input())
a = list(map(int, input().split()))

from collections import defaultdict
d = defaultdict(int)

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

ans=0
for num,cnt in d.items():
    if num > cnt:
        ans+=cnt
    else:
        ans+=cnt-num
print(ans)

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

arr.sort()
arr.reverse()

stack = []
ans = 0
while(True):
    if len(arr) == 0:
        if stack[-1] > len(stack):
            ans += len(stack)
        else:
            ans += (len(stack) - stack[-1])
        break
    tmp = arr.pop(-1)
    if len(stack) == 0:
        stack.append(tmp)
    elif stack[-1] == tmp:
        stack.append(tmp)
    else:
        if stack[-1] == len(stack):
            pass
        elif stack[-1] > len(stack):
            ans += len(stack)
        else:
            ans += (len(stack) - stack[-1])
        stack = []
        stack.append(tmp)

print(ans)

Solution (Python):
from collections import defaultdict
d = defaultdict(int)

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

for i in li:
  d[i] += 1
  
ans = 0  

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

Solution (Python):
import collections

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

a_count=collections.Counter(a)
count=0
for key ,atai in a_count.items():
    if key<=atai:
        count+=key
    
print(n-count)

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A.sort()
from collections import Counter
A=Counter(A)
ret=0
for i in A.most_common():
  if i[0]>i[1]:
    ret+=i[1]
  else:
    ret+=i[1]-i[0]
print(ret)

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


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

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

Solution (Python):
from itertools import groupby

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

ans = 0
for num, b in groupby(A):
    count = len(list(b))
    if num > count:
        ans += count
    elif num < count:
        ans += count - num

print(ans)

Solution (Python):
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
ad = Counter(a)
cnt = 0
i = list(ad.keys())
v = list(ad.values())
for x in range(0, len(i)):
    if int(i[x]) <= int(v[x]):
        cnt += int(v[x]) - int(i[x])
    else:
        cnt += int(v[x])
print(cnt)

Solution (Python):
import collections

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

count = 0

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

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
ans = 0
x = dict()
for i in range(N):
    if a[i] in x:
        x[a[i]] += 1
    else:
        x[a[i]] = 1
for idx in x:
    b = x[idx] - idx
    if b<0:
        ans += x[idx]
    else:
        ans += b 
print(ans)

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]
import collections
c = collections.Counter(a)
li = list(c.values())
lia = list(c.keys())
ans = 0
for i in range(len(li)) :
    if li[i] != lia[i] :
        if li[i] > lia[i] :
            ans += li[i] - lia[i]
        else :
            ans += li[i]
print(ans)

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

cDic = {}
for i in nList:
  if not(i in cDic):
    cDic[i] = 1
  else:
    cDic[i] += 1

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

print(count)

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

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

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

NA = set(A)
d = {x:0 for x in NA}

for i in range(N):
    d[A[i]] += 1

counter = 0
for p in d:
    if p > d[p]:
        counter += d[p]
    else:
        counter += d[p]-p

print(counter)

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





for i in a_counter:
    
    
    if i != a_counter[i]:
        if i < a_counter[i]:
            answer += a_counter[i] - i
        else:
            answer += a_counter[i]

print(answer)

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

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
D=[0]*(10**5+1)
ans=0
for i in A:
  if i > 10**5:
    ans+=1
  else:
    D[i]+=1

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

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
numberdict = dict()
for i in range(N):
    if A[i] in numberdict:
        numberdict[A[i]] += 1
    else:
        numberdict[A[i]] = 1
ans = 0
for j in numberdict.keys():
    if numberdict[j] >= j:
        ans += numberdict[j] - j
    else:
        ans += numberdict[j]
print(ans)

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

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

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

dic1 = dict()

for i in lst1:
    if i in dic1:
        dic1[i] += 1
    else:
        dic1[i] = 1

ans = 0

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

print(ans)

Solution (Python):
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return












from fractions import gcd












from queue import Queue




from collections import Counter




















n = int(input().strip())
s = list(map(int, input().strip().split()))
Map = Counter()
for i in range(n):
    Map[s[i]] += 1

cnt = 0
for value, number in Map.items():
    if number > value:
        cnt += number - value
    elif number == value:
        pass
    else:  
        cnt += number
print(cnt)

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

def main():
    N = INT()
    A = LIST()
    d = Counter()
    d.update(A)
    ans = 0
    for k, v in d.items():
        if k < v:
            ans += v - k
        if k > v:
            ans += v
        

    print(ans)
if __name__ == "__main__":
    main()

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

Solution (Python):
from collections import defaultdict
n = int(input())
nums = [int(i) for i in input().split()]

num_freq = defaultdict(int)
for num in nums:
    num_freq[num] += 1

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

print(ans)

Solution (Python):
import collections

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

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

Solution (Python):
import sys
from collections import Counter


input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    C = Counter(A)

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


    
    

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
dic = {}
count = 0

for i in range(n):
  dic.setdefault(l[i],0)
  dic[l[i]] += 1

for x,y in dic.items():
  if x <= y:
    count += y - x
  else:
    count += y
print(count)

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

cnt = {}

for i in range(N):
    cnt.setdefault(a[i], 0)
    cnt[a[i]] += 1

ans = 0

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

print(ans)

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

Solution (Python):
import collections

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

Solution (Python):
import sys

if sys.platform =='ios':
	sys.stdin=open('input_file.txt')
	

import itertools
n=int(input())
aa=list(map(int, input().strip().split()))
am={}
for a in aa:
	t=am.get(a, 0)
	am[a]=t+1

ans=0
for ak, av in am.items():
	if ak <= av:
		ans += av-ak
	else:
		ans += av
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 ai in d:
  if d[ai] - ai >= 0:
    ans += d[ai] - ai
  else:
    ans += d[ai]
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
d={}
l=[]
for i in range(n):
    try:
        d[a[i]]+=1
    except:
        d[a[i]]=1
        l.append(a[i])

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

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


d = {}


for i in range(N):
    if A[i] in d:
        d[A[i]] = d[A[i]] + 1
    else:
        d[A[i]] = 1

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

print(ans)

Solution (Python):
n = int(input())
arr = []
out = {}

input = input().split(" ")
for i in input:
	arr.append(int(i))
	
	if out.get(arr[-1], False):
		out[arr[-1]] += 1
	else:
		out[arr[-1]] = 1

count = 0
for key in out:
	if key > out[key]:
		count += out[key]
	else:
		count += out[key] - key

print(count)

Solution (Python):
from collections import defaultdict

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


dd=defaultdict(int)
ans=0
for a in A:
    dd[a]+=1

for k,v in dd.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()))
A=collections.Counter(A)
print(sum([A[i] if A[i]<i else A[i]-i if A[i]>i else 0 for i in A]))

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

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())))
b=set()
ans=0
d={}
cnt=0
for i in range(n):
    if i!=0 and a[i]!=a[i-1]:
        d[a[i-1]]=cnt
        cnt=0
    cnt+=1
    if i==n-1:
        x=a.count(a[i])
        d[a[i]]=x
for i in d.keys():
    if d[i]>=i:
        ans+=d[i]-i
    else:
        ans+=d[i]
print(ans)

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

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

result = {}

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

for i in result.keys():
  if result[i] > i:
    count += abs(i-result[i])
  elif result[i] < i:
    count += result[i]

  
print(count)

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

li = {}
for i in range(n):
    if a[i] in li:
        li[a[i]] += 1
    else:
        li[a[i]] = 1

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

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

Solution (Python):

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
ans = 0
for it in c.items():
    if it[0] <= it[1]:
        ans += (it[1]-it[0])
    else:
        ans += it[1]
print (ans)

Solution (Python):
import collections
n = int(input())
dat = list(map(int, input().split()))
c = collections.Counter(dat)
res = 0
for key in c:
    if c[key] < key:
        res += c[key]
    else:
        res += c[key] - key
print(res)

Solution (Python):
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
counter = Counter(a)
cnt = 0
for k, v in counter.items():
  cnt += v if k > v else v - k
print(cnt)

Solution (Python):
import sys
input = sys.stdin.readline
N=int(input())
a=list(map(int,input().split()))
from collections import Counter
d=Counter(a)
ans=0
for key,val in d.items():
    if key>val:
        ans+=val
    elif key<val:
        ans+=val-key
print(ans)

Solution (Python):

N = int(input())
import collections

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

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

print(count)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A = sorted(Counter(A).items(), key=lambda x:x[0])
cnt = 0
for k, v in A:
  if k != v:
    if k < v:
      cnt += (v-k)
    else:
      cnt += v
print(cnt)

Solution (Python):

import sys
from collections import Counter

def solve(N: int, a: "List[int]"):
    counter = Counter(a)
    answer = 0
    for key,value in counter.items():
        if key >value:
            answer += value
        else:
            answer += value-key
    print(answer)
    return

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

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

c = collections.Counter(a)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
d = dict()
for n in a:
    d[n] = d.get(n, 0) + 1

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

print(ans)

Solution (Python):

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
ans = 0
for c in counter.items():
    d = c[1]-c[0]
    if  d > 0:
        ans += d
    elif d < 0:
        ans += c[1]
print(ans)

Solution (Python):
import collections

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

c = collections.Counter(a)

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

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

ans = 0
keys = list(h.keys())
for i in range(len(keys)):
    k = keys[i]
    if k < h[k]:
        ans += h[k] - k
    elif k > h[k]:
        ans += h[k]
print(ans)

Solution (Python):
import collections

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

c = collections.Counter(a)

itms=c.items()
cnt=0
for key,value in itms:
    if key<value:
        cnt+=value-key
    elif key==value:
        continue
    else:
        cnt+=value

print(cnt)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = set(a)
x = {str(i):0 for i in b}
for i in a:
    x[str(i)] += 1
ans = 0
for i,j in x.items():
    if j < int(i):
        ans += j
    else:
        ans += j - int(i)
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
count = 0
x = 0
tmp_count = 0
for i in a:
    if i != x:
        if tmp_count < x:
            count += tmp_count
        else:
            count += tmp_count - x
        tmp_count = 1
        x = i
    else:
        tmp_count += 1
if tmp_count < x:
    count += tmp_count
else:
    count += tmp_count - x
print(count)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
d = {}

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

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

Solution (Python):
from collections import defaultdict


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

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

for key, count in count_dic.items():
    if count < key:
        ans += count

    else:
        ans += count - key

print(ans)

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

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

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    num2freq = collections.defaultdict(int)
    for a in A:
        num2freq[a] += 1
    cnt = 0
    for key, val in num2freq.items():
        if key > val:
            cnt += val
        else:
            cnt += (val - key)
    print(cnt)

main()

Solution (Python):
from collections import Counter
N=int(input())
L=list(map(int,input().split()))
C=Counter(L)
ANS=0
for k,v in C.most_common():
  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.sort()
nums=[0]*(10**5+1)
counter=0
for i in range(N):
  if a[i]>10**5:
    counter+=1
  else:
    nums[a[i]]+=1
    
for i in range(10**5+1):
  if nums[i]>i:
    counter+=nums[i]-i
  elif nums[i]<i:
    counter+=nums[i]
print(counter)

Solution (Python):
import sys
from collections import Counter
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(a_ls)
res = 0
for k, v in ct.items():
    if v > k:
        res += v - k
    if v < k:
        res += v
print(res)

Solution (Python):
import sys
from collections import Counter

n, *a = map(int, sys.stdin.read().split())

def main():
    res = 0
    for v, c in Counter(a).items():
        if c < v:
            res += c
        elif c > v:
            res += c - v
    return res

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

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

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

print(ans)

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

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

Solution (Python):
from collections import Counter
n = int(input())
a = [int(el) for el in input().split(' ')]

ans = 0
b = Counter(a)
 
for key, value in b.most_common():
	if value < key:
		ans += value
	if value > key:
		ans += value - key
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
a = [int(x) for x in input().split()]
import collections
c = collections.Counter(a)
ans = 0
for i in c:
    d = c[i] - i
    if d < 0:
        ans += c[i]
    else:
        ans += d
print(ans)

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

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

import collections
c = collections.Counter(a)
ans=0

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

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

D={}
for i in range(n):
      if A[i] in D:
            D[A[i]]+=1
      else:
            D[A[i]]=1

ans=0
for i in D:
      if i>D[i]:
            ans+=D[i]
      else:
            ans+=D[i]-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 in c.items():
    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()))

import collections

ac = collections.Counter(a)
common = ac.most_common()

operation_count = 0
for num, num_count in common:
  if num < num_count:
    operation_count += num_count - num
  elif num_count < num:
    operation_count += num_count

print(operation_count)