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()))
num_dict = {}
for a in A:
    if a in num_dict:
        num_dict[a] += 1
    else:
        num_dict[a] = 1

ans = 0
for k, v in num_dict.items():
    if k == v:
        continue
    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()))

b = set(a)

hoge = {}

for x in b:
    hoge[x] = 0

for x in a:
    hoge[x] += 1

ans = n
for x in b:
    if hoge[x] >= x:
        ans -= x

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

def getN():
    return int(input())


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


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

n = getN()
seq = getList()
bucket = defaultdict(int)

for num in seq:
    bucket[num] += 1

ans = 0
for i in (bucket.keys()):
    num = bucket[i]
    if num != 0:
        if num < i:
            ans += num
        elif num > i:
            ans += num -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 e in C:
    if C[e] >= e:
        ans += C[e]-e
    else:
        ans += C[e]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
D = {}
for i in A :
    if i in D :
        D[i] += 1
    else :
        D[i] = 1
KEY = list(D.keys())
ITEM = list(D.values())
ans = 0
for i in range(len(KEY)) :
    if KEY[i] <= ITEM[i] :
        ans += ITEM[i]-KEY[i]
    else :
        ans += ITEM[i]
print(ans)

Submission status: Accepted

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


def main():
    from collections import Counter

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

from collections import Counter
counter=Counter(A)

ANS=0

for i in counter:
    if counter[i]==i:
        continue
    elif counter[i]>i:
        ANS+=counter[i]-i
    else:
        ANS+=counter[i]

print(ANS)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

cnt = Counter(a)

ans = 0

for k,v in cnt.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())
a = list(map(int,input().split()))
cnt = Counter(a)

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

Submission status: Accepted

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


ans=0

l=collections.Counter(a)

for i,j in l.most_common():
    if int(i)<j:
        ans+=j-int(i)
    elif int(i)>j:
        ans+=j
        
print(ans)

Submission status: Accepted

Solution code:
#ABC082C
N=int(input())
a_sorted=sorted(list(map(int,input().split())))
#必要な変数の作成
Allowable_original=0
Allowable_count=0
Delete_count=0
#aが要素1個のみの場合
if N==1:
    if a_sorted[0]==1:
        print(0)
    else:
        print(1)
    exit()
#順番にチェック
for i in range(N):
    #開始処理
    if i==0:
        #許容個数カウントとその元値を作成
        Allowable_original=a_sorted[0]
        Allowable_count=Allowable_original-1
        continue

    #前の数字と同じか否か
    # 同じなら、
    if a_sorted[i]==a_sorted[i-1]:
        #許容個数カウントを一つ減らす
        Allowable_count-=1
    # 違うなら、または末尾なら、
    if a_sorted[i]!=a_sorted[i-1]:
        # 許容個数カウントの現在値が正か0か負かチェック
        # 正なら、
        if Allowable_count>0:
            #カウントしてきた許容個数（許容個数カウントの元値-現在値）を削除対象カウントに追加
            Delete_count+=Allowable_original-Allowable_count
        #0以下なら、
        else:
            # -1をかけた値を削除対象カウントに追加
            Delete_count-=Allowable_count
        # 許容個数カウントとその元値を新規作成
        Allowable_original = a_sorted[i]
        Allowable_count = Allowable_original - 1
    #末尾なら、
    if i==N-1:
        # 許容個数カウントの現在値が正か0か負かチェック
        # 正なら、
        if Allowable_count>0:
            #カウントしてきた許容個数（許容個数カウントの元値-現在値）を削除対象カウントに追加
            Delete_count+=Allowable_original-Allowable_count
        #0以下なら、
        else:
            # -1をかけた値を削除対象カウントに追加
            Delete_count-=Allowable_count
#結果出力
print(Delete_count)

Submission status: Accepted

Solution code:
dic={}
N=int(input())
for x in map(int,input().split()):
    if dic.get(x,'a')=='a':
        dic[x]=-x+1
    else:
        dic[x]+=1
