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: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil

n = ni()
A = lma()
co = collections.Counter(A)
ans = 0
for num,cnt in co.items():
    if num<cnt:
        ans+=(num-cnt)
    if num>cnt:
        ans+=cnt
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int,input().split()))
dicta={}
ans=0
for i in arr:
    dicta[i] = dicta.get(i,0)+1
for key,value in dicta.items():
    if key == value:
        continue
    else:
        diff = abs(key-value)
        ans+=diff

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))
dic,cnt={},0
for i in arr:
    dic[i]=dic.get(i,0)+1
for i in dic:
    if dic[i]!=i:
        cnt+=min(abs(dic[i]-i),dic[i])
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def rem(a,M):
    for i in range(M.count(a)):
        M.remove(a)
    return M
a=int(input())
A=[int(x) for x in input().split()]
m=0
for i in A:
    v=A.count(i)
    if v==i:
        pass
    else:
        m+=1
        A.remove(i)
print(m)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
N = int(input())
A = list(map(int, input().split()))

C = collections.Counter(A)
ans = 0
for v, c in C.items():
    ans += min(abs(c-v), c)
print(ans)

Submission status: Wrong Answer

Solution code:
hm={}
n=int(input())
ans=n
arr=[int(i) for i in input().split()]
for i in arr:
    hm[i]=hm.get(i,0)+1
print(hm)
for i in hm:
    if hm[i]!=i:
        if hm[i]>i:
            ans-=hm[i]-i
        else:
            ans-=hm[i]
print(n-ans)

Submission status: Wrong Answer

Solution code:
hm={}
n=int(input())
ans=0
arr=[int(i) for i in input().split()]
for i in arr:
    hm[i]=hm.get(i,0)+1
# print(hm)
for i in hm:
    if hm[i]==i:
        ans+=i
