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
def main():
    n = int(input())
    a = tuple(map(int, input().split()))
    ac = Counter(a)
    r = 0
    for ace in ac:
        if ac[ace] < ace:
            r += ac[ace]
        else:
            r += (ac[ace] - ace)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())

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

def thankyou():
    for k, v in a.items():
        if k > v:
            yield v
        else:
            yield v - k

print(sum(thankyou()))

Submission status: Accepted

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

ans = 0
c = {}
for i in s:
    if i not in c:
        c[i] = 1
    elif c[i] < i:
        c[i] += 1
    else:
        ans += 1

for k,v in c.items():
    if k != v:
        ans += v
print(ans)

Submission status: Accepted

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

import collections
c = collections.Counter(A)

A = sorted(set(A))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(A)
ans = 0
for k, v in c.items():
    if k == v:
        continue
    elif k < v:
        ans += v-k
    else:
        ans += v
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
n = ii()
A = iil()
c = Counter(A)

ans = 0

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

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
A = Counter(getList())

ans = 0
for i in A.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:
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    counter = Counter(A)
    ans = 0
    for a, c in counter.items():
        if c < a:
            ans += c
        else:
            ans += c - a
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

d = {}
for ai in a:
  if ai in d:
    d[ai] += 1
  else:
    d[ai] = 1
  
ans = 0
for key in d:
  if d[key] >= key:
    ans += (d[key] - key)
  else:
    ans += d[key]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d = defaultdict(int)
for ai in a:
  d[ai] += 1
  
ans = 0
for key in d:
  if d[key] >= key:
    ans += (d[key] - key)
  else:
    ans += d[key]
print(ans)

Submission status: Accepted

Solution code:
import collections
def solve(n, a_list):

    counter = collections.Counter()

    for i in a_list:
        counter[i] += 1

    ans = sum([v-k if k < v else v for k, v in counter.items() if k != v])

    return ans

if __name__ == "__main__":
    n = int(input())
    a_list = [int(i) for i in input().split()]
    print(solve(n, a_list))

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
cou=Counter(lis)
ans=0
for v in cou.keys():
    if cou[v]>=v:
        ans+=cou[v]-v
    else:
        ans+=cou[v]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
L = sorted(map(int, input().split()))
d = {}
for i in range(n):
    if L[i] not in d:
        d[L[i]] = 1
    else:
        d[L[i]] += 1
cnt = 0
for k, v in d.items():
    if k == v:
        continue
    else:
        if k > v:
            cnt += v
        else:
            cnt += v - k
print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter

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

a = Counter(a)

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

print(ans)

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n = n//a
    count += 1
  if a**count == n:
    return count
  else:
    return count+1

#############
# Main Code #
#############

N = I()
A = IL()
d = DD(int)
for a in A:
  d[a] += 1
  
keys = [k for k in d]
ans = 0

for k in keys:
  if k > d[k]:
    ans += d[k]
  else:
    ans += d[k]-k

P(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
A = a.sort()
array = list(set(a))
array.sort()
sum = 0
n = 0
for i in range(len(array)):
    cnt = 0
    for j in range(n,len(a)):
        if array[i] == a[j]:
            cnt += 1
        else:
            break
    n += cnt
    if cnt >= array[i]:
        sum += cnt - array[i]
    else:
        sum += cnt
print(sum)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split())) 
s = 0
A = Counter(a)
l = len(A)


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

print(s)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]
A = Counter(a)
ans = 0
for x in A:
    if x < A[x]:
        ans += A[x]-x
    elif A[x] != x:
        ans += A[x]
print(ans)

Submission status: Accepted

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
a=collections.Counter(a)
values,counts=zip(*a.most_common())
l=len(values)
ans=0
for i in range(0,len(values)):
  if counts[i]<values[i]:
    ans=ans+counts[i]
  elif counts[i]>values[i]:
    ans=ans+counts[i]-values[i]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
def main():
    N = int(input())
    a = [int(i) for i in input().split()]
    dd = defaultdict(int)
    res=0

    for i in a:
        dd[i]+=1 
    for i in dd.keys():
        if dd[i]<i:
            res += dd[i]
        elif dd[i]>i:
            res += dd[i]-i 
            dd[i] = i 
    print(res)
            



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

a_c = Counter(a_input)
ans = 0
for k,v in a_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()))
d = dict()
for b in a:
  if b in d:
    d[b] += 1
  else:
    d[b] = 1
c = 0
for k,v in d.items():
  if k == v:
    pass
  elif k < v:
    c += (v-k)
  else:
    c += v
print(c)

Submission status: Accepted

