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

Solution (Python):

import sys
import collections

readline = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, readline().split()))
    countA = collections.Counter(A)
    ans = 0
    for c in countA.items():
        if c[1] >= int(c[0]):
            ans += c[1] - c[0]
        else:
            ans += c[1]

    print(ans)    


if __name__ == "__main__":
    main()

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

Solution (Python):
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
count = dict(Counter(a))
for i in count:
    j = count[i]
    if i > j:
        ans += j
    elif i==j:
        continue
    else:
        ans += j-i
print(ans)

Solution (Python):
import io
from collections import Counter

data=int(input())
num=list(map(int,input().split()))

dic=Counter(num)
counter=0
for k,v in dic.items():
  if k<v:
    counter+=v-k
  elif v<k:
    counter+=v
print(counter)

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

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    from collections import Counter

    counter = Counter(a)
    ans = 0

    for num, cnt in counter.items():
        if cnt > num:
            ans += (cnt-num)
        if cnt < num:
            ans += cnt

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import collections

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


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

print(ans)

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

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

Solution (Python):

import sys
import math
import random

sys.setrecursionlimit(100000)

br=dict()

n=int(input())
ar=list(map(int, input().split()))
cr=set(ar)

for i in range(n):
    br[ar[i]]=0
for i in range(n):
    br[ar[i]]=br[ar[i]]+1

ans=0
for xd in cr:
    times = br[xd]
    if(times < xd):
        ans = ans + times
    else:
        ans = ans + times-xd

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()
arr=limii()

mat=Counter(arr)
ans=0
for i,j in mat.items():
    if i<=j:
        ans+=j-i
    else:
        ans+=j
print(ans)

Solution (Python):
from collections import Counter
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    ans = 0
    for k,v in c.items():
        if v<k:
            ans += v
        else:
            ans += v-k
    return ans
print(solve())

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

Solution (Python):
def resolve():
    N = int(input())
    A = list(map(int, input().split(" ")))
    d = {0: 0}
    for a in A:
        if a in d:
            d[a] += 1
        else:
            d[a] = 1
    cnt = 0
    for i in d.keys():
        if d[i] >= i:
            cnt += d[i] - i
        else:
            cnt += d[i]
    print(cnt)

if '__main__' == __name__:
    resolve()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
seta=set(a)
d=dict([[x,0] for x in seta])
for i in range(len(a)):
  d[a[i]]+=1
seta=set(a)
ans=0
for ai in seta:
  if d[ai]==ai:
    pass
  elif d[ai]<ai:
    ans+=d[ai]
  else:
    ans+=d[ai]-ai
print(ans)

Solution (Python):


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


debug=0

def pront(*n):
    if debug==1:
        print(n)


X={}
for i in A:
    if i in X:
        X[i]+=1
    else:
        X[i]=1

        x=0
for i in X.items():
    pront(i)
    if i[0]>i[1]:
        x+=i[1]
    else:
        x+=i[1]-i[0]
        
print(x)

Solution (Python):
from collections import defaultdict
d = defaultdict(int)
N = int(input())
a = list(map(int, input().split()))
for x in a:
    d[x] += 1
ans = 0
for k in d:
    if d[k] < k:
        ans += d[k]
    else:
        ans += d[k]-k
print(ans)

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

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

cnt = [[k, v] for k, v in cnt.items()]
cnt.sort(reverse=True)
ans = 0
for k, v in cnt:
    
    if k <= v:
        
        ans += v - k
    else:
        
        ans += v

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 - i
    else:
        ans += j
print(ans)

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

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

for i in range(len(a)):
    tmp = a[i]
    if tmp not in d:
        d[tmp] = 0
    d[tmp] += 1

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

print(ans)

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

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

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

Solution (Python):



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

count = 0
for i in set(a):
	if (i > length):
		continue
	if(i <= a.count(i)):
		count += i
print(length - count)

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():
        res += c if c < v else c - v
    print(res)

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 a in set(A):
  ans += [C[a], C[a] - a][C[a] >= a]
print(ans)

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

Solution (Python):
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
dic = defaultdict(int)
for i in range(n):
    dic[a[i]] += 1
ans = 0
for k, v in dic.items():
    if k < v:
        ans += v - k
    elif v < k:
        ans += v

