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())
Data = list(map(int,input().split()))
Dic = {}
for d in Data:
    if d in Dic.keys():
        Dic[d] += 1
    else:
        Dic[d] = 1
ans = 0
for k,v in Dic.items():
    if k == v:
        pass
    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()))
B = [0] * 100001
ans = 0
for i in range(N):
	if A[i] <= 100000:
		B[A[i]] += 1
	else:
		ans += 1
for i in range(100001):
	if B[i] < i:
		ans += B[i]
	else:
		ans += B[i] - i
print(ans)

Submission status: Accepted

Solution code:
import collections

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

ca = collections.Counter(A)
cc = ca.most_common()

cnt = 0
for i in range(len(cc)):
    if cc[i][1]>=int(cc[i][0]):
        cnt += cc[i][1] - int(cc[i][0])
    else:
        cnt += cc[i][1]


print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
ls=[int(s) for s in input().split()]
dic={}
for e in ls:
  if (e in dic):
    dic[e]+=1
  else:
    dic[e]=1
ans=0
for k,v in dic.items():
  if k<=v:
    ans+=v-k
  else:
    ans+=v
print(ans)

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    A = string_to_int(inputs[0])
    counter = collections.Counter()
    del_num = 0
    LIMIT = 10 ** 5 + 1
    for a in A:
        if a >= LIMIT:
            del_num += 1
        else:
            counter[a] += 1
    for k in counter.keys():
        c = counter[k]
        if k > c:
            del_num += c
        else:
            del_num += c - k
    return del_num


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
list_cnt = [0] * N

ans = 0
for a in A:
    if a > N:
        ans += 1
    else:
        list_cnt[a-1] += 1

for i in range(N):
    if list_cnt[i] >= i + 1:
        ans += (list_cnt[i] - i - 1)
    else:
        ans += list_cnt[i]

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

print(ans)

Submission status: Accepted

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

i = 0
remove_cnt = 0
while i < N:
    s = a[i]

    cnt = 1
    while True:

        i += 1
        if i == N or a[i] != s:
            break
        else:
            cnt += 1 

    if cnt > s:
        remove_cnt += cnt - s
    elif cnt < s:
        remove_cnt += cnt
        
print(remove_cnt)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
ary = Counter(list(map(int,input().split()))).items()
print(sum([y if x > y  else y-x if y > x else 0 for x,y in list(ary)]))

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(lst)

ans = 0
for k, v in c.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()))
ac = Counter(A).most_common()
ans = 0
for num,cnt in ac:
  if num > cnt:
    ans += cnt
  elif num < cnt:
    ans += cnt - num
print(ans)

Submission status: Accepted

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

for i in range(len(ckey)):
  if ckey[i]>cval[i]:
    ans+=cval[i]
  elif ckey[i]<cval[i]:
    ans+=cval[i]-ckey[i]
print(ans)

Submission status: Accepted

Solution code:
import collections

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

res = 0
for k, v in collections.Counter(a).items():
    if v-k < 0:
        res += v
    else:
        res += min(v, v-k)

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
N = int(input())
a = list(map(int, input().split()))
D = dd(int)
for i in range(N):
  D[a[i]] += 1
ans = 0
for i in D:
  if D[i] < i:
    ans += D[i]
  else:
    ans += D[i] - i
print (ans)

Submission status: Accepted

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

num_count = {}

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

remove = 0

for i in num_count:
  if num_count[i] < i:
    remove += num_count[i]
  else:
    remove += num_count[i] - i

