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
cnt=1
for i in range(n-1):
	if a[i]==a[i+1]:
		cnt+=1
	else:
		if cnt>=a[i]:
			x=cnt-a[i]
		else:
			x=10**10
		ans+=min(cnt,x)
		cnt=1
if cnt>=a[-1]:
	x=cnt-a[-1]
else:
	x=10**10
ans+=min(cnt,x)
print(ans)

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

d = dict()

for a in A:
    d[a] = d.get(a, 0) + 1

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

print(ans)

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

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

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

from collections import Counter
counter = Counter(a_list)

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

print(ans)

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

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

for i in range(N):
  if a[i] <= 10 ** 5:
    count[a[i]] += 1
    ans += 1
    if count[a[i]] == a[i]:
      ans -= a[i]
  else:
    ans += 1

print(ans)

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

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
data = sorted(data) + [0]

if N == 1 and data[0] == 1:
    print(0)

elif N == 1 and data[0] != 1:
    print(1)

else:
    ans = 0
    num = data[0]
    cnt = 0
    for i in range(N+1):
        if data[i] == num:
            cnt += 1
        else:
            if cnt < data[i-1]:
                ans += cnt
            else:
                ans += (cnt-data[i-1])
            cnt = 1
            num = data[i]
    print(ans)

Solution (Python):
from collections import Counter
N = int(input())
c = Counter([int(_) for _ in input().split()])
ans = 0
for a, b in c.items():
    if b < a:
        ans += b
    else:
        ans += b - a
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
c = Counter([int(s) for s in input().split()])
ans = 0
for k in c:
    if k < c[k]:
        ans += c[k] - k
    if k > c[k]:
        ans += c[k]
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
C = [0] * 100007
count = 0
total = 0

for i in range(N):
    if A[i] < 100007:
        C[int(A[i])] += 1

for i in range(1, len(C)):
    count += C[i]
    if C[i] < i:
        total += C[i]
    if C[i] > i:
        total += C[i] - i

print(total + N - count)

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

print(total)

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

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

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

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

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

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

x = l[0]
y = 0
ans = 0
for i in range(n):
  if l[i] != x:
    if x < y:
      ans += y -x
    elif x > y:
      ans += y
    else:
      pass
    x = l[i]
    y = 1
  else:
    y += 1
else:
  if x < y:
      ans += y -x
  elif x > y:
    ans += y
  else:
    pass

print(ans)

Solution (Python):
from collections import Counter


n = int(input())
num_list = list(map(int, input().split()))
cnt = Counter(num_list)
print(sum([val-key if val>=key else val for key, val in cnt.items()]))

Solution (Python):
from collections import Counter

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

count = Counter(A)
ans = 0

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

print(ans)

Solution (Python):
import collections

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

for ai in set(a):
    if c[ai] < ai:
        ans += c[ai]
    else:
        ans += c[ai] - ai

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
d = {}
count = 0
for i in range(n):
    if not a[i] in d.keys() and (n-count)>=a[i]:
        ac = a.count(a[i])
        d.update({a[i]:ac})
        count += ac
ans = 0
for i in sorted(d.keys()):
    if i <= d[i]:
        ans += d[i]-i
    else:
        ans += d[i]

print(ans + n-count)

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
ret = 0
for k,v in d.items():
    if k > v:
        ret += v
    elif k < v:
        ret += (v-k)
print(ret)

Solution (Python):
import collections
N = int(input())
X = list(map(int,input().split()))
clst = collections.Counter(X)
clst = clst.most_common()
cnt = 0
for i in range(len(clst)):
	if clst[i][0] > clst[i][1]:
		cnt += clst[i][1]
	else:
		cnt += clst[i][1]-clst[i][0]

print(cnt)

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

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

ans = 0
for key in d.keys():
    if d[key] < key:
        ans += d[key]
    elif d[key] == key:
        continue
    else:
        ans += (d[key]-key)
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
can = []
for i in range(n):
  now = a[i]
  try:
    if now == can[-1][0]:
      can[-1][1] += 1
    else:
      can.append([now,1])
  except:
    
    can.append([now,1])
