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



Sample input:
4
3 3 3 3


Sample output:
1

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    n=int(input())
    a=Counter(map(int,input().split()))
    d=0
    for k,v in a.items():
        if k > v:
            d += v
        elif k < v:
            d += v-k
    print(d)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from collections import Counter

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

counter = Counter(A)
ans = 0
for value, count in counter.items():
    if count > value:
        ans += count - value
    elif count < value:
        ans += count

print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
A = collections.Counter(int(T) for T in input().split()).most_common()
Remove = 0
for T in range(0,len(A)):
    if A[T][0]>A[T][1]:
        Remove += A[T][1]
    elif A[T][0]<A[T][1]:
        Remove += A[T][1]-A[T][0]
print(Remove)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
n, *a = map(int, open(0).read().split())
c = Counter(a)
ans = 0
for k, v in c.items():
    ans += v - k if v >= k else v
print(ans)

Submission status: Accepted

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

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

K=0
for b in T:
    if T[b]<b:
        K+=T[b]
    elif b<T[b]:
        K+=T[b]-b
print(K)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
count = 0

B = [0]*100001

for i in range (0, N):
	if A[i] <= 100000:
		B[A[i]]+=1
	else:
		count+=1

for i in range (1, 100001):
	if B[i] < i:
		count+=B[i]
	if B[i] > i:
		count+=(B[i]-i)

print(count)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]

c = Counter(a)
ans = 0
for x in c:
    if c[x] < x:
        ans += c[x]
    else:
        ans += c[x] - x

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = Counter(list(map(int, input().split())))
S = 0
for k, v in A.items():
  if k<v:
    S += (v-k)
  elif k>v:
    S += v
print(S)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    from collections import Counter
    c = Counter(a)
    cnt = 0
    for i,j in c.items():
        if i == 1:
            cnt += max(j-1,0)
        else:
            cnt += j%i
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter


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

Submission status: Accepted

Solution code:
import collections


def main():
    N = int(input())
    A = list(map(int, input().split()))
    counter = collections.Counter(A)
    ans = 0
    for k, v in counter.items():
        if v > k:
            ans += v - k
        elif v < k:
            ans += v
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


def main():
    n = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A: d[a] += 1
    ans = 0
    for key in d:
        if d[key] < key:
            ans += d[key]
            continue
        ans += d[key] - key
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter
def main():
    N = int(input())
    A = list(input().split())
    C = Counter(A)
    ans = 0
    for k, v in C.items():
        if v >= int(k):
            ans += v - int(k)
        else:
            ans += v
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = [int(i) for i in input().split()]
b = collections.Counter(a)
ans =0
for i,n in b.items():
    if i > n:
        ans += n
    else:
        ans += abs(n-i)
print(ans)

Submission status: Accepted

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

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

total_cnt = 0
for k, v in dict.items():
    a_cnt = 0
    if k > v:
        a_cnt += v
    else:
        a_cnt += (v - k)
    total_cnt += a_cnt
print(total_cnt)

Submission status: Accepted

Solution code:
from collections import *
N = int(input())
C = Counter(list(map(int,input().split())))
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = (10**5+1)*[0]
ans = 0

for a in A:
  if a<=10**5:
    B[a]+=1
  else:
    ans+=1

for n in range(10**5):
  if B[n]<n:
    ans+=B[n]
  elif n<B[n]:
    ans+=B[n]-n

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
counter =dict(Counter(a))
c_key =list(counter.keys())
c_value =list(counter.values())
cnt = 0
sl = len(c_value)
for i in range(sl):
  if int(c_key[i]) <  c_value[i]:
      cnt += (c_value[i]- int(c_key[i]))
  elif int(c_key[i]) >  c_value[i]:
 	  cnt += c_value[i] 
print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
A = Counter(a)
c = 0
for k, v in A.items():
    if k < v:
        c += v - k
    elif k > v:
        c += v
print(c)

Submission status: Accepted