print(n-ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

occ = {}
for i in range(n):
    if a[i] not in occ:
        occ[a[i]] = 0
    occ[a[i]] += 1

res = 0
for x in occ:
    if (occ[x] < x):
        res += occ[x]
    else:
        print(x, occ[x] - x)
        res += occ[x] - x

print(res)

Submission status: Wrong Answer

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

occ = {}
for i in range(n):
    if a[i] not in occ:
        occ[a[i]] = 0
    occ[a[i]] += 1

res = 0
for x in occ:
    if (occ[x] < x):
        res += x
    else:
        res += occ[x] - x

print(res)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(A)
cs = sorted(c.items(), key=lambda x:x[0])
cnt = 0
for i in range(len(cs)):
    if(cs[i][0] != cs[i][1]):
        if(cs[i][0] < cs[i][1]):
            cnt += cs[i][1]-cs[i][0]
        else:
            cnt += cs[i][1]

if(N==1):
    print(0)
else:
    print(cnt)

Submission status: Wrong Answer

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

a.sort()

good_val = 0
total_cnt = 0
tmp_cnt = 0
over = 0
for i in range(n):
  if good_val == 0:
    good_val = a[i]

  if a[i] == good_val:
    tmp_cnt += 1
    if over == 0 and tmp_cnt == good_val:
      tmp_cnt = 0
      over = 1
    if i == n - 1:
      total_cnt += tmp_cnt
  else:
    total_cnt += tmp_cnt
    good_val = a[i]
    tmp_cnt = 1
    over = 0

print(total_cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)#n
c=[x for x in set(b) if b.count(x) > 0]
kosuu_list=[]
kosuu=1
for i in range(len(b)-1):
    #kosuu=0
    #print(b[i])
    if b[i]==b[i+1]:
        kosuu+=1
    else:
        kosuu_list.append(kosuu)
        kosuu=1
kosuu_list.append(b.count(b[-1]))

count=0
for i in range(len(c)):
    if kosuu_list[i]==c[i]:
        count+=0
    elif kosuu_list[i]>=c[i]:
        count+=kosuu_list[i]-c[i]
    else:
        count+=kosuu_list[i]
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
a = collections.Counter(a)
a = a.most_common()
ans = 0
for i in range(len(a)):
  if a[i][0] >= a[i][1]:
    ans += a[i][0] - a[i][1]
  else:
    ans += a[i][1]
    
print(ans)

Submission status: Wrong Answer

Solution code:
n= int(input())
a = list(int(i) for i in input().split())
a2 = list(set(a))
ans = 0
for i in a2:
   ans += min(a.count(i),max(0,abs(i-a.count(i))))
print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    if (a[i] in nlis)==False:
        nlis[a[i]]=1
    else:
        nlis[a[i]]+=1
ans=0
for i in nlis:
    if nlis[i]<i:
        ans+=i
    else:
        ans+=min(abs(nlis[i]-i),nlis[i])
print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    if (a[i] in nlis)==False:
        nlis[a[i]]=1
    else:
        nlis[a[i]]+=1
ans=0
for i in nlis:
    ans+=min(abs(nlis[i]-i),nlis[i])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
l.sort()
l.append(0)
ans = 0
j = 0
for i in unique_l:
    cnt = 0
    while l[j] == i and j < N:
        cnt += 1
        j += 1
    if cnt == i:
        pass
    elif cnt > i:
        ans += cnt - i
    elif cnt < i:
        ans += cnt
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
l.sort()
l.append(0)
ans = 0
j = 0
for i in unique_l:
    cnt = 0
    while l[j] == i and j < N:
        cnt += 1
        j += 1
    if cnt == i:
        pass
    elif cnt > i:
        ans += cnt - 1
    elif cnt < i:
        ans += cnt
print(ans)

Submission status: Wrong Answer

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

if __name__ == '__main__':
  N = int(input())
  a = list(map(int, input().split()))

  if len(a) == 0:
    print(0)
  elif a.count(0) >= int(len(a) / 2):
    print(len(a) - a.count(0))
  else:
    count = 0
    temp = ['']
    for i in a:
      if i > a.count(i) and i not in temp:
        count += a.count(i)
      elif i < a.count(i) and i not in temp:
        count = count + a.count(i) - i
      else:
        pass
      temp.append(i)
    print(count)

Submission status: Wrong Answer

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

if __name__ == '__main__':
  N = int(input())
  a = list(map(int, input().split()))

  if len(a) == 0:
    print(0)
  elif a.count(0) >= int(len(a) / 2):
    print(len(a) - a.count(0))
  else:
    count = 0
    for i in a:
      if i > a.count(i):
        count += a.count(i)
      elif i < a.count(i):
        count = a.count(i) - i
      else:
        pass
    print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in set(a):
    count += min(a.count(i), abs(a.count(i) - i))
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = input()
xs = [int(c) for c in input().split()]
c = Counter(xs)
ans = 0
for x, cnt in c.items():
  ans += cnt if x < cnt else (x - cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
length = input()
nums = input().split(" ")

numdict = {}
for i, num in enumerate(nums):
	if num not in numdict:
		numdict[str(num)] = 1
	else:
		numdict[str(num)] += 1

ret = 0
for k,v in numdict.items():
	if int(k) > int(v):
		ret += int(k) - int(v) 
	else:
		ret += int(v) - int(k)

print(ret)

Submission status: Wrong Answer

Solution code:
from collections import *
input()
a = Counter(map(int, raw_input().split()))
z = 0
for i in a:
	z += a[i] % i
print z

Submission status: Wrong Answer

Solution code:
import sys,binascii
if binascii.crc32((sys.stdin.read()+"  "*1).encode("utf-8"))&1:
    print("Yes")  
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys,binascii
if binascii.crc32((sys.stdin.read()+"  "*0).encode("utf-8"))&1:
    print("Yes")  
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())

d = {}
A = [int(x) for x in input().split()]
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

ans = 0
for k, v in d.items():
    ans += min(v, abs(k - v))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N=int(input())
A=list(map(int,input().split()))
A.sort()
ans=0
current=A.pop()
num=1
if len(A)==0:
  if num<current: ans+=num
  else: ans+=num-current
while A:
  if A[-1]==current:
    num+=1
    current=A.pop()
    if len(A)==0:
      if num<current: ans+=num
      else: ans+=num-current
  else:
    if num<current: ans+=num
    else: ans+=num-current
    current=A.pop()
    num=1
print(ans)

Submission status: Wrong Answer

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

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string

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

Submission status: Time Limit Exceeded

Solution code:
num=int(input())
main=list(map(int,input().split()));index=0;valor=1;test=[];temp=1;rpta=0
for i in range(len(main)-1):
    if(main[i] not in test):
        test.append(main[i])
        while(valor!=len(main)):
            if(main[index]==main[valor]):
                temp=temp+1
            valor=valor+1
        if(main[index]>temp):
            rpta=temp+rpta
        elif(temp>main[index]):
            rpta=(temp-main[index])+rpta
    index=index+1
    valor=index+1
    temp=1
    
if(main[len(main)-1] not in test):
    if(main[len(main)-1]==1):
        rpta=rpta
    elif(main[len(main)-1]>1):
        rpta=rpta+1
print(rpta)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
mi = a
br = set(ar)
count = 0
for r in br:
    if r > ar.count(r):
        count += ar.count(r)
    elif r < ar.count(r):
        count += ar.count(r) - r
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=list(map(int,input().split()))
yoso=list(set(a))
count=0
for i in range(0,len(yoso)):
    acount=a.count(yoso[i])
    if yoso[i]>acount:
        count+=acount
    elif yoso[i]<acount:
        count+=(acount-yoso[i])
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

a = set(A)

con = 0

for i in a:
  n = A.count(i)
  if i > n:
    con += n
  elif i < n:
    con += (n - i)
    
print(con)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
c=set(a)
count=0
for i in c:
    if b.count(i)==i:
       count+=0
    elif b.count(i)>=i:
       count+=b.count(i)-i
    else:
       count+=b.count(i)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = list(map(int,input().split()))
set = []
for l in li:
  if set.count(l) == 0 :
    set.append(l)
result = 0
for l in set:
  if li.count(l) == l:
    continue
  elif li.count(l) < l:
    limit = li.count(l)
    result += limit
  elif li.count(l) > l:
    limit = li.count(l) - l
    result += limit

print(result)

Submission status: Time Limit Exceeded

Solution code:
n= int(input())
a = list(int(i) for i in input().split())
a2 = list(set(a))
ans = 0
for i in a2:
  tmp = a.count(i)
  if tmp <i:
   ans += tmp
  else:
   ans += (tmp-i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n= int(input())
a = list(int(i) for i in input().split())
a2 = list(set(a))
ans = 0
for i in a2:
  if a.count(i) <i:
   ans += a.count(i)
  else:
   ans += (a.count(i)-i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
ans = 0
for i in unique_l:
    cnt = l.count(i)
    if cnt==i:
        pass
    elif cnt > i:
        ans += cnt - i
    elif cnt < i:
        ans += cnt
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = list(map(int, input().split()))
N_MAX =  int(1e+9 + 1)
cnt = [0 for _ in range(N_MAX)]
for i in l:
    cnt[i] += 1
ans = 0
for idx, val in enumerate(cnt):
    if val == 0 or val == idx:
        pass
    elif val < idx:
        ans += val
    elif idx < val:
        ans += val - idx
print(ans)

Submission status: Time Limit Exceeded

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

a.sort()

count = 0

while a:
    k = a.pop(0)
    k_count = 1
    while (len(a) > 0) and (a[0] == k):
        a.pop(0)
        k_count += 1
    if k_count < k:
        count += k_count
    else:
        count += k_count - k
print(count)

Submission status: Time Limit Exceeded

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

removals = 0
for i in set(a):
    c = a.count(i)
    if c>i:
        removals += c-i
    elif c<i:
        removals += c
print(removals)

Submission status: Time Limit Exceeded

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

a_unique = list(set(a_list))
count = 0
ans = 0

for a in a_unique:
	count = a_list.count(a)
	if count >= a:
		ans += count - a
	else:
		ans += count

print(ans)

Submission status: Time Limit Exceeded

Solution code:
input()
inp=list(map(int,input().split(" ")))
inp.sort()
ins=set(inp)
def ncnt(i,j):
 n=i.index(j)
 nn=list(reversed(i)).index(j)
 return len(i)-n-nn

cnt=0
for i in ins:
 nc=ncnt(inp,i)
 if i>nc:
  cnt+=nc
 else:
  cnt+=nc-i
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
count = 0
if (N==0):
  count = 0
else:
  a = []
  a = list(map(int, input().split()))
  a.sort()
  a.reverse()
  i = 0
  while int(a[0]) > N:
    del a[0]
    i += 1
    if(len(a)==0):
      break
  if(len(a)>0):
    k = int(a[0])
    while k > 0:
      b = a.count(k)
      if (b < k):
        i += b
      elif(b > k):
        i += b - k
      k -= 1
  count = i
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = list(set(a))
ans = 0
for i in s:
    if i > a.count(i):
        ans += a.count(i)
    else:
        ans += a.count(i) - i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
cnt = 0
S = 0
for i in range(100000):
    tmp = a.count(i + 1)
    S += tmp
    if tmp > i + 1:
        cnt += tmp - i - 1
    elif tmp < i + 1:
        cnt += tmp
cnt += N - S
print(cnt)

Submission status: Accepted

Solution code:
# author:  Taichicchi
# created: 28.09.2020 23:14:40

import sys
from collections import Counter


n = int(input())

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

ans = 0

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

print(ans)

Submission status: Accepted

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

count = Counter(a)

cnt = 0
for i in count.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=int(input())
A=list(map(int,input().split()))
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########
ans=0
C=Counter(A)
for i,v in C.items():
    if i>v:
        ans+=v
    if i<v:
        ans+=v-i
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
d = Counter(A)
res = 0
for elem, cnt in d.items():
    if cnt-elem>=0:
        res += cnt-elem
    else:
        res += cnt
print(res)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
nums = Counter(map(int, input().split()))
cnt = 0
for key, value in nums.items():
    if key > value:
        cnt += value
    elif key < value:
        cnt += value - key
    else:
        continue
print(cnt)

Submission status: Accepted

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

cs = collections.Counter(a)
# print('cs:',cs)

out=0
for key in cs:
    # print( 'key,cs[key]:',key,cs[key])
    if cs[key] > key:
        out+= cs[key] - key
    elif cs[key] < key:
        out+= cs[key]
    # print('out:',out)

print(out)

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil

n = ni()
A = lma()
co = collections.Counter(A)
ans = 0
for num,cnt in co.items():
    if num<cnt:
        ans+=(cnt-num)
    if num>cnt:
        ans+=cnt
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()
    dct = defaultdict(lambda: 0)

    for a in A:
        dct[a] += 1

    ans = 0
    for key, val in dct.items():
        if key == val:
            continue
        elif key < val:
            ans += val - key
        else:
            ans += val

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

b = set(a)
c = Counter(a)
ans = 0

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

Submission status: Accepted

Solution code:
import collections
N = int(input())
a = list(map(int,input().split()))
ans = 0
c = collections.Counter(a)
for i,j in zip(c.keys(),c.values()):
    if(j>i):
        ans += j-i
    elif(j==i):
        pass
    else:
        ans += j
print(ans)

Submission status: Accepted

Solution code:
n = len(input())
mp, res = {}, 0
for el in list(map(int, input().split())): mp[el] = mp.get(el, 0) + 1
for key in mp:
    val = mp[key]
    if key > val: res += val
    elif key < val: res += val - key
print(res)

Submission status: Accepted

Solution code:
n = int(input())
list_val = [int(val) for val in input().split()]
if len(list_val)<1:
  print(0)
dict_val = {}
count=0
for i in range(n):
  dict_val[list_val[i]] = dict_val.get(list_val[i],0)+1
for key, values in dict_val.items():
  if key>values:
    count+=values
  elif key<values:
    count+=values-key
print(count)

Submission status: Accepted

Solution code:
n = int(input())
arr = list(map(int,input().split()))
dicta={}
ans=0
for i in arr:
    dicta[i] = dicta.get(i,0)+1

for key,value in dicta.items():
    if key == value:
        continue
    elif key > value:
        ans+=value
    else:
        diff = abs(value-key)
        ans += diff

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
dic,cnt={},0
for i in arr:
    dic[i]=dic.get(i,0)+1
for i in dic:
    if dic[i]>i:
        cnt+=dic[i]-i
    elif dic[i]<i:
        cnt+=dic[i]
print(cnt)

Submission status: Accepted

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

d = defaultdict(int)

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

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

Submission status: Accepted

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

d = defaultdict(int)

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = sorted(map(int,input().split()))
c = collections.Counter(a)
ans = 0

for i in c.keys():
    if i == 0:
        pass
    if i < c[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(map(int, input().split()))

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

Submission status: Accepted

Solution code:
from collections import Counter
_, *lst = map(int, open(0).read().split())
c = Counter(lst)
res = 0
for i, j in c.items():
  if i == j:
    continue
  elif i > j:
    res += j
  else:
    res += j - i
print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections
N = int(input())
A = list(map(int, input().split()))

C = collections.Counter(A)
ans = 0
for v, c in C.items():
    if v > c:
        ans += c
    else:
        ans += c-v
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
n  = int(input())
#  = map(int, input().split())
a  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
c = collections.Counter(a)

ans = 0

for c_ in c.items():
    if c_[0] > c_[1]:
        ans += c_[1]
    elif c_[0] < c_[1]:
        ans += c_[1] - c_[0]

print(ans)

Submission status: Accepted

Solution code:
import collections
a = int(input())
ar = list(map(int,input().split(" ")))
br = collections.Counter(ar)
cr = set(ar)
count = 0
for r in cr:
    if br[r] < r:
        count += br[r]
    elif br[r] >= r:
        count += br[r] - r
print(count)

Submission status: Accepted

Solution code:
import collections
N=int(input())
a=list(map(int,input().split()))
b=collections.Counter(a)
c=list(set(a))
count=0
for i in range(0,len(c)):
    if b[c[i]]>=c[i]:
        count+=b[c[i]]-c[i]
    else:
        count+=b[c[i]]
print(count)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
dict=Counter(a)
ans=0
for k,v in dict.items():
    if v>=k:
        ans+=v-k
    else:
        ans+=v

print(ans)

Submission status: Accepted

Solution code:
#!python3

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


def main():
    d = {}
    for a in A:
        if a in d:
            d[a] += 1
        else:
            d[a] = 1
    
    ans = 0
    for key, value in d.items():
        if key > value:
            ans += value
        else:
            ans += value - key
    
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
hm={}
n=int(input())
ans=n
arr=[int(i) for i in input().split()]
for i in arr:
    hm[i]=hm.get(i,0)+1
for i in hm:
    if hm[i]!=i:
        if hm[i]>i:
            ans-=hm[i]-i
        else:
            ans-=hm[i]
print(n-ans)

Submission status: Accepted

Solution code:
import random, math
from copy import deepcopy as dc
from bisect import bisect_left, bisect_right



# Function to call the actual solution
def solution(li):
	ma = {}
	for i in li:
		ma[i] = ma.get(i, 0) + 1
	s = 0
	for i in ma:
		if i != ma[i]:
			if ma[i] > i:
				s += ma[i] - i
			else:
				s += ma[i]
	return s


# Function to take input
def input_test():
	# for _ in range(int(input())):
		n = int(input())
		# a, b = map(int, input().strip().split(" "))
		# a, b, c = map(int, input().strip().split(" "))
		li = list(map(int, input().strip().split(" ")))
		out = solution(li)
		print(out)

# Function to check test my code
def test():
	pass


input_test()
# test()

Submission status: Accepted

Solution code:
N = int(input())

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

cnt = {}

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

occ = {}
for i in range(n):
    if a[i] not in occ:
        occ[a[i]] = 0
    occ[a[i]] += 1

res = 0
for x in occ:
    if (occ[x] < x):
        res += occ[x]
    else:
        res += occ[x] - x

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(A)
cs = sorted(c.items(), key=lambda x:x[0])
cnt = 0
for i in range(len(cs)):
    if(cs[i][0] != cs[i][1]):
        if(cs[i][0] < cs[i][1]):
            cnt += cs[i][1]-cs[i][0]
        else:
            cnt += cs[i][1]
print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
cnt_dic=defaultdict(int)
for i in a:
  cnt_dic[i]+=1
cnt=0
for v in cnt_dic.keys():
  if cnt_dic[v]==v:
    pass
  else:
    if cnt_dic[v]<v:
      cnt+=cnt_dic[v]
    else:
      cnt+=(cnt_dic[v]-v)
print(cnt)

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter
get_string = lambda: sys.stdin.readline().strip()
get_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
get_int = lambda: int(sys.stdin.readline())

#----------------------------------------------------------------------#

n=get_int()
a=get_list()
freq=Counter(a)
ans=0
for key,val in freq.items():
    if val>key:
        ans+=val-key
    elif key>val:
        ans+=val
print(ans)

Submission status: Accepted

Solution code:
len_nums = int(input())
nums = input().split()

dic = {}
for num in nums:
	if num in dic:
		dic[num] += 1
	else:
		dic[num] = 1

count_to_be_removed = 0
for key, value in dic.items():
	key = int(key)
	# keyがvalue個あるような数列。key=valueになるように取り除く
	if key <= value:
		count_to_be_removed += value - key
	else:
		count_to_be_removed += value

print(count_to_be_removed)

Submission status: Accepted

Solution code:
import os
import sys
from collections import Counter

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

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

ans = 0
for n, cnt in Counter(A).items():
    if cnt >= n:
        ans += cnt - n
    else:
        ans += cnt
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)