print(ans)

Solution (Python):
import collections

N = int(input())
a = [int(i) for i in input().split()]
count = 0
b = collections.Counter(a)
for i in b:
    if int(i) < b[i]:
        count += (b[i] - int(i))
    elif(int(i) > b[i]):
        count += b[i]
print(count)

Solution (Python):
from sys import stdin 
n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
a = sorted(a)
t = 1
c = 0
answer = 0
for i in range(n):
    if a[i] == t:
        c += 1
    else:
        if c > t:
            answer += c-t
        elif c < t:
            answer += c
        c = 1
        t = a[i]
if c > t:
    answer += c-t
elif c < t:
    answer += c
print(answer)

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

for a in A:
  if a > n:ans += 1
  else:backet[a-1] += 1

for i,b in enumerate(backet):
  if b >= i+1:
    ans += b-i-1
  else:
    ans += b
print(ans)

Solution (Python):
n=int(input())
from collections import Counter as co
var=co(list(map(int,input().split()))).items()
ans=0
for k,v in var:
    if k<=v:ans+=(v-k)
    else:ans+=v
print(ans)

Solution (Python):


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n = int(input())
    dic = {}
    A = readInts()
    
    cnt = 0
    for i in range(n):
        
        if A[i] in dic:
            if dic[A[i]] == A[i]:
                
                cnt += 1
            else:
                
                dic[A[i]] += 1
        else:
            
            dic[A[i]] = 1
    
    for k,v in dic.items():
        if k != v:
            cnt += v
    print(cnt)



if __name__ == '__main__':
  main()

Solution (Python):

from collections import defaultdict
N = int(input())
a = list(map(int, input().split()))


d = defaultdict(list)
for i in range(1, N+1):
    d[a[i-1]].append(a[i-1])

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

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

Solution (Python):
from collections import Counter
n, *A = map(int, open(0).read().split())
counter = Counter(A)

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

Solution (Python):
import math

line1 = int(input())
line2 = str(input()).split(" ")
for index in range(len(line2)):
    line2[index] = int(line2[index])

newList = []
counter = dict()
newLength = 0
for element in line2:
    try:
        counter[element] += 1
    except:
        counter[element] = 1
    if (counter[element] == element):
        newLength += element

print(line1 - newLength)

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

Solution (Python):
N = int(input())
arr = list(map(int, input().split()))
a = dict()
for i in arr:
    if i in a.keys():
        a[i] += 1
    else:
        a[i] = 1
ans = 0
for i in a.keys():
    if a[i] < i:
        ans += a[i]
    elif a[i] > i:
        ans += a[i] - i
print(ans)

Solution (Python):
from collections import defaultdict
dic = defaultdict(int)
n = int(input())
ns = map(int, input().split())
for i in ns:
    dic[i] += 1
result = 0
for key, value in dic.items():
    if key < value:
        result += value - key
    elif key > value:
        result += value
print(result)

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

d = {}
for i in range(0,N):
    e = seq[i]
    if e not in d.keys():
        d[e] = 1
    else:
        d[e] += 1

r = 0
for k in d.keys():
    v = d[k]
    if (v < k):
        r += v
    else:
        r += v-k

print(r)

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

if len(seq) == 1:
  if seq[0] == 1:
    print("0")
  else:
    print("1")
else:
  total = 0
  counts = {}
  for x in seq:
    if x not in counts:
      counts[x] = 1
    else:
      counts[x] += 1

  for key,val in counts.items():
    if val < key:
      total += val
    else:
      total += abs(key-val)
  print(total)

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

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