l = len(can)
ans = 0
for j in range(l):
  if can[j][1] >= can[j][0]:
    ans += can[j][1] - can[j][0]
  else:
    ans += can[j][1]

print(ans)

Solution (Python):
from collections import defaultdict

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

elems = defaultdict(int)
for elem_i in A:
    elems[elem_i] += 1




ans = 0
for num_a, freq in elems.items():
    diff = freq - num_a
    if diff >= 0:
        ans += diff
    else:
        ans += freq

print(ans)

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

Solution (Python):
from collections import*
_,*l=map(int,open(0).read().split())
a=0
c=Counter(l)
for i in list(set(l)):
	j=c[i]
	a+=j-i*(i<=j)
print(a)

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

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

Solution (Python):
from collections import Counter

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

    a = Counter(A)

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

    print(cnt)

main()

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

d = dict()
for i in a:
    d[i] = d.get(i, 0) + 1


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

print(ans)

Solution (Python):

from collections import Counter

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

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

Solution (Python):

import sys, math, fractions, itertools, collections


def solve(N: int, a: "List[int]"):
    c = collections.Counter(a)
    d = dict(c.items())
    counter = 0
    for k in c.keys():
        if k == 1:
            counter += d[k] - 1
            continue
        counter += d[k] - (d[k] // k) * k
    print(counter)
    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):
n = int(input())
li = list(map(int, input().split()))
num = list(set(li))
num.sort()
ans = 0
sums = 0
for index, i in enumerate(num):
    if i > n - sums:
        ans += n-sums
        break
    count = li.count(i) 
    ans += count
    if count >= i:
        ans -= i
    sums += count
print(ans)

Solution (Python):
import collections

N = map(int, input().split())
S = list(map(int, input().split()))
S_unique_count = list(collections.Counter(S).items())

ans = 0
for i in range(len(S_unique_count)):
    if S_unique_count[i][0] == S_unique_count[i][1]:
        pass
    elif S_unique_count[i][0] > S_unique_count[i][1]:
        ans += S_unique_count[i][1]
    elif S_unique_count[i][0] < S_unique_count[i][1]:
        ans += S_unique_count[i][1] - S_unique_count[i][0]

print(ans)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
dic = {}
ckd = []
ans = 0

for i in range(N):
  try:
    dic[A[i]] += 1
  except KeyError:
    dic[A[i]] = 1
    
tpl = dic.items()
for i in tpl:
  if i[0] > i[1]:
    ans += i[1]
  else:
    ans += i[1] - i[0]
    
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
count1 = 1
ans = 0
i = 0
while i < n-1:
    if a[i] == a[i+1]:
        count1 = count1 + 1
    else:
        if count1 >= a[i]:
            ans = ans + count1 - a[i]
        else:
            ans = ans + count1
        count1 = 1
    i = i + 1
if count1 >= a[i]:
    ans = ans + count1 - a[i]
else:
    ans = ans + count1
print(ans)

Solution (Python):
import sys, collections

input=sys.stdin.readline

def main():
    n=int(input())
    a = [int(i) for i in input().split()]
    ac = collections.Counter(a)
    k = ac.keys()
    ans = 0
    for i in k:
        if i <= ac[i]:
            ans += ac[i] - i
        else:
            ans += ac[i]

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import bisect

N = int(input())
A = [int(zz) for zz in input().split()]
B = set(A)
A.sort()
ans = 0
for i in B:
    p = bisect.bisect_right(A, i) - bisect.bisect_left(A, i)
    if i > p:
        ans += p
    elif i < p:
        ans += p - i

print(ans)

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a2 = {}
for i in a:
    a2.setdefault(i, 0)
    a2[i] += 1
count = 0
for i, j in a2.items():
    if i > j:
        count += j
    else:
        count += j - i
print(count)

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

