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

a.sort()
amax=a[-1]
amin=a[0]

s=[]
ai=a[0]
acnt=-1
for i in range(n):
    if a[i]>ai:
        s.append([ai,acnt+1])
        acnt=0
        ai=a[i]
    else:
        acnt=acnt+1
s.append([ai,acnt+1])
        
# print(s)
    
dn=0
for i in range(len(s)):
    ni=s[i][1]
    if ni>s[i][0]:
        dn=dn+(ni-s[i][0])
    elif ni<s[i][0]:
        dn=dn+ni

print(dn)

Submission status: Accepted

Solution code:
from collections import*;input();print(sum(v-k*(k<=v)for k,v in Counter(map(int,input().split())).items()))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

b = collections.Counter(a)
delete = 0

for i,j in b.items():
  i = int(i)
  if i > j:
    delete += j
  elif i < j:
    delete += j - i
    
print(delete)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
def runlength(S):
    ans = []
    for s in S:
        if len(ans) == 0 or ans[-1][0] != s:
            ans.append([s,1])
        else:
            ans[-1][1] += 1
    return ans
a = runlength(a)
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 = list(map(int, input().split()))

c = Counter(a)

ans = 0
for n, count in c.items():
  if n == count:
    continue
  if n < count:
    ans += count - n
  elif n > count:
    ans += count

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a_l=sorted(map(int,input().split()))
a_l.append("!")
cnt = 1
ans = 0

for i in range(1,n+1):
    a1 = a_l[i-1]
    a2 = a_l[i]
    if a1 == a2:
        cnt += 1
    else:
        if cnt - a1 >= 0:
            ans += cnt - a1
        else:
            ans += cnt
        cnt = 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

num = {}

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

keys = list(num.keys())
values = list(num.values())

ans = 0
for i in range(len(keys)):
    if values[i] < keys[i]:
        ans += values[i]
    else:
        ans += values[i] - keys[i]

print(ans)

Submission status: Accepted

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

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-k
  elif k>v:
    ans += v

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

res = 0
for i, c in Counter(a).items():
	res += c - i if c >= i else c
	
print(res)

Submission status: Accepted

Solution code:
from collections import defaultdict


def solve():
    _ = int(input())
    a = list(map(int, input().split()))
    
    b_dict = defaultdict(int)
    for ai in a:
        b_dict[ai] += 1
    
    ans = 0
    for key, val in b_dict.items():
        if val < key:
            ans += val
        elif key < val:
            ans += val - key
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter

N = int(input().strip())
a_list = list(map(int, input().rstrip().split()))
#-----

cnt_dic = Counter(a_list)

cnt=0
for i,value in cnt_dic.items():
    if i == value:
        continue
    elif i > value:
        cnt += value
    elif i < value:
        cnt += (value - i)

print(cnt)

Submission status: Accepted

Solution code:
import collections
n=int(input())
t = list(map(int,input().split()))
c = collections.Counter(t)
c1 = sorted(c.items(), key=lambda x:-x[1])
count = 0

for k,i in c1:
    if k<=i:
        count += i-k
    else:
        count += i
print(count)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [i for i in a if i <= 10**5]
ans = len(a)-len(b)
import collections
c = collections.Counter(b)
for i in range(0,10**5+1):
  if c[i] < i:
    ans += c[i]
  if c[i] > i:
    ans += c[i]-i
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

s=set(l)

import collections
c = collections.Counter(l)

x=0
for i in s:
    y = c[i]
    if i <= y:
        x += y - i
    else:
        x += y

print(x)

Submission status: Accepted

Solution code:
N=int(input())
a=input().split()
numbers=[0]*10**5
A=[int(b) for b in a]
answer=0
for c in A:
    if c>10**5:
        answer+=1
    else:
        numbers[c-1]+=1
for d in range(10**5):
    if numbers[d]==0:
        continue
    elif numbers[d]==d+1:
        continue
    else:
        if numbers[d]>d+1:
            answer+=numbers[d]-d-1
        else:
            answer+=numbers[d]
print(answer)

Submission status: Accepted

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


ans = 0
A = Counter(a)

for i in A.keys():
    if i != A[i]:
        if A[i] < i:
            ans += A[i]
        else:
            ans += A[i]-i

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
cA = Counter(A).items()
ans = 0
for key, val in cA:
    if key>val:
        ans += val
    elif key<val:
        ans += (val-key)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = {}
for a in A:
    if a not in B:
        B[a] = 0
    B[a] += 1