ans=0
for k,v in dic.items():
    if v<0:
        ans+=k+v
    else:
        ans+=v
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
list_a = list(map(int, input().split()))
dict_a = {}
for number in list_a:
    try:
        dict_a[number] += 1
    except KeyError:
        dict_a[number] = 1
count = 0
for key,value in dict_a.items():
    if key > value:
        count += value
    else:
        count += value - key
print(count)

Submission status: Accepted

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

remCount=0
beforeN =0
index=0
count=0
while index < len(listA):
    if index==0:
        beforeN = listA[index]
        count+=1
    elif beforeN == listA[index]:
        count+=1
    else:
        if count == beforeN:
            pass
        elif count > beforeN:
            remCount+=(count-beforeN)
        else:
            remCount+=count
        beforeN = listA[index]
        count=1
    index+=1
if count == beforeN:
    pass
elif count > beforeN:
    remCount+=(count-beforeN)
else:
    remCount+=count
            
print(remCount)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
A = [int(x) for x in input().split()]
C = defaultdict(int)
for a in A:
  C[a] += 1
cnt = 0
for k, v in C.items():
  cnt += v - k if v >= k else v
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
i = 1
cnt = 1
key = a[0]
ans = 0
while True:
    if i >= len(a):
        break
    if key == a[i]:
        cnt += 1
    else:
        if key != cnt:
            if cnt > key:
                ans += cnt - key
            else:
                ans += cnt
        cnt = 1
        key = a[i]
    
    i += 1

if key != cnt:
    if cnt > key:
        ans += cnt - key
    else:
        ans += cnt

print(ans)

Submission status: Accepted

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

n_cnt = {}
for n in a:
    if n not in n_cnt:
        n_cnt[n] = -n+1
    else:
        n_cnt[n] += 1

print(sum([val if val >=0 else key+val for key, val in n_cnt.items()]))

Submission status: Accepted

Solution code:
from collections import Counter
N, *A = map(int, open(0).read().split())
print(sum(c - x * (c >= x) for x, c in Counter(A).items()))

Submission status: Accepted

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

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

ans = 0
for k in nums.keys():
    if nums[k] > k:
        ans += nums[k]-k
    elif nums[k] < k:
        ans += nums[k]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

cnt = Counter(a)
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = [int(v) for v in input().split()]
cnt = Counter(a)
ans = 0

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

print(ans)

Submission status: Accepted

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

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

    # 初期設定
    ans = 0
    a_set = set(a_list)

    for a in a_set:
        c = a_list.count(a) # 要素の出現回数をカウントする
        if c < a:
            ans += c
        elif c > a:
            ans += c-a
    print(ans)

def main2():
    N = int(input())
    a_list = list(map(int, input().split()))
    ans = 0

    import collections
    count_dict = collections.Counter(a_list) # キーに要素、値に出現回数の辞書

    for key in count_dict:
        diff = key - count_dict[key]
        if diff == 0:
            continue
        elif diff > 0:
            ans += count_dict[key]
        elif diff < 0:
            ans += abs(diff)
    print(ans)



if __name__ == "__main__":
    main2()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

# a = [1, 1, 1, 2, 2, 3]

c = collections.Counter(a)

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
D=dict()
for i in range(N):
    if a[i] in D:
        D[a[i]]+=1
    else:
        D[a[i]]=1
ans=0
for num in D:
    if num<=D[num]:
        ans+=D[num]-num
    else:
        ans+=D[num]
print(ans)

Submission status: Accepted

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

count = {}
for a in a_list:
    if a not in count.keys():
        count[a] = 1
    else:
        count[a] += 1

result = 0
for item, item_count in count.items():
    if item <= item_count:
        result += item_count - item
    else:
        result += item_count

print(result)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
a = [int(x) for x in input().split()]

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a = [int(ai) for ai in input().split()]
c = Counter(a).most_common()
r = 0
for k, v in c:
    if k <= v:
        r += v - k
    else:
        r += v