Solution code:
import collections
n=int(input())
A=list(map(int,input().split()))
a=collections.Counter(A)
key,value=zip(*a.most_common())
cnt=0
for i in range(len(key)):
  if key[i]>value[i]:
    cnt+=value[i]
  elif key[i]<value[i]:
    cnt+=value[i]-key[i]
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

A = Counter(A).most_common()
for key,val in A:
  if val >= key:
    ans += val - key
  else:
    ans += val
print(ans)

Submission status: Accepted

Solution code:
import collections

n = int(input())
li = list(map(int,input().split()))
c = collections.Counter(li)
ans = 0

for item in c.items():
    x = item[0] #要素
    y = item[1] #個数

    if x < y:
        ans += y-x

    if x > y:
        ans += y

print(ans)

Submission status: Accepted

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

a_map=defaultdict(int)
for i in a:
    a_map[i] += 1
print(sum([cnt-i if i < cnt else cnt for i, cnt in a_map.items() if i != cnt]))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
c = Counter(a)
nums = 0
for key, value in c.items():
    if key == value:
        pass
    elif key > value:
        nums += value
    else:
        nums += value - key
print(nums)

Submission status: Accepted

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

d = {}

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections


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

a.sort()

aSet = set(a)

c = collections.Counter(a)

count = 0

for i in aSet:
    if c[i] > i:
        count = count + c[i] - i
    elif c[i] < i:
        count = count + c[i]


print(count)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
ans = 0
before_num = A[0]
num_count = 1
A.append(-1)#一番大きい数を計算するとき用

for num in A[1:]:
    if num == before_num:
        num_count += 1
    else:
        if num_count >= before_num:
            ans += num_count - before_num
        else:
            ans += num_count
        num_count = 1
        before_num = num

print(ans)

Submission status: Accepted

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

c = dict()
for a in A:
    if a not in c:
        c[a] = 1
    else:
        c[a] += 1

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(numbers)

output = 0

for k, v in c.items():
    if k > v:
        output += v
    elif v > k:
        diff = v - k
        output += diff

print(output)

Submission status: Accepted

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

c = Counter(a)
key = c.keys()
f = []
ans = 0

for i in key:
    if i < c[i]:
        ans += c[i] - i
    elif i > c[i]:
        ans += c[i]

print(ans)

Submission status: Accepted

Solution code:
from collections import*
_, *a = map(int, open(0).read().split())
print(sum(v - i if i < v else v if i > v else 0 for i, v in Counter(a).items()))

Submission status: Accepted

Solution code:
import collections

#文字列を一文字ずつ取得したいとき
def inputStrOnebyOne():
    s = list(input())
    return s

#整数を一つずつリストに入れる
def inputOnebyOne_Int():
    a = list(int(x) for x in input().split())
    return a

def main():
	n = input()
	a = list(map(int,input().split()))
	c = collections.Counter(a)
	cntRem = 0

	for key, val in c.items():
		if key < val:
			cntRem+= val - key
		elif key > val:
			cntRem+= val
	print(cntRem)

if __name__=='__main__':
    main()

Submission status: Accepted

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

als.sort()

my_dict = dict()

for item in als:
    if item in my_dict:
        my_dict[item] += 1
    else:
        my_dict[item] = 1


ret = 0
for item in my_dict:
    val = my_dict[item]
    if val < item:
        ret += val
    else:
        ret += (val - item)

print(ret)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
ans = 0
c = Counter(a)
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(x) for x in input().split()]
c = Counter(a)
ans = 0
for v, c in c.items():
  if v < c:
    ans += c-v
  if v > c:
    ans += c

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
c = [0] * (n + 1)
for i in a:
  if i <= n:
    c[i] += 1
s = 0
for i in range(1, n + 1):
  if c[i] >= i:
    s += i
print(n - s)

Submission status: Accepted

Solution code:
from collections import Counter

input()
counter = Counter(map(int, input().split(' ')))

print(sum([count if number > count else count - number for number, count in counter.items()]))

Submission status: Accepted

Solution code:
from collections import Counter

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

ans = 0
for key, val in Counter(a).most_common():
    if key > val:
        ans += val
    elif key < val:
        ans += val - key

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 11:47:51 2020