print(remove)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
ary = Counter(map(int,input().split()))
ans = 0
for i in ary:
    if ary[i] == i:continue
    if ary[i] < i:ans += ary[i]
    else: ans += ary[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 - i
    else:
        ans += j
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
A = list(map(int,input().split()))
A = Counter(A)
count = 0

for a in A:
    if A[a]>=a:
        count += A[a]-a
    else:
        count += A[a]

print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

from collections import Counter

def main(N,A):
    count = 0
    A_count = Counter(A)
    for a in A_count:
        if a==A_count[a]:
            continue
        else:
            if A_count[a]-a<0:
                count += A_count[a]
            else:
                count += A_count[a]-a
    print(count)

if __name__ == '__main__':
    N = int(input())
    A = [int(a) for a in input().split()]
    main(N,A)

Submission status: Accepted

Solution code:
def cc082():
    from collections import Counter

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

    dan = Counter()
    for i in range(0, n):
        dan[an[i]] += 1

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

    print(cnt)

cc082()

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
    else:
        ans+= v
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, amount in c.items():
    if num == amount:
        continue
    elif num < amount:
        ans += amount - num
    else:
        ans += amount

print(ans)

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

from collections import Counter

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

c = Counter(A)
#print(c)

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

print(count)

Submission status: Accepted

Solution code:
import collections

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

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

Submission status: Accepted

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

cnt = 0

for a in A:
    if a not in dictA:
        dictA[a] = 0
    dictA[a] += 1


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

print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
a.sort()
c = Counter(a)
keys = list(c.keys())
values = list(c.values())
count = 0

for i in range(len(keys)):
    if keys[i] == values[i]:
        count += 0
    elif keys[i] > values[i]:
        count += values[i]
    elif keys[i] < values[i]:
        count += values[i] - keys[i]

print(count)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import collections as c

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

ans=0
for a in A:
  if a[0]>a[1]:
    ans+=a[1]
  else:
    ans+=a[1]-a[0]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    from collections import Counter
    C=Counter(map(int,input().split()))
    ans=0
    for k,v in C.items():
        ans+=v if v<k else v-k
    print(ans)
resolve()

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
li.sort()
from collections import Counter
a = dict(Counter(li))
#print(a)
num = 0
for k,v in a.items():
    #print(k,v)
    if k < v:
        num += (v-k)
    elif k > v:
        num += v
print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

a = collections.Counter(a) # dict型

ans = 0
for num, cnt in a.items():
    #print(num, cnt)
    if num <= cnt:
        ans += cnt - num
    else:
        ans += cnt

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = Counter(int(i) for i in input().split())
ans = 0

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

Submission status: Accepted

Solution code:
n = int(input())
aList = list(map(int, input().split()))
aLen = len(aList)
aSet = sorted(list(set(aList)))
aSum = 0
for a in aSet:
    aCount = aList.count(a)
    if aCount > a:
        aSum += aCount - a
    if aCount < a:
        aSum += aCount
    aLen -= aCount
    if a > aLen:
        aSum += aLen
        break

print(aSum)

Submission status: Accepted

Solution code:
import collections

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

a_dict=collections.Counter(a)

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

print(ans)

Submission status: Accepted

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

z=a[0]
c=0
ans=0
for i in range(n):
    if z==a[i]:
        c+=1
    else:
        if z==c:
            z=a[i]
            c=1
            continue
        elif z<c:
            ans+=c-z
        elif z>c:
            ans+=c
        z=a[i]
        c=1
p=a.count(a[-1])
if p<a[-1]:
    ans+=p
elif p>a[-1]:
    ans+=p-a[-1]

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter as ct

n=int(input())
lists=list(map(int,input().split()))
wanted=dict(ct(lists))
if n>=2:
    numbers=0
    for i in wanted.keys():
        a=i-wanted[i]
        if a<0:
            numbers+=abs(a)
        elif a==0:
            numbers+=0
        if a>0:
            numbers+=wanted[i]
    print(numbers)
elif n==1:
    if lists==[1]:
        print(0)
    else:
        print(1)

Submission status: Accepted

Solution code:
# ABC082C - Good Sequence (ARC087C)
from collections import Counter


def main():
    N, *A = map(int, open(0).read().split())
    C = Counter(A)
    ans = sum(j if i > j else j - i for i, j in C.items())
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
C=Counter(A).most_common()
r=0
for j,k in C:
	if k>j:
		r+=k-j
	elif k<j:
		r+=k
print(r)

Submission status: Accepted

Solution code:
import collections

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

#print(a)
cnt=0
for k,v in list(a.items()):
  if v>=k:cnt+=v-k
  else:cnt+=v
    
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
C = [0] * N # [1の個数, 2の個数, 3の個数, ... , Nの個数]
for i in range(N):
  n = A[i]
  if n <= N:
    C[n-1] += 1
  else: # n > N:
    ans += 1

for i in range(N):
  cnt = C[i]
  if cnt > i+1:
    ans += (cnt - (i+1))
  elif cnt < i+1:
    ans += cnt

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
l=defaultdict(int)
n=int(input())
l1=list(map(int,input().split()))
for i in l1:
  l[i]+=1
b=True
lset=set(l1)
answer=0
for i in lset:
  if l[i]!=i:
    if l[i]<i:
      answer+=l[i]
    else:
      answer+=min(l[i]-i,l[i])
print(answer)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
import collections

def main():
    _ = int(input())
    D = collections.defaultdict(int)
    for a in list(map(int, input().split())):
        D[a] += 1
    ans = 0
    for k,v in D.items():
        if k > v:
            ans += v
        elif k < v:
            ans += v-k
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    
    D = defaultdict(int)
    count = 0
    for a in A:
        D[a] += 1
        if D[a] > a:
            count += 1
    for k in D:
        if D[k] < k:
            count += D[k]
    print(count)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
a = Counter(list(map(int, input().split())))
ak = list(a.keys())
av = list(a.values())
ans = 0

for i in range(len(ak)):
    if ak[i] > av[i]:
        ans += av[i]
    elif ak[i] < av[i]:
        ans += av[i] - ak[i]
    else:
        continue

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
b = list(set(a))
ans = 0
for i in range(len(b)):
  cnt = 1
  while len(a) > 1 and a[-1] == a[-2]:
    a.pop()
    cnt += 1
  c = a.pop()
  if c <= cnt:
    ans += cnt - c
  else:
    ans += cnt
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int,input().split()))
    
    from collections import defaultdict
    B = defaultdict(int)
    
    for i in A:
        B[i] += 1
    ans = 0
    for i in B:
        if B[i] < i:
            ans += B[i]
        else:
            ans += (B[i]-i)
    print(ans)
    
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 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())
A=Counter(list(map(int,input().split())))
ans=0
for i in A:
  if A[i]>=i:
    ans+=A[i]-i
  else:
    ans+=A[i]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