for num in nums:
  if num in dict.keys():
    dict[num] += 1
  else:
    dict[num] = 1
ans = 0
for key, value in dict.items():
  if int(key) == value:
    continue
  elif int(key) > value:
    ans += value
  else:
    ans += value - int(key)
print(ans)

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math






def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    a = inputList()
    
    tmp = {}
    for i in a:
        if i in tmp:
            tmp[i] += 1
        else:
            tmp[i] = 1
            
    ans = 0
    for k, v in tmp.items():
        if k != v:
            if k < v:
                ans += v-k
            else:
                ans += v
    
    print(ans)
            	
if __name__ == "__main__":
	main()

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: ans += v - k
    if k > v: ans += v
print(ans)

Solution (Python):
import collections

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

B = collections.Counter(A)

ans = 0
for key, value in B.items():
    if key == value:
        continue
    if key > value:
        ans += value
    if key < value:
        ans += value - key

print(ans)

Solution (Python):
import sys

def main():
	n = int(input())
	a = list(map(int,input().split()))
	a.sort()
	a = listtodict(a)
	cost=0
	for k,v in a.items():
		if(k!=v):
			cost += v if(v<k) else v-k
	print(cost)

def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Solution (Python):
import collections
n=int(input())
l=list(map(int,input().split()))
c=collections.Counter(l)
mc=c.most_common()
ans=0
for i in mc:
    if i[1]<i[0]:ans+=i[1]
    else: ans+=i[1]-i[0]
print(ans)

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

cnt=0
counterarr=[0 for _ in range(N)]
others=[]
for i in range(N):
    if a[i]-1<N:
        counterarr[a[i]-1]+=1
    else:
        others.append(a[i])
for i in range(N):
    shoudbe=i+1
    now=counterarr[i]
    if shoudbe>now:
        cnt+=now
    elif shoudbe<now:
        cnt+=now-shoudbe
cnt+=len(others)
print(cnt)

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

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

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

Solution (Python):



import sys

input = sys.stdin.readline

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

    A.sort()
    m = {}
    for i in range(N):
        if A[i] not in m:
            m[A[i]] = 1
        else:
            m[A[i]] += 1

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

    print(n)

main()

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

Solution (Python):
from collections import defaultdict
d = defaultdict(lambda : 0)
N = int(input())
A = list(input().split())
for a in A: d[a]+=1
cnt = 0
for key in d.keys():
    if d[key]<int(key): cnt+=d[key]
    elif d[key]>int(key): cnt+=(d[key]-int(key))
print(cnt)

Solution (Python):



from collections import Counter

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

b = Counter(a)
b = list(b.items())
ans = 0
for i,j in b:
    if j >= i:
        ans += j - i
    else:
        ans += j
print(ans)

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()


def summarize_list(l):
  sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res

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

  l=summarize_list(l)

  ans=0
  for x in l:
    if x[0]<=x[1]:
      ans+=x[1]-x[0]
    else:
      ans+=x[1]

  return ans


print(main())

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
adic = {}
for c in a:adic[c] = adic.get(c,0) + 1
g = 0
for k in adic.keys():
    if adic[k] > k:g += adic[k] - k
    elif adic[k] == k:pass
    else:g += adic[k]
print(g)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
now = [A[0], 1]
numberlist = []
for i in range(1, N):
	if now[0] == A[i]:
		now[1] += 1
	else:
		numberlist.append(now)
		now = [A[i], 1]
numberlist.append(now)
ans = 0
for i in range(0, len(numberlist)):
	if numberlist[i][1] < numberlist[i][0]:
		ans += numberlist[i][1]
	elif numberlist[i][0] < numberlist[i][1]:
		ans += numberlist[i][1] - numberlist[i][0]
print(ans)

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

b = defaultdict(int)
for i in range(n):
    b[a[i]] += 1

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

print(ans)

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

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

Solution (Python):
from collections import Counter
N = int(input())
a_lis = [int(_) for _ in input().split()]

count = 0