@author: shinba
"""

n = int(input())

data = {}
ans = 0

for x in map(int,input().split()):
    if not x in data:
        data[x] = 1
    else:
        if data[x] < x:
            data[x] += 1
        else:
            ans += 1

for i,j in data.items():
    if i == j:
        continue
    ans += j
    
print(ans)

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()
    A = collections.Counter(il())

    ret = 0
    for k in A:
        v = A[k]
        if k <= v:
            ret += abs(k-v)
        else:
            ret += v
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import Counter
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = input()
m = map(int, input().split())
d = {}
for i in m:
    if i in d.keys():
        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:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

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

print(count)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
count = [0] * 100001
over = 0
ans = 0
for i in a:
    if i > 100000:
        over += 1
    else:
        count[i] += 1
for i in range(100001):
    if count[i] < i:
        ans += count[i]
    elif count[i] == i:
        continue
    else:
        ans += count[i] - i
print(ans + over)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
l = collections.Counter(a)
#print(l)
v = list(l.keys())
#print(v)
ans = 0
for i in v:
    if (l.get(i)>=i):
        ans += (l.get(i)-i)
    else:
        ans += l.get(i)
print(ans)

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():
  tmp = v - k if k <= v else v
  ans += tmp
print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
a = collections.Counter(a)
a_key = list(a.keys())
a_value = list(a.values())
cnt = 0
for i in range(len(a)):
    x = int(a_value[i])-int(a_key[i])
    if  x >= 0:
        cnt += x
    else:
        cnt += a_value[i]
print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(a)
cnt = 0
for key,value in Counter(a).items():
    if key < value:
        cnt += value - key
    if key > value:
        cnt += value
print(cnt)

Submission status: Accepted

Solution code:
A=int(input())
import collections
B=list(map(int,input().split()))
B=collections.Counter(B)
C=list(B.keys())
D=list(B.values())
ans = 0
for i,j in zip(C,D):
    if i > j:
        ans+=j
    elif i < j:
        ans+=j-i
print(ans)

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions

import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n = ni()
    a = na()

    c = collections.Counter(a)

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(a)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline


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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter

def resolve():
	n = int(input())
	c = Counter(list(map(int, input().split())))
	lis = list(c.keys())
	ans = 0
	for k in c.keys():
		if k != c[k]:
			if k > c[k]:
				ans += c[k]
			else:
				ans += c[k] - k
	print(ans)
resolve()

Submission status: Accepted

Solution code:
from collections import Counter

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

a=Counter(a)
ans=0
for key,count in a.most_common():
    key=int(key)
    if count>=key:
        ans+=count-key
    else:
        ans+=count
print(ans)

Submission status: Accepted

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

li.sort()
ans = 0
cnt = 0
check = 0

for i in li:
    if i != check:
        if cnt >= check:
            ans += cnt - check
        else:
            ans += cnt

        check = i
        cnt = 1
    else:
        cnt += 1
else:
    if cnt >= check:
        ans += cnt - check
    else:
        ans += cnt

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a_s = [int(x) for x in input().split()]

counts = Counter(a_s)

ans = 0
for key in counts.keys():
    if key <= counts[key]:
        ans += counts[key] - key
    else:
        ans += counts[key]
        
print(ans)

Submission status: Accepted

Solution code:
import collections
import fractions
from functools import reduce
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    a = input_list()
    ac = collections.Counter(a)
    # 個数が少ない場合は空にする
    ans = 0
    for num, count in ac.items():
        if num < count:
            ans += count - num
        if num > count:
            ans += count
    print(ans)

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

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans=0
import collections
c=collections.Counter(a)
c=c.most_common()
for i in range(len(c)):
    x=c[i][0]
    y=c[i][1]
    if x<=y:
        ans += y-x
    else:
        ans += y
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = list(map(int,input().split()))
ac = Counter(a)
an = len(ac)
a_mostcommon = ac.most_common()
cnt = 0
for i in range(an):
  num, count = a_mostcommon[i]
  if count > num:
    cnt += count - num
  elif count < num:
    cnt += count

print(cnt)

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
n = int(input())
A = list(ma())
import collections
co = collections.Counter(A)
ans = 0
for num,cnt in co.items():
    if num>cnt:ans+=cnt
    if num<cnt:ans+=(cnt-num)
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

n, *a = map(int, read().split())
ans = 0
for k, v in Counter(a).items():
    if k > v:
       ans += v
    elif k < v:
        ans += v - k
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    count = Counter(A)
    ans = 0
    for key, value in count.items():
        if key == value:
            continue
        else:
            if key<value:
                ans += value-key
            else:
                ans += value
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque,Counter

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

cnt = Counter(lisA)

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

print(ans)

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(a)
cnt=0

for item in c.keys():
    if c[item]>=item:
        cnt+=c[item]-item
    else:
        cnt+=c[item]
print(cnt)

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    A_list = [int(item) for item in input().split()]

    cnt_dict = collections.Counter(A_list)

    cnt = 0
    for i, v in cnt_dict.items():
        if i <= v:
            cnt += v - i
        elif i > v:
            cnt += v
    print(cnt)
if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
from collections import Counter


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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

print(count)