ans = 0
for b in B:
    v = B[b]
    if v >= b:
        ans += v - b
    else:
        ans += v
print(ans)

Submission status: Accepted

Solution code:
import collections
N=int(input())
a=list(map(int,input().split()))
l=[]
cnt=0
c=collections.Counter(a)
values=list(c.values())
key=list(c.keys())
for i in range(len(key)):
    l.append([key[i],values[i]])
#print(l)
for i in range(len(key)):
    if l[i][1]>l[i][0]:
        cnt=cnt+(l[i][1]-l[i][0])
    elif l[i][1]<l[i][0]:
        cnt=cnt+l[i][1]
print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
d=Counter(a)
cnt=0
for i , j in d.items():
    if i>j:
        cnt+=j
    elif i==j:
        continue
    else:
        cnt=cnt+j-i

print(cnt)

Submission status: Accepted

Solution code:
#082_C
from collections import Counter
n=int(input())
a=Counter(input().split())

ans=0
for key,value in a.items():
    if value>int(key):
        ans+=value-int(key)
    elif value<int(key):
        ans+=value
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())

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

dicts = Counter(lists)

ans = 0

for key in dicts.keys():
    if dicts[key] - int(key) >= 0:
        ans += dicts[key] - int(key)
    else:
        ans += dicts[key]
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
import collections

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

la = len(a)
ans = 0
for k, c in ac.items():
  if c < k:
    ans += c
  else:
    ans += c - k
    
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
def main():
    N = int(input())
    d = defaultdict(int)
    ans = 0
    for a in tuple(map(int,input().split())):
        d[a] += 1
    for v in d.items():
        if v[0] > v[1]:
            ans += v[1]
        else:
            ans += v[1]-v[0]
    print(ans)
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 k, v in C.items():
    if k < v:
        ans += v - k
    elif k > v:
        ans += v
print(ans)

Submission status: Accepted

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

from collections import Counter

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

num = list(set(a))
cnt = Counter(a)
ans = 0

for i in range(len(num)):
    # print(num[i], cnt[num[i]])
    if num[i] == cnt[num[i]]:
        continue
    elif num[i] < cnt[num[i]]:
        # print('<')
        ans += (cnt[num[i]] - num[i])
    else:
        # print('0')
        ans += cnt[num[i]]

print(ans)

Submission status: Accepted

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

for i in data:
    if d.get(i) is None:
        d[i] = 1
    else:
        d[i] += 1

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = [int(x) for x in input().split()]

from collections import Counter
asz = Counter(a)

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

print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = collections.Counter([int(x) for x in input().split()])
res = 0
for key in a.keys():
    k_int = int(key)
    val = a[key]
    if k_int == val:
        continue
    elif k_int < val:
        res += val - k_int
    else:
        res += val
print(res)

Submission status: Accepted

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

a=sorted(a)
s=set(a)
count=0

base=0
judge=0

for i in a:
    if base!=i:
        #print(judge,base)
        if judge>=base:
            count+=judge-base
        else:
            count+=judge
        base=i
        judge=1
    else:
        judge+=1
if judge>=base:
    count+=judge-base
else:
    count+=judge


print(count)

Submission status: Accepted

Solution code:
import collections
n = int(input())
A = list(map(int, input().split()))
B = collections.Counter(A)
ans = 0
for i in B:
    if i > B[i]: 
        ans += B[i]
    else: ans += B[i] - 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 key, val in c.items():
    if key == val:
        continue
    else:
        if val - key > 0:
            ans += min(val, val - key)
        else:
            ans += val

print(ans)

Submission status: Accepted

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
a.sort()
c=collections.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:
#Counterめちゃべんり！！ 辞書型のkey(),value(),items()をつかえるようにしよう
from collections import Counter

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

ans = 0
for i,j in aa.items():
	if i > j:
		ans += j
	elif 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()))

ACounter=Counter(A)

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

Submission status: Accepted

Solution code:
import collections

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

counter = collections.Counter(a_L)

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
cnt,ans=0,0
p=0
for x in a:
  if p==x:
    cnt+=1
  else:
    if cnt>p:
      ans+=cnt-p
    elif cnt<p:
      ans+=cnt
    p=x
    cnt=1
if cnt>p:
  ans+=cnt-p
elif cnt<p:
  ans+=cnt
print(ans)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

ans = 0
for key, value in Counter(A).items():
    if key <= value:
        ans += (value - key)
    else:
        ans += value

print(ans)