for key, value in Counter(a_lis).items():
    if int(value) - int(key) > 0:
        count += int(value) - int(key)
    elif int(value) - int(key) < 0:
        count += int(value)
    else:
        count += 0
print(count)

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

Solution (Python):
n=int(input())
a_list=list(map(int,input().split()))
D={}
for i in a_list:
    if i in D:
        D[i]+=1
    else:
        D[i]=1
ans=0
for i in D:
    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()))
a = sorted(a)
ans = 0
now = 0
cnt = 1
for i in range(1, n):
    if(a[i-1] != a[i]):
        if(cnt >= a[i-1]):
            ans += cnt - a[i-1]
        else:
            ans += cnt
        cnt = 1
    else:
        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()))
d={}
for i in a:
    d[i]=d.get(i,0)+1
print(sum(d[i]-i*(d[i]>=i)for i in d))

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

keys=list(dic.keys())
count=0

for i in range(len(keys)):
    if keys[i]<dic[keys[i]]:
        count+=dic[keys[i]]-keys[i]
    elif dic[keys[i]]<keys[i]:
        count+=dic[keys[i]]
    else:
        pass

print(count)

Solution (Python):

N = int(input())

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

dic = {}

for i in a:

    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

ans = 0

for i in dic:

    if i > dic[i]:
        ans += dic[i]

    else:
        ans += ( dic[i] - i )

print (ans)

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

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

Solution (Python):
import bisect
n = int(input())
a = [int(_) for _ in input().split()]
a.sort()

res = 0

for i in set(a):
    tmp = bisect.bisect_right(a,i)-bisect.bisect_left(a,i)
    if tmp < i:
        res += tmp
    else:
        res += tmp - i

print(res)

Solution (Python):
from collections import Counter

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

L = Counter(a)
R = L.most_common()

r = []
for i in range(len(R)):
    if R[i][0] == 1:
        r.append(abs(R[i][1] - R[i][0]))
    else:
        r.append(R[i][1] % R[i][0])

print(sum(r))

Solution (Python):
n = int(input())
a = [int(_) for _ in input().split()]
a.sort()
a.append(0)
cnt = 1
ans = 0
for i in range(n):
    if a[i+1] == a[i]:
        cnt += 1
    else:
        if cnt > a[i]:
            ans += cnt - a[i]
        elif cnt < a[i]:
            ans += cnt
        cnt = 1

print(ans)

Solution (Python):
from collections import defaultdict

N=int(input())

d = defaultdict(int)
for i in input().split():
    d[int(i)]+=1

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

print(ans)

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

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

Solution (Python):

import sys
input = sys.stdin.readline

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


if __name__ == "__main__":
    main()

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

Solution (Python):

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

ans = 0
a_as = {}

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

for x in a_as:
    if x > a_as[x]:
        ans += a_as[x]
    else:
        ans += abs(a_as[x]-x)
    
print(ans)

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

ans=0
for i in A.items():

    k=i[0]
    l=i[1]
    if k<l:
        ans+=l-k
    elif l<k:
        ans+=l

print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A.sort()
A+=[10**9+1]
ans,memo,counter=0,0,0
for a in A:
    if a!=memo:
        if memo>counter:ans+=counter
        memo,counter=a,0
    counter+=1
    if counter>memo:ans+=1
print(ans)

Solution (Python):
import collections

n = int(input())
a_list = [int(i) for i in input().split()]
mpCnt = collections.Counter(a_list)

count = 0
for k, v in mpCnt.items():
    if k == v:
        continue
    if k > v:
        count +=  v
    else:
        count += v - k       
print(count)

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

hash = {}

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

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


print(ans)

Solution (Python):
n = int(input())
num_list = sorted([ int(v) for v in input().split() ])


judge_list = []
count_list = []

for i in num_list:
    if judge_list == []:
        judge_list.append(i)
        count_list.append(1)
    else:
        if i != judge_list[-1] or judge_list ==[]:
            judge_list.append(i)
            count_list.append(1)
        else:
            count_list[-1] += 1