Solution code:
inputs = [input() for i in range(2)]
n = int(inputs[0])
a = map(lambda x: int(x), inputs[1].split(" "))

b = {}
for i in a:
  if i not in b:
    b[i] = 1
  else:
    b[i] += 1
count = 0
for k in b.keys():
  tmp = k - b[k]
  if tmp > 0:
    count += b[k]
  else:
    count += -tmp


print(count)

Submission status: Accepted

Solution code:
import numpy as np
def main():
  N = int(input())
  A = list(map(int, input().split()))
  dic = {}
  for i in range(N):
    if not A[i] in dic:
      dic[A[i]]=1
    else:
      dic[A[i]]+=1
  ans = 0
  for i, j in dic.items():
    if i < j:
      ans += j-i
    if j < i:
      ans += j
  print(ans)
  
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
from collections import Counter

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

num_removal = 0
for digit, count in Counter(a).items():
    if digit > count:
        num_removal += count
    else:
        num_removal += (count - digit)
print(num_removal)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[2]:


import collections


# In[15]:


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


# In[16]:


mycnt = collections.Counter(a)
ans = 0
for x,cnt in mycnt.items():
    if x > cnt:
        ans += cnt
    else:
        ans += cnt - x
print(ans)


# In[ ]:

Submission status: Accepted

Solution code:
N = input()

num = {}
for a in map(int, input().split()):
  if not a in num.keys(): num[a] = 1
  else: num[a] += 1

res = 0
for a, a_num in num.items():
  if a_num < a: res += a_num
  else: res += a_num - a
print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
A = zz()
dic = defaultdict(int)
for a in A:
    dic[a] += 1
ans = 0
for key in dic:
    if (dic[key] >= key):
        # kouho.append(dic[key]-key)
        ans += (dic[key]-key)
    else:
        ans += dic[key]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
c_value = list(c.values())
c_key = list(c.keys())
cnt = 0

for i in range(len(c_key)):
    if c_key[i] > c_value[i]:
        cnt += c_value[i]
    elif c_value[i] > c_key[i]:
        cnt += c_value[i]- c_key[i]
print(cnt)

Submission status: Accepted

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

a = [i for i in a.items() if i[0]!=i[1]]
ans = 0

for i, j in a:
    if i>j:
        ans += j
    else:
        ans += j-i

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    d = defaultdict(int)
    ans = 0
    for e in a:
        if d[e] < e:
            d[e] += 1
        else:
            ans += 1

    for e in d:
        if d[e] != e:
            ans += d[e]
    print(ans)
        
    

    
    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

2 3 4 4
3 4 4
2 3 4
2 3 4
2 4 4