print(r)

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]
    elif c[i] > i:
        ans += c[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)
sum = 0
for keys, values in CA.items():
    if int(keys) > values:
        sum += values
    else:
        sum += (values - keys)
print(sum)

Submission status: Accepted

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

uni_A = list(set(A))
cnt_dict = {}
for uni_a in uni_A:
    cnt_dict[uni_a] = 0

# print(cnt_dict)

del_count = 0
for a in A:
    cnt_dict[a] += 1
    if cnt_dict[a] > a:
        del_count += 1

for key in cnt_dict.keys():
    if cnt_dict[key] < key:
        del_count += cnt_dict[key]

print(del_count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Ca = [0] * (N+1)
# upper limit is N<10^5
cnt = 0
for a in A:
  if a > N:
    cnt += 1
  else:
    Ca[a] += 1

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

print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()
used = set()
cnt = defaultdict(int)

for a in aa:
	if cnt[a] == 0:
		used.add(a)
	cnt[a] += 1

ans = 0
for n in used:
	if cnt[n] > n:
		ans += cnt[n]-n
	elif cnt[n] < n:
		ans += cnt[n]

print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
a = sorted(list(map(int,input().split())))
res = 0
g = itertools.groupby(a)

for k,v in g:
    l = len(list(v))
    if l>k:
        res += l-k
    elif l<k:
        res += l

print(res)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
A = collections.Counter(a)
ans = 0
for key in A.keys():
    if key <= A[key]:
        ans += A[key] - key
    else:
        ans += A[key]
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 10 01:03:03 2018

@author: Yuki
"""


N = int(input())
A = sorted([int(i) for i in input().split()])
import collections
#N = 5
#A = sorted([2, 4, 1, 4, 2])
cnt_dict = collections.Counter(A)
res_cnt = 0
for key in cnt_dict.keys():
    if key == cnt_dict[key]:
        pass
    else:
        if key < cnt_dict[key]:
            res_cnt += cnt_dict[key] - key
        else:
            res_cnt += cnt_dict[key]
print(res_cnt)

Submission status: Accepted

Solution code:
import collections
_=input();num_dict=collections.Counter(map(int,input().split()))
count=0
for k in num_dict.items():
    if k[0]>k[1]:
        count+=k[1]
    elif k[0]<=k[1]:
        count+=k[1]-k[0]
print(count)

Submission status: Accepted

Solution code:
import bisect
n=int(input())
a = list(map(int,input().split()))
a.sort()
 
c = 0
d = 0 #i
 
while d <= n-1:
    s2 = bisect.bisect_right(a,a[d])
    s = s2-d
    if a[d] > s:
        c += s
    else:
        c += s-a[d]
    d = d + s
    
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 k,v in cnt.items():
    if k < v:
        ans += (v-k)
    elif k > v:
        ans += v
        
print(ans)

Submission status: Accepted

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

a_count = dict()
for a_i in a:
	if a_i not in a_count:
		a_count[a_i] = 0 
	a_count[a_i] += 1

sum_num = 0
for a_i in a_count:
	a_count_a_i = a_count[a_i]
	sum_num += a_count_a_i - a_i if a_i <= a_count_a_i else a_count_a_i
print(sum_num)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

b = [0]*(10**5+1)
ans = 0

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

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

print(ans)

Submission status: Accepted

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

d = {}

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

tot = 0
for k in d.keys() :
    if d[k] < k :
        tot += d[k]
    elif d[k] > k :
        tot += d[k] - k
        
print(tot)

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=chk=0
for i in d:
    ans+=[d[i],d[i]-i][d[i]>=i] 
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 k, v in d.items():
    if k < v:
        ans += v - k
    elif k > v:
        ans += v
print(ans)

Submission status: Accepted

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

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

    a_set = set(a_list)
    cnt = Counter(a_list)

    min_cnt = 0
    for i in a_set:
        if cnt[i] - i >= 0:
            min_cnt += cnt[i] - i
        else:
            min_cnt += cnt[i]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))
    counter = {}
    ans = 0

    for i in a:
        if str(i) in counter.keys():
            counter[str(i)] += 1
        else:
            counter[str(i)] = 1
    for i, j in counter.items():
        if int(i) > j:
            ans += j
        else:
            ans += j - int(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 ele in a:
  d[ele] += 1
ans = 0
for k, v in d.items():
  if k!=v:
    t = float("INF")
    if v>k:
      t = v-k
    ans += min(t, v)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
'''input
4
3 3 3 3
'''
from collections import Counter
n = input()
arr = map(int,raw_input().split())
c = Counter(arr)
ans = 0
for i in c:
	if c[i] < i:
		ans += c[i]
	else:
		ans += (c[i]-i)
print ans

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))

npA = np.sort(A)

ans = 0
while len(npA) > 0 and N >= npA[0]:
    i = np.min(npA)
    tmp = np.sum(npA == i)
    if tmp > i:
        ans += tmp - i
    elif tmp < i:
        ans += tmp
    npA = np.delete(npA, range(tmp))


print(ans + len(npA))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
dic = {}
for nums in A:
  if nums in dic:
    dic[nums] += 1
  else:
    dic[nums] = 1
a = list(dic.keys())
b = list(dic.values())
i = 0
ans = 0
while i < len(a):
  if a[i] > b[i]:
    ans += b[i]
    i += 1
  else:
    ans += b[i]-a[i]
    i += 1
print(ans)

Submission status: Accepted

Solution code:
def line_input(f, type):
    return f(map(type, input().split(" ")))

n = input()
a = line_input(tuple, int)

from collections import Counter
c = Counter(a)
ans = 0
for k, v in c.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()))
a.sort()

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

if len(a)==1 and a[0]!=1:
    ans = 1
print(ans)

Submission status: Accepted

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

arr = map(int,raw_input().split())

counter = collections.Counter(arr)

ans = 0 

for item in counter.items() :
	if item[0] == item[1]:
		next

	elif item[1] < item[0]:
		ans += item[1]

	else :
		ans += item[1]-item[0]

print ans

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 22 10:08:31 2018

@author: Yuya
"""

N=int(input())

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



#count_sum=0
#count = 1
#
#for i in range(N-1):
#    flag=-1
#    if a[i+1]!=a[i]:
#        if count>a[i]:
#            count_sum += count-a[i]
#        elif count<a[i]:
#            count_sum += count
#        count=1
#        flag=1
#    else:
#        count+=1
#
#if flag==-1:
#    if count>a[N-1]:
#        count_sum += count-a[N-1]
#    elif count<a[N-1]:
#        count_sum += count
#
#print(count_sum)

count_a = [0]*100000
ans = 0

for i in range(N):
    if a[i]<100001:
        count_a[a[i]-1] += 1
    else:
        ans += 1


for i in range(100000):
    if i+1<count_a[i]:
        ans+=count_a[i]-i-1
    elif i+1>count_a[i]:
        ans+=count_a[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([(j-i if j>=i else j) for i,j in C.items()]))

Submission status: Accepted

Solution code:
from collections import Counter

_ = input()
xs = [int(x) for x in input().split()]
c = Counter(xs)

print(sum(v*(k > v) + max(v - k, 0) for k, v in c.items()))

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
a = [int(x) for x in input().split()]

c = defaultdict(lambda: 0)
for a_i in a:
    c[a_i] += 1

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

Submission status: Accepted

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

from collections import Counter 

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

# 各数値ごとに数を集計(Counterオブジェクトで集計処理を簡略化)
num_dict = Counter(input_list)

ans = 0
# 数値(key)と個数(value)の大小によって処理を分ける
for key, value in num_dict.items():
    # valueのが大きければkeyとvalueを揃える
    if key < value:
        ans += value - key
    # 元々揃っていれば何もしない
    elif key == value:
        continue
    # keyのが大きければその値を取り除く
    elif key > value:
        ans += value
print(ans)

Submission status: Accepted

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

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

num_dict = {}
# 各数値ごとに数を集計
for num in input_list:
    # 辞書にその数値のキーが存在すれば+1追加
    if num in num_dict:
        num_dict[num] += 1
    # なければ新たにキー作成
    else:
        num_dict[num] = 1

ans = 0
# 数値(key)と個数(value)の大小によって処理を分ける
for key, value in num_dict.items():
    # valueのが大きければkeyとvalueを揃える
    if key < value:
        ans += value - key
    # 元々揃っていれば何もしない
    elif key == value:
        continue
    # keyのが大きければその値を取り除く
    elif key > value:
        ans += value
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())

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



