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:
from collections import Counter

ignore = int(raw_input())
k = dict(Counter(map(int, raw_input().split())))
copyk = list(set(k))
counter = 0
for i,j in k.items():
    if i > j:
        counter += j
    elif i < j:
        counter += j - i

print counter

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 num, kosu in C.items():
    if num > kosu:
        ans += kosu
    else:
        ans += kosu - num
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
cnt=[int(i) for i in input().split()]
dict={}
for i in range(len(cnt)):
  if cnt[i] in dict:
    dict[cnt[i]]+=1
  else:
    dict[cnt[i]]=1

ans=0
for j,k in dict.items():
  if int(j)>k:
    ans+=k
  else:
    ans+=k-int(j)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = list(map(int, input().split()))

dic = {}
for elem in a:
    if elem not in dic:
        dic[elem] = 1
    else:
        dic[elem] += 1

cnt = 0
for k in dic.keys():
    if dic[k] > k:
        cnt += dic[k]-k
    elif dic[k] < k:
        cnt += dic[k]

print(cnt)

Submission status: Accepted

Solution code:



n = int(input())
xs = map(int, input().split())

mp = dict()

for x in xs:
    if x in mp:
        mp[x] = mp[x] + 1
    else:
        mp[x] = 1

res = 0
for x in mp.keys():
    v = mp[x]
    if v < x:
        res += v
    else:
        res += v - x

print(res)

Submission status: Accepted

Solution code:
# C - Good Sequence
# coding: utf-8

from collections import Counter

N = int(raw_input())
a = map(int, raw_input().split())
result = 0
cnt = Counter()

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

for x, y in cnt.items():
  result += y if x>y else y-x

print result

Submission status: Accepted

Solution code:
import math
import itertools
import heapq
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_I(): return map(int, stdin)
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))

##### main #####



def main():
	n = I()
	A = LI()
	d=defaultdict(lambda: 0)
	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)




if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d=defaultdict(int)
for b in a:
    d[b] +=1

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

print(c)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
i = 0
a = sorted(a)
b = []
num = 0
ins = 1
while i < len(a):
    while ins == a[i]:
        num += 1
        if ins == num:
            b.append(ins)
        i += 1
        if len(a) == i:
            break
    if len(a) != i:
        ins = a[i]
    i += 1
    num = 1
print(len(a)-sum(b))

Submission status: Accepted

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

answer=0
count_sum=0

counter = Counter(a)
for num, cnt in counter.most_common():
#  print (num, cnt)
  count_sum+=cnt
  if cnt>num:
    answer += cnt-num
  elif cnt<num:
    answer += cnt
answer+=N-count_sum
print(answer)

Submission status: Accepted

Solution code:
N = int(input())

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

place = {}
counter = 0

for i in series:
    if i not in place:
        place[i] = 0
    place[i] += 1
    
for j in place.keys():
    if place[j] > j:
        counter += place[j] - j
    elif j > place[j]:
        counter += place[j]
        
print(counter)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# coding=utf-8

import collections
import sys

n = sys.stdin.readline().strip()
a = sys.stdin.readline().strip().split(" ")
a_count = collections.Counter(a)
ans = 0
for k, v in a_count.items():
    if int(k) > v:
        ans += v
    else:
        ans += v - int(k)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
N = int(input())
a_i = list(map(int, input().split()))
c = Counter(a_i)
rtn = 0
for a,cnt in c.items():
    if cnt > a:
        rtn += cnt-a
    elif cnt < a:
        rtn += cnt
print(rtn)

Submission status: Accepted

Solution code:
N = int(input())
a = input().split()
list_a = list(a)
d = dict()
for i in range(len(list_a)):
    d[list_a[i]] = 0

for i in range(len(list_a)):
    d[list_a[i]] += 1

sum = 0
for item in d:
    key = int(item)
    val = d[item]
    if key > val:
        sum += val
    elif key < val:
        sum += val - key

print(sum)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
i = 0
ans = 0
while i < n:
    head = a[i]
    if head + i - 1 >= n:
        ans += n - i
        break
    if a[head+i-1] != a[i]:
        while i < n and head == a[i]:
            i += 1
            ans += 1
    else:
        i += head
        while i < n and head == a[i]:
            i += 1
            ans += 1

print(ans)

Submission status: Accepted

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

def count(num, counter_list):
    if len(counter_list) == 0:
        counter_list.append([num, 0])
    current = counter_list[-1]     
    if current[0] == num:
        current[1] += 1
    else:
        counter_list.append([num, 1])