Submission status: Accepted

Solution code:
def Good_Sequence(n , al):

    count = {}
    ans = 0

    for i in al:
        if i in count:
            count[i] += 1
        else:
            count[i] = 1

    for i in count.keys():
        key = int(i)
        value = int(count[i])
        if key != value:
            ans += value if value < key else abs(key - value)

    return ans

def main():
    n = int(input())
    al = list(map(int , input().split()))
    print(Good_Sequence(n , al))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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


c=Counter(a).items()


ans=0
for i,j in c:
  if j>=i:ans+=(j-i)
  else:ans+=j

    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

import collections

A_count = collections.Counter(A)


ans = 0
for x, x_count in A_count.items():
    if x == x_count:
        continue
    elif x < x_count:
        ans += x_count-x
    else:
        ans += x_count
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

from collections import Counter

c = Counter(a)
keys, values = zip(*c.most_common())

ans = 0

for i in range(len(keys)):
    if values[i] - keys[i] < 0:
        ans += values[i]
    else:
        ans += values[i] - keys[i]
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
n = len(a)
a.sort()
a.append(-1)
ans = 0
i = 0
while i < n:
    cnt = 1
    while a[i] == a[i+1]:
        cnt += 1
        i += 1
        if i == len(a)-1:
            break
    if cnt > a[i]:
        ans += cnt - a[i]
    elif cnt < a[i]:
        ans += cnt
    i += 1
print(ans)

Submission status: Accepted

Solution code:
import collections

N = int(input())
sequence = list(map(int, input().split()))
CTR = collections.Counter(sequence).most_common()
ans = 0

for i in range(len(CTR)):
    cnt = CTR[i][1]
    obj = int(CTR[i][0])

    if (obj > cnt):
        ans += cnt
    
    else:
        ans += cnt - obj
    
print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = [int(_) for _ in input().split()]
c = collections.Counter(a).items()
ans = 0
for i in c:
    if i[0] == i[1]:
        pass
    elif i[0] > i[1]:
        ans += i[1]
    else:
        ans += i[1] - i[0]
print(ans)

Submission status: Accepted

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

for key,value in b.items():
    if key <= value:
        ans += value - key  
    else:
        ans += value

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
d={}
for i in range(len(a)):
    d[a[i]] = d.get(a[i],0)+1
res=0
for k,v in d.items():
    res+=v if v<k else v-k
print(res)

Submission status: Accepted

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

d = {}
for ai in a:
    if d.get(ai) == None:
        d[ai] = 1
    else:
        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:
n = int(input())
a = sorted(list(map(int, input().split())))

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

if cnt < x:
    ans += cnt
else:
    ans += cnt - x

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

i,cnt,ans=1,1,0
m=num[0]
while i<n:
    if num[i]==m:
        cnt+=1
    else:
        if cnt<m:
            ans+=cnt
        elif cnt>m:
            ans+=cnt-m
        m=num[i]
        cnt=1
    i+=1
if cnt<m:
  ans+=cnt
elif cnt>m:
  ans+=cnt-m
print(ans)

Submission status: Accepted

Solution code:
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

from collections import defaultdict
dd = defaultdict(int)

N=I()
a=LI()

a.sort()

for i in range(N):
    dd[a[i]]+=1
    
ans=0
for k,v in dd.items():
    if v>k:
        ans+=v-k
    if v<k:
        ans+=v
        
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

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

Submission status: Accepted

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

counter = Counter(b_list)
ans = 0

for num, count in counter.most_common():
  if num == count:
    pass
  else:
    if num < count:
      ans += count - num
    elif num > count:
      ans += count
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 num, cnt in c.items():
    if cnt>=num:
        ans += cnt - num
    else:
        ans += cnt
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from collections import deque

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
c = c.most_common()
ans = 0
for num, cnt in c:
    if cnt>=num:
        ans += cnt - num
    else:
        ans += cnt
print(ans)

Submission status: Accepted

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

from collections import defaultdict
d = defaultdict(int)

for a in A:
  d[a] += 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:
import collections

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

c = collections.Counter(ls)
ans = 0

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

print(ans)

Submission status: Accepted

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

for i in counter:
    if i != counter[i]:
        if i < counter[i]:
            ans += counter[i] - i
        else:
            ans += counter[i]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import collections

N = int(input())

a = [int(i) for i in input().split()]
c = collections.Counter(a)


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

Submission status: Accepted

Solution code:
from collections import Counter

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

