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: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
S=0
K=0
while K<N:
	I=A[K]
	X=A.count(I)
	if X==I:
		K+=X
	elif X>I:
		S+=X-I
		K+=X
	else:
		S+=X
		K+=X
print(S)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=[int(i) for i in input().split()]

#print(a)
counter = [0 for i in range(10**9+3)]
#print(counter[a[N-1]])
#print(counter[6])
for i in range(N):
    counter[a[i]] += 1
ans = 0
for i in range(N):
    if counter[i] < i:
        ans += counter[i]
    else:
        ans += counter[i] - i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
S=0
while A!=[]:
	I=A[0]
	X=A.count(I)
	if X==I:
		A=list(filter((I).__ne__, A))
	elif X>I:
		S+=X-I
		A=list(filter((I).__ne__, A))
	else:
		S+=X
		A=list(filter((I).__ne__, A))
print(S)

Submission status: Time Limit Exceeded

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

aa = list(set(a))

t = 0

for i in range(len(aa)):
    z = a.count(aa[i])
    if z > aa[i]:
        t += z - aa[i]
    elif z < aa[i]:
        t += z

print(t)

Submission status: Time Limit Exceeded

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

ans = 0
for s in sorted(set(a))[::-1]:
    cnt = a.count(s)
    tmp = cnt - s
    ans += (tmp > 0) * tmp + (tmp < 0) * cnt
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
st=input().split()
a=[0 for i in range(N)]
M=set([])
for i in range(N):
    a[i]=int(st[i])
    M.add(a[i])
Numlist=list(M)
b=[0 for i in range(len(M))]
def search(num):
    for k in range(len(M)):
        if Numlist[k]==num:
            return k
    return -1
for i in range(N):
    b[search(a[i])]+=1
count=0
for i in range(len(M)):
    if Numlist[i]<=b[i]:
        count+=b[i]-Numlist[i]
    else:
        count+=b[i]
print(count)

Submission status: Time Limit Exceeded

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

array = [0] * (N+1)
set_a = set(a)
for ai in a:
    try:
        array[ai] += 1
    except:
        pass

ans = 0
for sa in set_a:
    if sa > N:
        ans += a.count(sa)
        continue
    while array[sa] != sa and array[sa] > 0:
        array[sa] -= 1
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

list_a = list(set(a))

result = 0
for i in list_a:
    cnt = a.count(i)
    if cnt != i:
        result = result + cnt if cnt < i else result + cnt - i

print(result)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
P = list(map(int,input().split()))
ans = 0
for i in range(N):
    if P.count(P[i]) > P[i]:
        ans += 1
        P[i] = 0
    elif P.count(P[i]) < P[i]:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

list_a = list(set(a))

result = 0
for i in list_a:
    cnt = a.count(i)
    result = result + cnt if cnt < i else result + cnt - i

print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in set(a):
    temp = a.count(i)
    if temp > i:
        ans.append(temp - i)
    elif temp < i:
        ans.append(temp)
print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

aa = collections.Counter(a).most_common()
#print(aa)

for i,j in aa:
    if i > j:
        ans += j
    if i < j:
        ans += j-i
    
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 k < v:
        ans += v - k
    elif k > v:
        ans += v
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
flag = [False] * n
res = 0

for i in range(n):
  if flag[i]:
    continue
  
  c = 0
  j = i
  
  while a[i] == a[j]:
    c += 1
    flag[j] = True
    j += 1
    if j == n:
      break
  
  if c == a[i] or c == 0:
    continue
  elif c < a[i]:
    res += c
  else:
    res += c - a[i]
    
print(res)

Submission status: Accepted

Solution code:
import collections as c

n = int(input())
s = list(map(int,input().split()))
s = c.Counter(s)
ans = 0
for i in s.items():
    a = i[0]
    b = i[1]
    if b<a:
        ans += b
    else:
        ans += b-a
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import math
from collections import Counter
from sys import exit
from itertools import product

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
a = li()

cnt = Counter(a)
ans = 0
for i,j in cnt.items():
    if i > j:
        ans += j
    else:
        ans += j - i
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 math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n = I()
Count = Counter(readInts())
ans = 0
for k,v in Count.items():
    if k < v:
        ans += v - k
    if v < k:
        ans += v
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N, *A = map(int, open(0).read().split())
cnt = Counter(A)
ans = 0
for k, v in cnt.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()))
c = collections.Counter(a)
ans = 0
for k in c.keys():
  if k > c[k]:
    ans += c[k]
  elif k < c[k]:
    ans += c[k] - k
print(ans)

Submission status: Accepted

Solution code:
import collections

N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
C=collections.Counter(L)
D=list(C.keys())
E=list(C.values())
K=len(C)
ans=0
for i in range(K):
	if D[i]==E[i]:
		ans+=0
	if D[i]>E[i]:
		ans+=E[i]
	if D[i]<E[i]:
		ans+=(E[i]-D[i])
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
A = Counter(map(int, input().split()))
ans = 0
for k, v in A.items():
    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()))
C = {}
for i in range(N):
    a = A[i]
    if a not in C:
        C[a] = 0
    C[a] += 1