def calc(list):
    result = 0
    for item in list:
        cmp_count = item[1] - item[0]
        result += cmp_count if cmp_count >= 0 else item[1]
    return result

def main():
    A.sort()
    counter_list = []
    for i in range(N):
        count(A[i], counter_list)
    ans = calc(counter_list)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())

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

counter = Counter(numList)

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

n_dic = {str(i):0 for i in set(numbers)}


for i in numbers:
    n_dic[str(i)] += 1
  
count = 0

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

Submission status: Accepted

Solution code:
n,*A=map(int,open(0).read().split());B={}
for a in A:B[a]=B.get(a,0)+1
print(sum(B[b]-b*(B[b]>=b)for b in B))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from collections import Counter

N = input()
counts = Counter(map(int, input().split()))

removes = 0
for num, occr in counts.items():
    if num > occr:
        removes += occr
    elif num < occr:
        removes += occr-num

print(removes)

Submission status: Accepted

Solution code:
N = int(input())
alist = input().split()
count = [0 for i in range(100001)]
for a in alist:
	a = int(a)
	if a<100001:
		count[a]+=1
good = 0
for i in range(100001):
	if count[i] >= i:
		good += i
print(N-good)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
ans = 0
dic = {}

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

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

print(ans)

Submission status: Accepted

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

N = int(input())
an = map(int, input().split())

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

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

print(count)

Submission status: Accepted

Solution code:
from collections import Counter

_ = int(input())
nl = list(map(int, input().split()))

cnt = Counter(nl)

ans = 0
for w, c in cnt.most_common():
    if w > c:
        ans += c
    elif w < c:
        ans += c - w

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    _ = input()
    
    n_dic = defaultdict(lambda: 0)
    for x in input().split():
        n_dic[int(x)] += 1

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
d={}
for a in input().split():
    if a in d:
        d[a]+=1
    else:
        d[a]=1
print(sum([y if int(x)>y else y-int(x) if int(x)<y else 0 for x,y in d.items()]))

Submission status: Accepted

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

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

# dictの初期化
numbers_count = {}
# for i in numbers:
for i in numbers:
    numbers_count[i] = 0 

# 数値別の集計
for i in a:
    numbers_count[i] += 1

# 取り除く数を算出
remove=0
for i in numbers:
    # 3が2つある
    if(i > numbers_count[i]):
        remove += numbers_count[i]
    # 3が4つある
    elif(i < numbers_count[i]):
        remove += numbers_count[i] - i

print(remove)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

print(ans)

Submission status: Accepted

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

n = int(input())
a = list(map(int,input().split()))
counter = Counter(a)
ans = 0
for i in counter:
    if(i != counter[i]):ans += counter[i] if counter[i] < i else counter[i]-i
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
N=input()
A=input().split(' ')
dict={}
for i in A:
    if i not in dict.keys():
        dict[i]=1
    else:
        dict[i]+=1
count=0
for k,v in dict.items():
    k=int(k)
    v=int(v)
    if v<k:
        count+=v
    else:
        count+=v-k
print(count)

Submission status: Accepted

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

d = {}

ans=0

for i in range(N):
    if a[i] in d.keys():
        d[a[i]]+=1
        ans+=1
        if d[a[i]] == a[i]:
            ans-=a[i]
    else:
        d[a[i]] = 1
        ans+=1
        if a[i] == 1:
            ans-=1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
ans = 0
for tmp in list(set(a)):
    if b[tmp] > tmp:
        ans += b[tmp]-tmp
    elif b[tmp] < tmp:
        ans += b[tmp]
    else:
        continue
else:
    print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 19 16:13:34 2017