a_s=list(set(a))
c_l=Counter(a)

cnt=0
for i in a_s:
    cnt+=c_l[i] if c_l[i]<i else c_l[i]-i
print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
a_s=list(set(a))
c_l=Counter(a)

cnt=0
for i in a_s:
    if c_l[i]<i:
        cnt+=c_l[i]
    else:
        cnt+=c_l[i]-i
print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
dictnumbers = defaultdict(int)
res = 0

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

for i in range(n):
    dictnumbers[numbers[i]] += 1

for i, j in dictnumbers.items():
    if i < j:
        res += j - i
    elif i > j:
        res += j

print(res)

Submission status: Accepted

Solution code:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
counter=Counter(a)
b=list(set(a))
c=0
for i in b:
    k =  counter[i]
    c+= k-i if k-i>=0 else k
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections as c
N = int(input())
L = c.Counter(list(map(int, input().split())))

key = list(L.keys())
val = list(L.values())

cnt = 0

for i in range(len(key)):
	if key[i] <= val[i]:
		cnt += val[i] - key[i]
	else:
		cnt += val[i]

print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a = list(map(str,input().split()))
a_set = list(set(a))
cnt = 0
c = Counter(a)
for i in a_set:
    if c[i] >= int(i):
        
        cnt +=  (c[i] - int(i))
    elif  c[i] < int(i):
        cnt +=  c[i]
print(cnt)

Submission status: Accepted

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

from collections import Counter

c = Counter(a)

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

print(ans)

Submission status: Accepted

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

ans=0
for i,j in dic.items():
    if j >=i:
        ans+=j-i
    else:
        ans+=j
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import collections

N = int(input())
a = list(map(int,input().split()))
a = collections.Counter(a)
ans = 0
for i in a:
    if a[i] > i:
        ans += a[i]-i
    elif a[i] == i:
        pass
    else:
        ans += a[i]
print(ans)

Submission status: Accepted

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

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


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

L.sort()

prev = L[0]
ans = 0
cnt = 0
L.append(-1)
for l in L:
    if l != prev:
        if cnt > prev:
            ans += cnt - prev
        elif cnt < prev:
            ans += cnt
        else:
            pass
        prev = l
        cnt = 1
    else:
        cnt += 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 key, value in c.items():
  if key!=value:
    if key>value:
      ans+=value
    else:
      ans+=value-key
print(ans)

Submission status: Accepted

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

counter = Counter(A)

res = 0
for x in counter.keys():
    y = counter[x]
    if y == x:
        continue
    elif y > x:
        res += (y-x)
    else:
        res += y 