ans = 0
for i in range(len(judge_list)):
    if judge_list[i] > count_list[i]:
        ans += count_list[i]
    elif judge_list[i] < count_list[i]:
        ans += count_list[i] - judge_list[i]

print(ans)

Solution (Python):

import sys
import collections


def solve(N: int, A: "List[int]"):
    D = collections.defaultdict(int)
    for a in A:
        D[a] += 1

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

    print(res)
        




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

if __name__ == '__main__':
    main()

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

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

Solution (Python):
import collections

N = int(input())
a = list(map(int, input().split()))
a_s = collections.Counter(a) 
A = a_s.most_common()
count = 0

for i in range(len(A)):
    if int(A[i][1]) >= int(A[i][0]):
        count += int(A[i][1]) - int(A[i][0])
    else:
        count += int(A[i][1])

print(count)

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

from collections import defaultdict
d = defaultdict(int)

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

for i in d.keys():
    if d[i]-i>0:
        cnt += d[i]-i
    elif i == d[i]:
        pass
    else:
        cnt += d[i]
print(cnt)

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

n = 0
n_cnt = 0
ans = 0
for a in A + [0]:
	if a != n:
		ans += n_cnt if n_cnt < n else n_cnt - n
		n = a
		n_cnt = 1
	else:
		n_cnt += 1

print(ans)

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

for item in A.items():
    k = item[0]
    v = item[1]
    if k > v:
        res += v
    elif k < v:
        res += v-k
print(res)

Solution (Python):
from collections import Counter

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

cnt_li = dict(Counter(a))
ans = 0
for x, y in cnt_li.items():
    diff = x-y
    if diff <= 0:
        ans += abs(diff)
    else:
        ans += y
print(ans)

Solution (Python):
from collections import Counter

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

a_count = Counter(a)

ans = 0
for i in a_count:
    if int(i) > a_count[i]:
        ans += a_count[i]
    else:
        ans += a_count[i] - int(i)

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
la = {k:v for k,v in Counter(a).items()}
ans = 0
for k,v in la.items():
    if k != v:
        if k < v:
            ans += abs(k-v)
        else:
            ans += v
print(ans)

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

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

i=0
ans=0
while i!=len(a):
    x=a[i]
    x1=a.count(x)
    if (x>len(a)-i):
        ans=ans+len(a)-i
        break
    else:

        if x<x1:
            ans=ans+x1-x
        elif x>x1:
            ans=ans+x1
        else:
            pass
        i=i+x1
print(ans)

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

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

a.sort()


ans = 0
count = 0
keep = a[0]
for i in a+[0]:
    if i == keep:
        count +=1
    else:
        if count < keep:
            ans += count
            count = 1
            
        else:
            ans += count-keep
            count = 1
            
    keep = i

print (ans)

Solution (Python):
from collections import defaultdict

N=int(input())
A=list(map(int,input().split()))
C=defaultdict(int)
B=[]
for a in A:
    C[a]+=1
ans=0
for i,v in C.items():
    if i>v:
        ans+=v
    elif i<=v:
        ans+=v-i
print(ans)

Solution (Python):
from collections import Counter
N = int(input())


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

r = 0
for x, c in A.items():
    if x == c:
        continue
    elif x < c:
        r += c - x
    elif x > c:
        r += c
print(r)

Solution (Python):
from collections import defaultdict

def main():
    num = int(input())
    data = list(map(int, input().split()))
    dic = defaultdict(int)

    for ele in data:
        dic[ele] += 1

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

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
countlist = []
tmp = 0
for i in range(0, N):
	if A[i] != tmp:
		countlist.append([A[i], 0])
		tmp = A[i]
	countlist[-1][1] += 1
sum = 0
for i in range(0, len(countlist)):
	if countlist[i][1] < countlist[i][0]: sum += countlist[i][1]
	else: sum += countlist[i][1] - countlist[i][0]
print(sum)