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:
n = int(input())
arr = list(map(int,input().split()))

arr.sort()
arr.reverse()

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

print(ans)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
import collections

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
count = Counter(A)
# print('Count', count)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import groupby

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

count = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

print(counter)

Submission status: Accepted

Solution code:
import collections
N=int(input())
a=list(map(int,input().split()))
a_counter=collections.Counter(a)
answer = 0
# print(a_counter)
# print(a_counter[0])
# print(a_counter[1])
# print(a_counter[2])
# print(a_counter[3])
for i in a_counter:
    # print(i)
    # print(i == a_counter[i])
    if i != a_counter[i]:
        if i < a_counter[i]:
            answer += a_counter[i] - i
        else:
            answer += a_counter[i]

print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
#n,m = map(int,input().split())
lst1 = list(map(int,input().split()))

dic1 = dict()

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys
input = sys.stdin.readline


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


# import re
# import array
# import copy
# import functools
# import operator

# import math
# import string
# import fractions
# from fractions import Fraction
from fractions import gcd

# import collections
# import itertools
# import bisect

# import heapq
# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace
# from queue import PriorityQueue as pq
from queue import Queue

# from itertools import accumulate

# from collections import deque
from collections import Counter

# from operator import mul
# from functools import reduce

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random
# import time

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import collections

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

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter


input = sys.stdin.readline


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

    C = Counter(A)

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


    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

cnt = {}

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('input_file.txt')
	
#+++++
import itertools
n=int(input())
aa=list(map(int, input().strip().split()))
am={}
for a in aa:
	t=am.get(a, 0)
	am[a]=t+1

ans=0
for ak, av in am.items():
	if ak <= av:
		ans += av-ak
	else:
		ans += av
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


d = {}


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

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

print(ans)

Submission status: Accepted

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

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

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

print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

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

Submission status: Accepted

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
A=collections.Counter(A)
print(sum([A[i] if A[i]<i else A[i]-i if A[i]>i else 0 for i in A]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

result = {}

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

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

  
print(count)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N = int(input())
import collections

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(a)

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(a)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(a)

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict


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

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

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

    else:
        ans += count - key

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int, input().split()))
a.sort()
nums=[0]*(10**5+1)
counter=0
for i in range(N):
  if a[i]>10**5:
    counter+=1
  else:
    nums[a[i]]+=1
    
for i in range(10**5+1):
  if nums[i]>i:
    counter+=nums[i]-i
  elif nums[i]<i:
    counter+=nums[i]
print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter

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

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

import collections

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

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

print(operation_count)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
a = LIST()

dic = defaultdict(int)

for n in a:
	dic[n] += 1

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

Submission status: Accepted

Solution code:
from collections import Counter

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

s = list(Counter(a).items())

ans = 0

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
dd = collections.defaultdict(int)
ans = 0
for i in range(n):
    dd[str(a[i])] += 1
for k in dd.keys():
    v = dd[k]
    diff = int(k) - v
    if diff <= 0:
        ans += abs(diff)
    else:
        ans += v
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

l = {}
for i in range(len(set_A)):
    l[set_A[i]] = 0
for i in range(N):
    l[A[i]] += 1
    
ans = 0
for k in l.keys():
    if l[k] >= k:
        ans += (l[k] - k)
    else:
        ans += l[k]
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1

n=int(input())
A=list(map(int,input().split()))
C=collections.Counter(A)
for k,w in C.items():
    if k<w:
        count+=w-k
    elif k>w:
        count+=w
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 k,v in d.items():
    if k < v: ans += v-k
    if k > v: ans += v
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

C = Counter(A).most_common()
#print(C)

ans = 0
for k, v in C:
	if v > k:
		ans += v - k
	elif v < k:
		ans += v

print(ans)