aa = collections.Counter(a)
ans = 0
for i in aa:
    if i != aa[i]:
        if aa[i] < i:
            ans += aa[i]
        else:
            ans += aa[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[0]>i[1]:
        ans += i[1]
    elif i[0]<i[1]:
        ans += i[1]-i[0]

print(ans)

Solution (Python):






def main():
    N = int(input())
    a = list(map(int, input().split()))
    
    num_cnt = {}
    for num in a:
        if num in num_cnt:
            num_cnt[num] += 1
        else:
            num_cnt[num] = 1
    
    ans = 0
    for num, cnt in num_cnt.items():
        if cnt >= num:
            ans += cnt - num
        else:
            ans += cnt

    return ans


print(main())

Solution (Python):
url = "https://atcoder.jp/contests/abc082/tasks/arc087_a"
import copy
def main():
    n = int(input())
    li = list(map(int, input().split()))
    inds = {}
    ans = 0
    for i in range(len(li)):
        inds.setdefault(li[i], 0)
        inds[li[i]] += 1
    for k, v in inds.items():
        if k == v:
            pass
        elif k > v:
            ans += v
        elif k < v:
            ans += v - k
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n = int(input())
list_A = list(map(int, input().split()))
l = Counter(list_A)
ans = 0
for s, i in l.items():
    if i >= s:
        ans += i - s
    else:
        ans += i

print(ans)

Solution (Python):
n = int(input())
list_A = list(map(int, input().split()))
set_a = list(set(list_A))
dic_A = dict()

for i in range(len(set_a)):
    j = str(set_a[i])
    dic_A[j] = 0

for i in list_A:
    j = str(i)
    dic_A[j] += 1
ans = 0
for s, i in dic_A.items():
    c = int(s)
    if i >= c:
        ans += i - c
    else:
        ans += i

print(ans)

Solution (Python):
from collections import defaultdict

if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    d = defaultdict(int)
    for aa in a:
        d[aa] += 1

    ans = 0
    for dd in d:
        if dd < d[dd]:
            ans += d[dd] - dd
        elif dd > d[dd]:
            ans += d[dd]

    print(ans)

Solution (Python):
from collections import Counter
n = int(input())
A = Counter([int(x) for x in input().split()])
res = 0
for a in A.keys():
    res += A[a] - a * (A[a] >= a)
print(res)

Solution (Python):
url = "https://atcoder.jp/contests/abc082/tasks/arc087_a"
import copy
def main():
    n = int(input())
    li = list(map(int, input().split()))
    inds = {}
    ans = 0
    for i in range(len(li)):
        inds.setdefault(li[i], 0)
        inds[li[i]] += 1
    for k, v in inds.items():
        if k == v:
            pass
        elif k > v:
            ans += v
        elif k < v:
            ans += v - k
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

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

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

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

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

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
num_cnt = {}
for i in range(N):
    if a[i] in num_cnt:
        num_cnt[a[i]] += 1
    else:
        num_cnt[a[i]] = 1
cnt = 0
for i, j in num_cnt.items():
    if j >= i:
        cnt += j - i
    else:
        cnt += j
print(cnt)

Solution (Python):

from collections import Counter
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, a: "List[int]"):
    ctr = Counter(a)
    print(sum(nn if n > nn else nn - n for n, nn in ctr.items()))


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_lst = [int(elem) for elem in input().split()]

c = collections.Counter(a_lst)
cnt = 0

for k in c.keys():
  if c[k] > k:
    cnt += c[k] - k
  elif c[k] < k:
    cnt += c[k]
print(cnt)

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

count = {}

for i in lst:
    if i in count.keys():
        count[i]+=1
    else:
        count[i]=1


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

Solution (Python):
import collections

n, *a = map(int, open(0).read().split())
c = collections.Counter(a)
cnt = 0
for s in c.keys():
    if s < c[s]:
        cnt += c[s] - s
    elif s > c[s]:
        cnt += c[s]
print(cnt)

Solution (Python):
import collections

n, *a = map(int, open(0).read().split())
c = collections.Counter(a)
cnt = 0
for s in c.keys():
    s_num = c[s]
    if s < s_num:
        cnt += s_num - s
    elif s > s_num:
        cnt += s_num
print(cnt)

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

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

Solution (Python):

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

ans = 0
c = collections.Counter(a)
for i in set(a):
    if i < c[i]:
        ans += c[i] - i
    elif i > c[i]:
        ans += c[i]
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
ans = 0
for x, y in d.items():
  ans += y if x > y else y - x
print(ans)

Solution (Python):

from collections import Counter
def inputlist(): return [int(j) for j in input().split()]

N = int(input())
a = inputlist()
c = Counter(a)
key = c.keys()
ans = 0
for i in key:
    if c[i] == i:
        continue
    if c[i] > i:
        ans += c[i]-i
    if c[i] < i:
        ans +=c[i]