D={}
for i in range(N):
    if str(S[i]) in D:
        D[str(S[i])]+=1
    else:
        D.update({str(S[i]):1})

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

Submission status: Accepted

Solution code:
n = input()
arr = list(map(int, input().split()))
ar = [0 for i in range(100001)]
res = 0
for i in arr:
    if i > 100000:
        res += 1
    else:
        ar[i] += 1
for i in range(len(ar)):
    if ar[i] > i:
        res += ar[i] - i
    if ar[i] < i:
        res += ar[i]
print(res)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

Solution code:
N = int(input())
S = sorted(list(map(int, input().split())))
stk = []
tmp = 0
res = 0
passed = 0
for e in S:
    if e <= passed:
        res += 1
        continue
    if tmp == 0:
        tmp = e
    if e == tmp:
        stk.append(e)
    else:
        res += len(stk)
        stk = [e]
        tmp = e
    if tmp == len(stk):
        stk = []
        passed = tmp
res += len(stk)
print(res)

Submission status: Accepted

Solution code:
N = int(input())
S = sorted(list(map(int, input().split())))
stk = []
tmp = 0
res = 0
passed = set()
for e in S:
    if e in passed:
        res += 1
        continue
    if tmp == 0:
        tmp = e
    if e == tmp:
        stk.append(e)
    else:
        res += len(stk)
        stk = [e]
        tmp = e
    if tmp == len(stk):
        stk = []
        passed.add(tmp)