"""

Submission status: Accepted

Solution code:
from collections import Counter


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

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
c = Counter(readInts())

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

ans = 0
for number, count in counter.items():
    if count < number:
        ans += count
    else:
        ans += count - number

print(ans)

Submission status: Accepted

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

dic = {}
for i in range(N):
    data = A[i]
    if data in dic:  dic[data] += 1
    else:  dic[data] = 1
        
ans = 0
for i in dic:
    if dic[i] > i:  ans += dic[i] - i
    elif dic[i] < i:  ans += dic[i]
print(ans)

Submission status: Accepted

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

a.sort()

import collections
c = collections.Counter(a)

ans = 0
for i in c.most_common():
    if i[0] <= i[1]:
        ans += i[1] - i[0]
    else:
        ans += i[1]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A_LI = sorted(map(int, input().split()))
a_dict = {}
ans = 0
pre = None
for a in A_LI:
    if a not in a_dict:
        if pre in a_dict:
            # 出揃った値について取り除く個数を求める
            if a_dict[pre] < pre:
                ans += a_dict[pre]
            else:
                ans += a_dict[pre] - pre
        pre = a
        a_dict[a] = 1
    else:
        a_dict[a] += 1
# 最後の値について取り除く個数を求める
if a_dict[pre] < pre:
    ans += a_dict[pre]
else:
    ans += a_dict[pre] - pre
print(ans)

Submission status: Accepted

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

from collections import Counter
A_=Counter(A)

A_key=list(A_.keys())
A_key.sort()

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

Submission status: Accepted

Solution code:
# やるだけ
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 k, v in d.items():
    if k > v:
        # そもそも足りない場合はまるごとなかったことにしなければいけない（増やせないので
        ans += v
    elif k < v:
        # 多かった場合は差分
        ans += v - k
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import collections
N = int(input())
A=  list(map(int,input().split()))

A.sort()

c = collections.Counter(A)
A_ = list(set(A))
ans = 0
for a in A_:
    #print(c[a],a)
    if a > c[a]:
        ans += c[a]
    else:
        ans += c[a]-a
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
old = A[0]
a = 1
ans = 0
for i in range(1, N):
    cur = A[i]
    if cur == old:
        a += 1
    else:
        if old <= a:
            ans += a - old
        else:
            ans += a
        a = 1
    old = cur
if old <= a:
    ans += a - old
else:
    ans += a
print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
dic = Counter(A)
ans = 0
for k,v in dic.items():
    if k < v:
        ans += v - k
    elif k > v:
        ans += v
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

B = collections.Counter(A)
#print(B)

C = list(B.keys())
#print(C)

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

ri()
a = rl()
d = collections.Counter(a)
ans = 0
for k, v in d.items():
    if k <= v:
        ans += (v-k)
    else:
        ans += v
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    n = int(input())
    As = list(map(int, input().split()))
    ans = 0
    for num, count in Counter(As).items():
        if count >= num:
            ans += (count - num)
        else:
            ans += count
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
d = c.most_common()

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

Submission status: Accepted

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

count = Counter(a)

ans = 0
for i in count.items():
  if i[1] < i[0]: ans += i[1]
  else: ans += abs(i[1]-i[0])
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = [0] * (n+1)
res = 0
for v in a:
    if v <= n:
        cnt[v] += 1
    else:
        res += 1

for i in range(1, n+1):
    if cnt[i] < i:
        res += cnt[i]
    else:
        res += cnt[i] - i

print(res)

Submission status: Accepted

Solution code:
from collections import Counter

# input
N = int(input())
res = sum([c - n if c >= n else c for n, c in Counter(list(map(int, input().split()))).most_common()])

print(res)

Submission status: Accepted

Solution code:
from collections import Counter

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

# check
res = 0
for n, c in A.most_common():
    if c >= n:
        res += c - n
    else:
        res += c

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]
    else:
        ans += i[1]-i[0]
print(ans)

Submission status: Accepted

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

from collections import*
C=Counter(A)
ans=0
for k,v in zip(C.keys(),C.values()):
    if k<=v:
        ans+=v-k
    else:
        ans+=v

print(ans)

Submission status: Accepted

Solution code:
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()
b = [0]*100010
ans = 0

for x in a:
        if (x<=1e5):
                b[x] += 1
        else:
                ans += 1
for i in range(100010):
        if (b[i]>=i):
                ans += b[i] - i
        else:
                ans += b[i]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
from collections import Counter
A = Counter(list(map(int,input().split())))
cnt = 0
for key,val in A.items():
   if val>=key: cnt += min(val-key,val)
   else: cnt += val
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, *aa = map(int, open(0).read().split())

from collections import Counter

ans = 0

for k, count in Counter(aa).items():
    if count<k:
        ans += count
    else:
        ans += count-k

print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
l=list(Counter(lmp()).items())
ans=0
for q in l:
    if q[0]>q[1]:
        ans+=q[1]
    elif q[0]<q[1]:
        ans+=q[1]-q[0]
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
from collections import Counter
c = Counter(As)

ans = 0
for num, c in c.most_common():
    if c>num:
        ans += c-num
    elif c<num:
        ans += c

print(ans)

Submission status: Accepted

Solution code:
def examA():
    N = I()
    A = LI()
    D = defaultdict(int)
    for a in A:
        D[a] += 1
    ans = 0
    for key,d in D.items():
        if key>d:
            ans += d
        else:
            ans += d - key
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    N, A, B, C = LI()
    L = [I()for _ in range(N)]
    loop = (1<<(2*N))
    ans = inf
    for l in range(loop):
        cost = 0
        bamboo_A = 0
        bamboo_B = 0
        bamboo_C = 0
        for j in range(N):
            if l&(1<<(2*j))>0:
                if l&(1<<(2*j+1))>0:
                    cost += 10
                    bamboo_A += L[j]
                else:
                    cost += 10
                    bamboo_B += L[j]
            else:
                if l&(1<<(2*j+1))>0:
                    cost += 10
                    bamboo_C += L[j]
        if bamboo_A==0 or bamboo_B==0 or bamboo_C==0:
            continue
        cost += abs(A-bamboo_A) + abs(B-bamboo_B) + abs(C-bamboo_C) - 30
        ans = min(ans,cost)

    print(ans)
    return

def examD():
    N = I()
    P = LI()
    O_ = [-1]*N
    start = P[0]-1
    for i in range(N):
        O_[P[i]-1] = i
    #print(O_,start)
    A = [1]*N
    B = [1]*N
    for i in range(start+1,N):
        cur = O_[i]-O_[i-1]
        if cur>0:
            A[i] = A[i-1] + (cur+1)
            B[i] = B[i-1] - 1
        else:
            A[i] = A[i-1] + 1
            B[i] = B[i-1] - (-cur+1)
    for i in range(start)[::-1]:
        cur = O_[i]-O_[i+1]
        if cur>0:
            B[i] = B[i+1] + (cur+1)
            A[i] = A[i+1] - 1
        else:
            B[i] = B[i+1] + 1
            A[i] = A[i+1] - (-cur+1)
    if A[0]<1:
        add = (1-A[0])
        for i in range(N):
            A[i] += add
    if B[-1]<1:
        add = (1-B[-1])
        for i in range(N):
            B[i] += add

    print(" ".join(map(str,A)))
    print(" ".join(map(str,B)))
    return

def examE():
    return

def examF():
    ans = 0
    print(ans)
    return


from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examA()

"""
9
7 3 9 1 8 4 5 6 2
"""

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import collections
import fractions
import itertools

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
C = {}
cnt = 0
for i in range(N):
    a = A[i]
    if a>N:
        cnt += 1
    else:
        if a not in C:
            C[a]=0
        C[a] += 1
for a in C:
    if a>C[a]:
        cnt += C[a]
    elif a<C[a]:
        cnt += C[a]-a
print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
dic = defaultdict(int)

for t in A:
  dic[t] += 1
#print(dic)
ans = 0
for n,i in dic.items(): #key value
  if n > i:
    ans += i
  elif n < i:
    ans += (i-n)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
lst = list(map(int, input().split()))
cntr = Counter(lst)
res = 0
for i in cntr:
  if cntr[i] >= i:
    res += (cntr[i] - i)
  else:
    res += cntr[i]
print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split())) + [10**18]
a = sorted(a)
c = 0
c_tmp = 1
num = a[0]
for i in range(1, n+1):
  if a[i] != num:
    if a[i-1] > c_tmp:
      c += c_tmp
    elif a[i-1] < c_tmp:
      c += c_tmp - a[i-1]
    c_tmp = 1
    num = a[i]
  else:
    c_tmp += 1
print(c)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(input().split())
cnt = collections.Counter(a)
c = 0
for key, value in cnt.items():
    while int(key) != value:
        value -= 1
        c += 1
        if value == 0:
            break
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
ca = Counter(a)
ans = 0
for k, v in ca.items():
    if v < k:
        ans += v
    elif v > k:
        ans += v-k
print(ans)