print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
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
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(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()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
a.sort()
b = sorted(list(set(a)))
idx = 0
cnt = [0 for _ in range(len(b))]
for i in range(n):
    if a[i] != b[idx]:
        idx += 1
    cnt[idx] += 1
ans = 0
for i in range(len(b)):
    tmp = cnt[i] - b[i]
    if tmp < 0:
        tmp = cnt[i]
    ans += tmp
print(ans)

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

d = defaultdict(int)
for i in a:
    d[i] += 1

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

print(ans)

Solution (Python):
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    input()
    aa=LI()
    cc=Counter(aa)
    ans=0
    for a,c in cc.items():
        if a>c:ans+=c
        else:ans+=c-a
    print(ans)

main()

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

ans = 0
for a, c in A.items():
    if a < c:
        ans += c - a
    elif a > c:
        ans += c
print(ans)

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

cnt = {}
for i in range(n):
    if a[i] not in cnt:
        cnt[a[i]] = 1
    else:
        cnt[a[i]] += 1
ans = 0
for i in cnt:
    if i <= cnt[i]:
        ans += cnt[i] - i
    else:
        ans += cnt[i]
print(ans)

Solution (Python):

from collections import Counter
n, *a = map(int, open(0).read().split())
a = Counter(a).items()
ans = 0
for v,c in a:
	if v<=c: ans += c-v
	else: ans += c
print(ans)

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

Solution (Python):
import collections

N=int(input())
A=list(map(int,input().split()))
M=collections.Counter(A)
tmp=0
for i,j in M.items():
	if i>j:
		tmp+=j
	else:
		tmp+=(j-i)
print(tmp)

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

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

a=sorted(a)
base={}
count=0

for i in range(N):
    if a[i] not in base.keys():
        base[a[i]]=1
        if i>=1 and base[a[i-1]]<a[i-1]:
            count+=base[a[i-1]]
    else:
        if base[a[i]]>=a[i]:
            count+=1
        else:
            base[a[i]]+=1
if base[a[N-1]]<a[N-1]:
    count+=base[a[i]]
print(count)

Solution (Python):
from collections import Counter

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

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

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

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

print(ans)

Solution (Python):

a = int(input())
b = list(map(int,input().split()))
from collections import defaultdict
d = defaultdict(int)
for i in b:
    d[i]+=1
ret = 0
for k,v in d.items():
    if v>=k:
        ret+=(v-k)
    else:
        ret+=v
print(ret)

Solution (Python):
from functools import reduce
from fractions import gcd
from collections import defaultdict
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    
    res = 0
    for k in d.keys():
        if d[k] >= k:
            res += d[k] - k
        else:
            res += d[k]
    
    print(res)
    
    


if __name__ == '__main__':
    main()

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

C = Counter(A)

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

print(ans)

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

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

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

from collections import Counter

c = Counter(a)

ans = 0

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

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.append(-1)
n = 0
cnt = 0
ans = 0
for a in A:
    if a == n:
        cnt += 1
    else:
        if cnt >= n:
            ans += cnt - n
        else:
            ans += cnt
        n = a
        cnt = 1
print(ans)

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

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    AD = dict()
    for a in A:
        if a in AD: AD[a] += 1
        else: AD[a] = 1

    count = 0
    for key in AD:
        if AD[key] == key: continue
        elif AD[key] > key: count += AD[key] - key
        else: count += AD[key]
    print(count)

    return 0

if __name__ == "__main__":
    solve()

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


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
c = Counter(a)
res = 0
for key in c.keys():
    
    if c[key] >= key:
        res += c[key] - key
    else:
        res += c[key]
print(res)

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

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

from collections import Counter

Acnt = Counter(A)

ans = 0
for key,cnt in Acnt.items():
    if key == cnt:
        pass
    elif key < cnt:
        ans += cnt - key
    else:
        ans += cnt
    
print(ans)

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    d = defaultdict(lambda : 0)
    for i in a:
        d[i] += 1
    ans = 0
    for i in set(a):
        if d[i] < i:
            ans += d[i]
        else:
            ans += d[i]-i
    print(ans)
    return


if __name__ == "__main__":
    solve()