res += len(stk)
print(res)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
distrib={}
for element in a:
    if element not in distrib:
        distrib[element] = 1
    else:
        distrib[element] += 1
ans = 0
for key in distrib:
    diff = distrib[key] - key
    if diff >= 0:
        ans += diff
    else:
        ans += distrib[key]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
L = list(set(a))
res = 0
d = Counter()
d.update(a)
for i in L:
    X = d[i]
    if X < i:
        res += X
    
    else:
        res += X - i

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter

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

d = Counter(A).most_common()
d = d[::-1]

reCounter = 0

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

Submission status: Accepted

Solution code:
from collections import Counter

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

mycounter = Counter(A)
count = 0
for item in mycounter.items():
    if item[0] < item[1]:
        count += item[1] - item[0]
    elif item[1] < item[0]:
        count += item[1]

print(count)

Submission status: Accepted

Solution code:
n = int(input())
userIn = input().split()
a = [0 for i in range(2*n+1)]
deleteCounter = 0

for j in userIn:
    if int(j) > n:
        deleteCounter += 1
    else:
        a[int(j)] += 1

for j in range(n+1):
    if a[j] != 0:
        if a[j] >= j:
            deleteCounter += a[j] - j
        else:
            deleteCounter += a[j]

print(deleteCounter)

Submission status: Accepted

Solution code:
from collections import Counter as C

N = int(input())
S = list(int(i) for i in input().split())
count = 0

for key, value in C(S).items():
    if key < value:
        count += (value-key)
    elif key > value:
        count += value

print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = list(int(i) for i in input().split())  
dict = {}
count = 0

for i in range(N):
    if S[i] not in dict:
        dict[S[i]] = 1
    else:
        dict[S[i]] += 1

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

print(count)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(a)

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

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