cnt = 0
for a in C:
    if C[a]<a:
        cnt += C[a]
    else:
        cnt += C[a]-a
print(cnt)

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 x<y: ans += y-x
    elif y<x: ans += y
print(ans)

Submission status: Accepted

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

from collections import Counter
C = Counter(A)
ans = 0
for k, v in C.items():
    if v < k:
        ans += v
    elif v > k:
        ans += (v-k)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 23 15:39:14 2020

@author: liang
"""

N = int(input())
A = [int(x) for x in input().split()]
d = [0]*N
ans = 0
for a in A:
    if a > N :
        ans += 1
    else:
        d[a-1] += 1

for i in range(N):
    if d[i] > 0:
        if d[i] > i+1:
            ans += d[i] - (i+1)
        if d[i] < i+1:
            ans += d[i]
#print(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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
import sys
sys.setrecursionlimit(10**6)


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

c = Counter(a)

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

Submission status: Accepted

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

Submission status: Accepted

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

a=sorted(a)
l=a[0]
cnt=0

b=[]
for i in range(N):
    if a[i]==l:
        cnt+=1
    else:
        b.append([l,cnt])
        l=a[i]
        cnt=1
if cnt>0:
    b.append([l,cnt])

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

count = 0

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

print(count)

Submission status: Accepted

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

count = 0
m = 0

for i in range(N):
  if count == 0:
    m = A[i]
    count += 1
  elif A[i] == m:
    count += 1
  else:
    if m > count:
      ans += count
    else:
      ans += count-m
    count = 1
    m = A[i]

if m > count:
  ans += count
else:
  ans += count-m

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
dic = {}

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

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

ans = 0

for key in dic:
    if dic[key] != key:
        if dic[key] > key:
            ans += dic[key] - key
        else:
            ans += dic[key]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

#import
#import math
#import numpy as np
N = int(input())
#= input()
#= map(int, input().split())
A = list(map(int, input().split()))
#= [input(), input()]
#= [list(map(int, input().split())) for _ in range(N)]
#= [int(input()) for _ in range(N)]
#= {i:[] for i in range(N)}

dic = {}

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

ans = 0

for key in dic:
    if dic[key] != key:
        if dic[key] > key:
            ans += dic[key] - key
        else:
            ans += dic[key]

print(ans)

Submission status: Accepted

Solution code:

from collections import defaultdict

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

D = defaultdict(int)
for a in A:
  D[a] += 1

ans = 0
for a, x in D.items():
  if x >= a:
    ans += x-a
  else:
    ans += x

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().strip().split()))
d={}

for n in range(N):
    if d.get(a[n])==None:
        d[a[n]]=1
    else:
        d[a[n]]+=1

cnt=0
for key in d.keys():
    if key>d[key]:
        cnt+=d[key]
    else:
        cnt+=d[key]-key

print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import starmap
def main():
    N = input()
    A = list(map(int, input().split()))
    count = Counter(A)
    remove = lambda x,y: y-x if y >= x else y
    ans = sum(starmap(remove, count.items()))
    print(ans)

main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    a_lst.sort()
    a_set_lst = list(set(a_lst))
    a_set_lst.sort()

    count_lst = []
    count = 1
    if n == 1:
        count_lst.append(count)
    else:
        for i in range(n - 1):
            a1 = a_lst[i]
            a2 = a_lst[i + 1]

            if a1 == a2:
                count += 1
                if i == n - 2:
                    count_lst.append(count)
            else:
                count_lst.append(count)
                count = 1
        if a_lst[-1] != a_lst[-2]:
            count_lst.append(count)

    minimum = 0
    for i in range(len(a_set_lst)):
        number = a_set_lst[i]
        count = count_lst[i]

        if count < number:
            minimum += count
        else:
            minimum += count - number

    print(minimum)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

counter = Counter(A)

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


print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
d={}
dd={}
if len(A)==1:
    if A[0]==1:
        print(0)
    else:
        print(1)
else:
    for a in A:
        try:
            d[a]+=1
            dd[a]+=1
        except KeyError:
            d[a]=1
            dd[a]=1
        #揃ったら除くべき数値を初期化
        if dd[a]==a:
            d[a]=0
    print(sum(d.values()))

Submission status: Accepted

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
co = 0
for t , count in c.items():
    if t < count:
        co += count - t
    elif count < t:
        co += count
print(co)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(s) for s in input().split()]
p = {}

for b in a:
    if b in p:
        p[b] += 1
    else:
        p[b] = 1

ans = 0
for k in p:
    if k > p[k]:
        ans += p[k]
    elif k < p[k]:
        ans += (p[k] - k)

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
a.sort()
a.append(0)
i=0
ans=0
while i<N:
    x=a[i]
    count=0
    while a[i]==x:
        i+=1
        count+=1
    if count<x:
        ans+=count
    else:
        ans+=count-x
print(ans)

Submission status: Accepted

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

from collections import Counter
c = Counter(l)
ans = 0
for key in c:
    if key > c[key]:
        ans += c[key]
    else:
        ans += c[key] - key

print(ans , flush=True)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = set(A)
d = {}
for a in A:
  d[a] = d.get(a, 0) + 1
ans = 0
for b in B:
  s = d[b]
  if s >= b:
    ans += (s - b)
  else:
    ans += s
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
C=Counter(list(map(int, input().split())))
# print(C)
ans=0
for i in C:
  j=C[i]
  if j>=i:
    ans+=j-i
  else:
    ans+=j
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] not in dict:
    dict[a[i]]=1
  else:
    dict[a[i]]+=1
ans=0
for i in dict:
  if dict[i]<i:
    ans+=dict[i]
  elif dict[i]==i:
    continue
  else:
    ans+=dict[i]-i
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,value in d.items():
    if key > value:
        ans += value
    if value > key:
        ans += (value - key)
print(ans)

Submission status: Accepted

Solution code:
#64 C - Good Sequence
import collections
N = int(input())
A = list(map(int,input().split()))

cnt = collections.Counter(A)

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

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N,A = ilint()
C = counter()
for a in A:
    C.add(a)
ans = 0
for k in C:
    ans += C[k] if C[k]<k else C[k]-k
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

from collections import defaultdict
dd = defaultdict(int)
for key in a:
    dd[key] += 1
for key in dd.keys():
    #print(key,dd[key])
    if dd[key]>=key:
        ans += dd[key]-key
    else:
        ans += dd[key]
print(ans)

Submission status: Accepted

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


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


def main():
    N = INT()
    li = LIST()
    A = defaultdict(int)
    for i in li:
        A[i] += 1
    cnt = 0
    for i in A.keys():
        if i < A[i]:
            cnt += A[i]-i
        elif i > A[i]:
            cnt += A[i]

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
num_map = dict()
for i in range(n):
    if a[i] not in num_map:
        num_map[a[i]] = 1
    else:
        num_map[a[i]] += 1

res = 0
for key, value in num_map.items():
    if key <= value:
        res += value - key
    else:
        res += value

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    a = i_list()
    dic = {}
    for i in a:
        dic[i] = dic.get(i,0) + 1
    ans = 0
    for i,k in dic.items():
        if i < k:
            ans += k-i
        elif i > k:
            ans += k
    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).most_common()
num = 0
for i,j in a:
    if i < j:
        num += (j-i)
    elif j < i:
        num += j
print(num)

Submission status: Accepted

Solution code:
import collections
N = int(input())
lsA = list(map(int,input().split()))
counterA = collections.Counter(lsA)
ans = 0
for i in counterA.keys():
    if i == counterA[i]:
        continue
    if i < counterA[i]:
        ans += counterA[i]-i
    elif i > counterA[i]:
        ans += counterA[i]

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]

dp=[0]*(n+2)
for i in a:
    if i>n:
        dp[-1]+=1
    else:
        dp[i]+=1

ans=dp[-1]
for i in range(1,n+1):
    if dp[i]>=i:
        ans+=dp[i]-i
    else:
        ans+=dp[i]
print(ans)

Submission status: Accepted

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

ans = 0

if N == 1 and a[0] != 1:
    print(1)
    exit()
elif N == 1 and a[0] == 1:
    print(0)
    exit()


for i in (a_counter.items()):
    key = (i[0])
    value = (i[1])

    if key == value:
        pass
    
    elif key < value:
        ans = ans + (value - key)
    else:
        ans = ans + (value) 

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

C = Counter(A)
ans = 0

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

print(ans)

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 set(A):
  I = C[i]
  if I == i:
    continue
  elif I > i:
    cnt += I - i
  else :
    cnt += I
  
print(cnt)

Submission status: Accepted

Solution code:
N = input()
A = sorted([int(x) for x in input().split()])
import bisect as bs
ans = 0
f = lambda X, x: bs.bisect_right(X,x) - bs.bisect_left(X,x)
for a in set(A):
    cnt = f(A,a)
    if cnt < a:
        ans += cnt
    else:
        ans += cnt-a
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
a = RI()

for i in range(n):
    ddict[a[i]] += 1

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

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
input = lambda: sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
dic = collections.defaultdict(int)
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
	dic[a[i]] += 1
ans = 0
for key in dic.keys():
    if dic[key] >= key:
    	ans += (dic[key] - key)
    else:
        ans += dic[key]
print(ans)

Submission status: Accepted

Solution code:
import collections
dic = collections.defaultdict(int)
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
	dic[a[i]] += 1
ans = 0
for key in dic.keys():
    if dic[key] >= key:
      ans += (dic[key] - key)
    else:
        ans += dic[key]
print(ans)

Submission status: Accepted

Solution code:
import collections
dic = collections.defaultdict(int)
n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
  dic[a[i]] += 1
ans = 0
for key in dic.keys():
    if dic[key] >= key:
      ans += (dic[key] - key)
    else:
        ans += dic[key]
print(ans)

Submission status: Accepted

Solution code:
N=int(input())

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

a.sort()
c=1
ans=0
for i in range(N-1):
    if a[i]==a[i+1]:
        c+=1
        if c>a[i]:
            ans+=1
    else:
        if c<a[i]:
            ans+=c
            c=1
        else:
            c=1
if c<a[N-1]:
    ans+=c

print(ans)