print(res)

Submission status: Accepted

Solution code:
from collections import Counter


n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
cnt = 0
for key, value in c.items():
    if key != value:
        if key > value:
            cnt += value
        else:
            cnt += value - key
print(cnt)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

    dic = {}
    for t in a:
        if t in dic:
            dic[t] += 1
        else:
            dic[t] = 1
    
    ans = 0
    for num, count in dic.items():
        if num > count:
            ans += count
        elif num < count:
            ans += count - num
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter
input()
A=Counter(list(map(int,input().split()))).most_common()
c=0
for a,b in A:
  c+= b-a if b>=a else b
print(c)

Submission status: Accepted

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

ans = 0
for i in cnt:
  if cnt[i] > int(i):
      ans += cnt[i] - int(i)
  elif int(i) > cnt[i]:
      ans += cnt[i]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

D = {}
ans = 0

for i in range(N):
	if a[i] in D.keys():
		D[a[i]] += 1
	else:
		D[a[i]] = 1

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

print(ans)

Submission status: Accepted

Solution code:
import collections

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

counter = collections.Counter()
for x in nums:
    counter[x] += 1

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

Submission status: Accepted

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

a_1 = collections.Counter(a)

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

print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict


def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(int)
    for ai in a:
        d[ai] += 1
    ans = 0
    for k, v in d.items():
        ans += v - k if v >= k else v
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
a = III()

x = defaultdict(int)

for i in range(N):
    x[a[i]] += 1

ans = 0
for k in x.keys():
    if x[k]<k:
        ans += x[k]
    else:
        ans += x[k]-k

print(ans)

Submission status: Accepted

Solution code:
import sys
import  math
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
aaa = na()
c = Counter(aaa)
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 = list(map(int, input().split()))

tmp = [0] * (N+1)
ans = 0

for i in a:
    if i > N:
        ans += 1
    else:
        tmp[i] += 1

for i in range(N+1):
    if i > tmp[i]:
        ans += tmp[i]
    elif i < tmp[i]:
        ans += tmp[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 k,v in c.items():
    if k<=v:
        ans+=v-k
    else:
        ans+=v
        
print(ans)

Submission status: Accepted

Solution code:
import collections

N = int(input())
A = list(map(int, input().split()))
a = collections.Counter(A)
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:
from collections import Counter
n = int(input())
a = [i for i in input().split()]
cnt = Counter(a)
ans = 0

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

Submission status: Accepted

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

    if i == n - 1:
        if cnt < a[i]:
            ans += cnt
        elif cnt > a[i]:
            ans += cnt - a[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
result = 0
for k in d:
  if d[k] < k:
    result += d[k]
  elif d[k] > k:
    result += d[k] - k
print(result)

Submission status: Accepted

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

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

dic_a = dic_a.items()
ans = 0

for j in dic_a:
    if j[0] <= j[1]:
        ans += j[1] - j[0]
    elif j[0] > j[1]:
        ans += j[1]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
Ns = {}
for A in As:
  if not(A in Ns):
    Ns[A] = 0
  Ns[A] += 1
r = 0
for A in Ns:
  n = Ns[A]
  if n >= A:
    r += n-A
  else:
    r += n
print(r)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc082/tasks/arc087_a
# C - Good Sequence
import collections

n = int(input().split()[0])
a_list = list(map(int, input().split()))

# 取り除くことはできる
# 追加はできない

counter = collections.Counter(a_list)

c = 0

# x個より小さい値xは完全に取り除くしかない
c += sum([v for k, v in counter.items() if v < k])
# x個ちょうどの値xには何もしない
# x個より多い値xは、値xと個数の差分を数える
c += sum([v - k for k, v in counter.items() if v > k])

print(c)

Submission status: Accepted

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

for v in a:
    try:
        d[v] += 1
    except:
        d[v] = 1

ans = 0
for i,j in d.items():
    a=j-i if j>=i else j
    ans+=a
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,j in C.items():
    a=j-i if j>=i else j
    ans+=a
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,j in C.items():
  if i!=j:
    a=j-i if j>=i else j
    ans+=a
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
aList = Counter(int(x) for x in input().split())
ans = 0
for i, j in aList.items():
    if i < j:
        ans += j - i
    elif i > j:
        ans += j
print(ans)