@author: kotania
"""
 
from collections import Counter

N = int(input())
aList = input().split()

aList.sort()

countDict = Counter(aList)

delsum = 0    

for k,v in countDict.items():
    if int(k) < v:
        delsum += v - int(k)
    elif int(k) > v:
        delsum += v

print (delsum)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    l = list(map(int,input().split(" ")))
    dic = {}
    count = 0
    for i in l:
        try:
            dic[i] += 1
        except Exception:
            dic[i] = 1

    for j in dic.items():
        count += j[1] - j[0] if j[1] >= j[0] else j[1]
    print(count)


if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter
N = raw_input()
A = raw_input().split()

cnt = Counter()
for num in A:
    cnt[str(num)] += 1

answer = 0
for x, y in cnt.items():
    x = int(x)
    if x < y:
        answer += (y-x)
    elif x > y:
        answer += y
print answer

Submission status: Accepted

Solution code:
N = int(input())
list = [int(a) for a in input().split()]
dict = dict()
for i in range(N):
    if list[i] in dict:
        dict[list[i]] += 1
    else:
        dict[list[i]] = 1
count = 0
for i, j in dict.items():
#    print(i, j) 
    if i <= j:
        count += j - i
    else:
        count += j
              
print(count)

Submission status: Accepted

Solution code:
#abc082c
import collections

n=int(raw_input())
s=map(int,raw_input().split())
cnt=collections.Counter(s)
temp=0
for k,v in cnt.items():
 if k<=v:
  temp+=k
print len(s)-temp

Submission status: Accepted

Solution code:
d = dict()
n = int(input())
a = list(map(int,input().split()))
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
r = 0
for k,v in d.items():
    if k < v:
        r += v-k
    elif k > v:
        r += v
print(r)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = input()
str = input()
nums = str.split()
num_dict = {}
for num in nums:
    if num in num_dict:
        num_dict[num] += 1
    else:
        num_dict[num] = 1
result = 0
for k, v in num_dict.items():
    if int(k) > v:
        result += v
    elif int(k) < v:
        result += (v - int(k))

print(result)

Submission status: Accepted

Solution code:
# coding:utf-8                                                                  

from collections import defaultdict

N = int(raw_input())
As = map(int, raw_input().split())

dic = defaultdict(lambda:0)
for a in As:
    dic[a] += 1

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

print count

Submission status: Accepted

Solution code:
N = input()
a = list(map(int, input().split()))
dict = {}
count = 0

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

for i in dict.keys():
    if dict[i] < i:
        count += dict[i]
    else:
        count += dict[i] - i

print(count)

Submission status: Accepted

Solution code:
import numpy as np
from collections import Counter
import collections
a = list(map(int,input().split()))
b = list(map(int,input().split()))
#値を大きさ順に並べる
b = sorted(b)
l = Counter(b)
Num = 0
for k,v in l.items():
  if v-k>=0 :
  	Num += v-k
  else:
    Num += v 
print(Num)

Submission status: Accepted

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

res = 0
counter = Counter(a)
for i in set(a):
	if counter[i] < i:
		res += counter[i]
	else:
		res += counter[i] - i

print(res)

Submission status: Accepted

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

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

res = 0
for key, value in cnt.items():
	if key < value:
		res += value - key
	elif key > value:
		res += value

print(res)

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 set(a):
    if counter[i] < i:
        ans += counter[i]
    else:
        ans += counter[i] - i
print(ans)

Submission status: Accepted

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

dicta = {'0':0}

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

ke = list(dicta.keys())
va = list(dicta.values())
ans = 0


for i in range(len(ke)):
    if int(ke[i])>va[i]:
        ans+= va[i]
    else :
        ans += va[i]-int(ke[i])

print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8

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

    ans = 0
    bin = {}
    for a in a_list:
        if a not in bin:
            bin[a] = 1
        else:
            bin[a] += 1
        if bin[a] > a:
            ans += 1
    for k in bin.keys():
        if bin[k] < k:
            ans += bin[k]
    
    print ans
        

if __name__=="__main__":
    main()

Submission status: Accepted

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

N = int(input())
a = sorted(list(map(int, input().split())))
a.append(-1)

ans = 0
pre = 0
count = 0
for n in a:
    if n == pre or pre == 0:
        count += 1
    else:
        if count >= pre:
            ans += count - pre
        else:
            ans += count
        count = 1
    pre = n
print(ans)

Submission status: Accepted

Solution code:
inputs = int(input())
line = raw_input().split()

nums = [int(i) for i in line]

map_ = {}

for num in nums:
    if num not in map_:
        map_[num] = 0
    map_[num] += 1

count = 0
for key, item, in map_.iteritems():
    if item < key:
        count += item
    else:
        count += (item - key)

print count

Submission status: Accepted

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

bucket = {}

for i in sort_a:
    if i not in bucket:
        bucket[i] = 1
    else:
        bucket[i] += 1

delete = 0
for key, value in bucket.items():
    if key < value:
        delete += value - key
    elif key > value:
        delete += value

print(delete)

Submission status: Accepted

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


from collections import defaultdict
d = defaultdict(int)


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

#print(d)

ans = 0
for i in d.keys():
	x = d[i]
#	print(i, x)
	if x == i: continue
	if x < i: ans += x
	if x > i: ans += (x - i)

#print(d)
print(ans)

Submission status: Accepted

Solution code:
from itertools import groupby
n, s = input(), sorted(map(int, raw_input().split()))
v, ans = [(i, len(list(t))) for i, t in groupby(s)], 0
for i, t in v:
    if i != t:
        ans += ((t - i) if i < t else t)
print ans

Submission status: Accepted

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

z = {}
for i in a:
    try:
        z[i] += 1
    except KeyError:
        z[i] = 1

ans = 0
for q in z.keys():
    if z[q] > q:
        ans += z[q] - q
    elif z[q] < q:
        ans += z[q]

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 set(a):
    if counter[i] < i:
        ans += counter[i]
    else:
        ans += counter[i] - i
print(ans)

Submission status: Accepted

Solution code:
from itertools import groupby
n, s = input(), sorted(map(int, raw_input().split()))
v, ans = [(i, len(list(t))) for i, t in groupby(s)], 0
for i, t in v:
    if i == t:
        continue
    ans += ((t - i) if i < t else t)
print ans

Submission status: Accepted

Solution code:
import collections
N = int(input())
P = list(map(int,input().split()))
ans = 0
P.sort()
cnt = collections.Counter(P)
for i in cnt:
    s = cnt[i]
    if s > i:
        t =  s - i
        ans += t
    elif s < i:
        ans += s
print(ans)

Submission status: Accepted

Solution code:
a=input()
b=map(int,raw_input().split())
b.sort()
c=[]
d=[]
max=0
loc=-1
for i in b:
    if max!=i:
        c.append(i)
        d.append(1)
        max=i
        loc+=1
    else:
        d[loc]+=1
ans=0
for i in range(len(c)):
    if c[i]>d[i]:
        ans+=d[i]
    elif c[i]<d[i]:
        ans+=d[i]-c[i]

print ans

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = map(int,input().split(" "))

x = {}

for i in a:
    if i not in x:
        x[i] = 0
    x[i] = x[i]+1

out = 0
for k in x:
    v = x[k]
    if v < k:
        out = out + v
    if v > k:
        out = out + v - k

print(out)

Submission status: Accepted

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

dic = {}

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

ans = 0
    
for x in dic:
  #print x,dic[x]
  if x > dic[x]:
    ans += dic[x]
  elif x < dic[x]:
    ans += (dic[x]-x)

print ans

Submission status: Accepted

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

res = 0

find = a[0]
cnt = {a[0]: 0}
for v in a:
  if v not in cnt:
    cnt[v] = 0
  cnt[v] += 1

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

print(res)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
lis = list(map(int,input().split()))
c = dict(Counter(lis))
count = 0
for key,value in c.items():
  if key > value:
    count += value
  else:
    count += (value-key)
print (count)

Submission status: Accepted

Solution code:
N = int(input())
a = []
ainfo = []
astrs = input().split()
for astr in astrs:
    a.append(int(astr))
sorteda = sorted(a)



for pos in range(N):
    if pos == 0:
        ainfo.append([sorteda[pos], 1])
    else:
        if sorteda[pos]==sorteda[pos-1]:
            ainfo[-1][1] += 1
        else:
            ainfo.append([sorteda[pos], 1])

ans = 0
for i in ainfo:
    if i[1]<i[0]:#個数が足りないとき
        ans += i[1]
    elif i[1]>i[0]:#多いとき
        ans += i[1]-i[0]
    else:
        pass
print(ans)

Submission status: Accepted

Solution code:
def c_good_sequence(N, A):
    from collections import Counter
    count = Counter(A)  # 要素iが何回数列に登場したか
    ans = 0
    for k, v in count.items():
        if k == 1:
            if v == 1:
                continue
            else:
                ans += v - k
        elif k != v:
            ans += v % k
    return ans
  
N = int(input())
A = [int(_) for _ in input().split()]
print(c_good_sequence(N, A))

Submission status: Accepted

Solution code:
debug = False
if debug:
    a = [2, 7, 1, 8, 2, 8, 1, 8]
    a = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5]
    N = len(a)
else:
    N = int(input())
    a = list(map(int, input().split()))

assert len(a) == N
d = {}
for ai in a:
    if ai in d:
        d[ai] += 1
    else:
        d[ai] = 1
s = 0
for k, v in d.items():
    t = min(abs(k - v), v)
    t = 0
    if k > v:
        t = v
    elif k == v:
        pass
    else:
        t = v - k
    s += t

print(s)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import collections

N = int(input())
a = input().split(" ")

test = collections.Counter(a)
test_key = list(test.keys())
test_value = list(test.values())

ans = 0
for i in range(len(test_key)):
    if int(test_key[i]) > test_value[i]:
        ans += test_value[i]
    elif int(test_key[i]) < test_value[i]:
        ans += test_value[i] - int(test_key[i])

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

# print(n)
# print(a)

num = 0
for k, v in a.most_common():
    if k - v > 0:
        num += v
    else:
        num +=  v - k

print(num)

Submission status: Accepted

Solution code:
N = int(input())

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

A = sorted(A)
set_A = sorted(list(set(A)))

min_elim = 0
count = 0
sub_count = 0
index = 0

for element in set_A:
    for i in range(index, len(A)):
        if A[i] == element:
            count += 1
        else:
            index = i
            break
    if count > element:
        sub_count = count - element
    elif count < element:
        sub_count = count
    min_elim += sub_count
    count = 0
    sub_count = 0

print(min_elim)

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(a)
k = list(c.keys())
v = list(c.values())

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

print(count)

Submission status: Accepted

Solution code:
N=int(input())
a=[0 for i in range(N)]
st=input().split()
for i in range(N):
    a[i]=int(st[i])
aa=sorted(a)
count=0
nowp=aa[0]
aa.append(10**9+1)
nowcount=1
for i in range(1,N+1):
    if aa[i-1]==aa[i]:
        nowcount+=1
    else:
        nowp=aa[i]
        if nowcount<aa[i-1]:
            count+=nowcount
        else:
            count+=nowcount-aa[i-1]
        nowcount=1
print(count)

Submission status: Accepted

Solution code:
# coding: utf-8
from collections import Counter
input()
A = [int(x) for x in input().split()]
c = Counter(A)

remove = 0
for num, count in c.most_common():
    if count < num:
        remove += count
    else:
        remove += (count - num)
print(remove)

Submission status: Accepted

Solution code:
N = raw_input()
array = map(int, raw_input().split())

#print N, array

dic = {}

while len(array):
    key = array.pop(0)
    if key not in dic:
        dic[key] = 1
    else:
        dic[key] = dic[key] + 1

#print dic
#print len(dic)

reduce_num = 0

#while len(dic) > 0:
for key in dic:
    if dic[key] == key:
        pass
    elif dic[key] > key:
        reduce_num = reduce_num + dic[key] - key
    else:
        reduce_num = reduce_num + dic[key]
        
print reduce_num

Submission status: Accepted

Solution code:
n = input()
ns = list(map(int, input().split()))
nums = {}
for i in ns:
    if i not in nums:
        nums[i] = 1
    else:
        nums[i] += 1

count = 0

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


print(count)

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# coding: utf-8

import math

def slove(n, a):
    dict = {}
    for i in range(n):
        if a[i] in dict:
            dict[a[i]] += 1
        else:
            dict[a[i]] = 1

    count = 0
    for k,v in dict.items():
        if int(k) < v:
            count += (v - int(k))
        elif int(k) != v:
            count += v
    return count

if __name__ == "__main__":
    n = int(input())
    a = input().split()

    print(slove(n, a))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
counts = {}
ans = 0
for i in a:
  if not i in counts:
    counts[i] = 1
  else:
    counts[i] += 1

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

print(ans)

Submission status: Accepted

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

count = 0

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

print(count)

Submission status: Accepted

Solution code:
#coding:utf-8
import math

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

ans = {}
for b in a:
    if not b in ans:
        ans[b] = 1
    else:
        ans[b] += 1

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

Submission status: Accepted

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

ans=0

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

Submission status: Accepted

Solution code:
N = int(input())
ali = list(map(int,input().split()))
sali = sorted(ali)
now = None
num = []
suu = []
kari = 0 
for i in range(N):
    if sali[i] == now:
        kari += 1
    else:
        if kari > 0:
            suu.append(kari)
        kari = 1 
        num.append(sali[i])
        now = sali[i]
suu.append(kari)
kari = 0 
for i in range(len(suu)):
    if num[i] > suu[i]:
        kari += suu[i]
    elif num[i] < suu[i]:
        kari += suu[i] - num[i]
print(kari)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
#print(a)
num=[]
num2=[]
count=0
m=a[0]
k=0
ans=0

for i in range(n):
    if a[i]==m:
        count=count+1
    else:
        num.append(m)
        num2.append(count)
        count=1
        m=a[i]
    if i==n-1:
        num.append(m)
        num2.append(count)

for i in range(len(num)):
    if num2[i]-num[i]>0:
        ans=ans+num2[i]-num[i]
    elif num2[i]-num[i]<0:
        ans=ans+num2[i]
#print(num,num2)
print(ans)