print(sum(v if v < k else v - k for k, v in Counter(A).items()))

Submission status: Accepted

Solution code:

from collections import Counter

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    counter = Counter(A)
    print(sum([v if v < k else v-k for k,v in counter.items()]))
    
solve()

Submission status: Accepted

Solution code:
from collections import Counter

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

for num, cnt in dict(A).items():
    total += cnt if cnt-num < 0 else cnt-num
print(total)

Submission status: Accepted

Solution code:
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a).most_common()
# print(cnt)
ans = 0
for i in cnt:
    if i[0] < i[1]:
        ans += i[1] - i[0]
    elif i[0] == i[1]:
        continue
    else:
        ans += i[1]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter # 重複個数のカウント: Counter(num_list)

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

    ans = 0

    count_dict = Counter(num_list)

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    numbers = sorted(list(map(int, input().split())))
    now = numbers[0]
    count = 0
    answer = 0
    for i in range(n):
        if now == numbers[i] and not i == n - 1:
            count += 1
        elif now < numbers[i] or i == n - 1:
            if i == n - 1:
                count += 1
            if count > now:
                answer += count - now
            elif now > count:
                answer += count
            now = numbers[i]
            count = 1
    print(answer)


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 num, i in cnt.items():
    if num == i:
        pass
    elif num < i:
        ans += i - num
    else:
        ans += i
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

print(ans)

Submission status: Accepted

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

n = len(a)
a.sort()
a.append(0)
ans = 0
i = 0

while i < n:
    cnt = 1
    while a[i] == a[i+1]:
        cnt += 1
        i += 1
    if cnt >= a[i]:
        ans += cnt - a[i]
    else:
        ans += cnt
    i += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n=input()
a=list(map(int,input().split()))
a_count = Counter(a)
ans = 0
for value,count in a_count.items():
    if value < count:
        ans += count - value
    elif value > count:
        ans += count
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
l = {}
for i in a:
    if i in l:
        l[i] += 1
    else:
        l[i] = 1
ans = 0
for i in l.keys():
    if i <= l[i]:
        ans += l[i]-i
    else:
        ans += l[i]
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:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.append(0)
ans = 0
cnt = 0
for i in range(1,n+1):
    cnt += 1
    if a[i] != a[i-1]:
        if cnt < a[i-1]:
            ans += cnt
        else:
            ans += cnt - a[i-1]
        cnt = 0
    #print(ans)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    counter = Counter(A)
    ret = 0
    for k,v in counter.items():
        ret += v-k if v-k>=0 else v
        
    print(ret)
    
solve()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
a2=sorted(a)
now=a2[0]
ren=1
for i in range(1,n):
    if now!=a2[i]:
        if ren<now:
            ans+=ren
        elif now<ren:
            ans+=(ren-now)
        now=a2[i]
        ren=1
        continue
    ren+=1
if ren<now:
    ans+=ren
elif now<ren:
    ans+=(ren-now)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = map(int, input().split())
dict = {}
for x in a:
    if x in dict:
        dict[x] += 1
    else:
        dict[x] = 1

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]

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

ans = 0
for i in d:
	if i<=d[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()))

from collections import defaultdict
d = defaultdict(int)

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

ans = 0
for t in set(a):
  cnt = d[t]

  if t > cnt:
    ans += cnt
  else:
    ans += (cnt - t)

print(ans)

Submission status: Accepted

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

n = len(a)
a.sort()
a.append(0)
ans = 0
i = 0
while i < n:
    cnt = 1
    while a[i] == a[i+1]:
        cnt += 1
        i += 1
    if cnt >= a[i]:
        ans += cnt - a[i]
    else:
        ans += cnt
    i += 1
print(ans)

Submission status: Accepted

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

a.sort()
cnt = 1
ans = 0
for i in range(len(a)-1):
    if a[i] == a[i+1]:
        cnt += 1
        continue

    if cnt >= a[i]:
        ans += cnt - a[i]
    else:
        ans += cnt
    cnt = 1
if cnt >= a[-1]:
    ans += cnt - a[-1]
else:
    ans += cnt
print(ans)

Submission status: Accepted

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

b = [0 for _ in range(n+1)]

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

for i in range(n+1):
    if b[i] > i: ans += b[i] - i
    if b[i] < i: ans += b[i]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

from collections import defaultdict
d = defaultdict(int)

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

ans=0
for num,cnt in d.items():
    if num > cnt:
        ans+=cnt
    else:
        ans+=cnt-num
print(ans)