Problem:


Score : 300 points

Problem Statement

You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N).
Your objective is to remove some of the elements in a so that a will be a good sequence.

Here, an sequence b is a good sequence when the following condition holds true:

For each element x in b, the value x occurs exactly x times in b.

For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.

Find the minimum number of elements that needs to be removed so that a will be a good sequence.

Constraints

1 \leq N \leq 10^5

a_i is an integer.

1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum number of elements that needs to be removed so that a will be a good sequence.

Sample Input 1

4
3 3 3 3

Sample Output 1

1

We can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good sequence.

Sample Input 2

5
2 4 1 4 2

Sample Output 2

2

We can, for example, remove two occurrences of 4. Then, (2, 1, 2) is a good sequence.

Sample Input 3

6
1 2 2 3 3 3

Sample Output 3

0

Sample Input 4

1
1000000000

Sample Output 4

1

Remove one occurrence of 10^9. Then, () is a good sequence.

Sample Input 5

8
2 7 1 8 2 8 1 8

Sample Output 5

5



Sample input:
4
3 3 3 3


Sample output:
1

Submission status: Accepted

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

a.sort()
cnt = 1
ans = 0
key = a[0]

for i in range(1,len(a)):
    if a[i] == key:
        cnt += 1
    else:
        if cnt >= a[i-1]:
            ans += ( cnt - a[i-1] )
        else:
            ans += cnt

        cnt = 1
        key = a[i]

if cnt >= a[len(a)-1]:
    ans += ( cnt - a[len(a)-1] )
else:
    ans += cnt

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

from collections import Counter

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

# 各要素数カウント
counter = Counter(a)

# メイン処理
count = 0
for k, v in counter.most_common():
    if k > v:
        count += v
    elif k < v:
        count += v - k

# 出力
print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N = int(input())
a = list(map(int, input().split()))
num = [0] * (N + 1)
ans = 0
for i in range(N):
    if a[i] > N:
        ans += 1
    else:
        num[a[i]] += 1

ans += sum([(0 if (num[i] == 0) else num[i] - i if (num[i] >= i) else num[i]) for i in range(N + 1)])
print(ans)

Submission status: Accepted

Solution code:
import collections
N=input()
a=map(int,raw_input().split())
b = collections.Counter(a)
#print b

cnt=0
for i,j in b.items():
	if i<j:
		cnt+=j-i
	elif i>j:
		cnt+=j
	else:
		pass

print cnt

Submission status: Accepted

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

Submission status: Accepted

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

from collections import Counter

def main():
    n = int(input())
    A = list(map(int, input().split()))
    counts = Counter()
    for a in A:
        counts[a] += 1
    remove_count = 0
    for i, c in counts.items():
        if c < i:
            remove_count += c
        else:
            remove_count += c - i
    print(remove_count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

ans = 0
cnt = Counter(a_list)
for num in cnt:
	if (cnt[num] > num):
		ans += cnt[num]-num
	elif (cnt[num] < num):
		ans += cnt[num]
print(ans)

Submission status: Accepted

Solution code:
import collections

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

ans = 0
count_dict = collections.Counter(a)
for k, v in count_dict.items():
    if k < v:
        ans = ans + abs(int(k)-int(v))
    elif k > v:
        ans = ans + int(v)

print(ans)

Submission status: Accepted

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

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

result = 0
for n in list(count_a.keys()):
    if count_a[n] != n:
        result = result + count_a[n] if count_a[n] < n else result + count_a[n] - n

print(result)

Submission status: Accepted

Solution code:
nb = int(input())
l = list(map(int,input().split()))
d = dict()
m = 0
for i in l:
   if i in d:
      d[i] += 1
   else:
      d[i] = 1
for k in d:
   if d[k] < k:
      m += d[k]
   else:
      m += d[k] - k
print(m)

Submission status: Accepted

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
a=sorted(a)
a.append(0)
ans=0
num_count=0
prev=0
for ai in a:
    # print(prev,ai,num_count,ans)
    if ai!=prev:
        if num_count>=prev:
            ans+=num_count-prev
        else:
            ans+=num_count
        num_count=1
    else:
        num_count+=1
    prev=ai

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


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

    x = [
        (num, count, count - num)
        for num, count in c.items()
        if count != num
    ]

    ans = 0
    for num, count, diff in x:
        if diff > 0:
            ans += diff
        else:
            ans += count
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n=input()
data = [int(i) for i in input().split(" ")]
counter = Counter(data)
n=0
for i, c in counter.most_common():
  if i>c:
    n+=c
  elif c>i:
    n+=c-i
print(n)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
C = Counter([int(i) for i in input().split()])
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()))

from collections import Counter
c = Counter(a)

ans = 0
for label, num in c.most_common():
    if(label > num):
        ans += num
    elif(label < num):
        ans += num - label
        
print(ans)

Submission status: Accepted

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

Adict = {}

for a in A:
    if str(a) in Adict:
        Adict[str(a)] += 1
    else:
        Adict[str(a)] = 1

ct = 0

for i in Adict:
    if int(i) < Adict[i]:
        ct += (Adict[i]-int(i))
    elif int(i) > Adict[i]:
        ct += Adict[i]
print(ct)

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, j in c.items():
    if i > j:
        ans += j
    elif i < j:
        ans += (j - i)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
count = 0
for key, value in d.items():
    if key < value:
        count += value - key
    elif key > value:
        count += value
print (count)

Submission status: Accepted

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

dic = {}
for n in a:
    dic.setdefault(n, 0)
    dic[n] += 1

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

print(s)

Submission status: Accepted

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

b = {}

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

ans = 0
for k,v in b.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()))

dic = defaultdict(int)
for i in range(N):
    dic[A[i]] += 1

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    counter = Counter(A).most_common()
    ans = 0
    for i, j in counter:
        if i > j:
            ans += j
        else:
            ans += j - i
    print(ans)

main()

Submission status: Accepted

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

from collections import Counter

N = int(input())
a = [int(i) for i in input().split()]
c = Counter(a)
cnt = 0
for i, j in c.items():
    if i < j:
        cnt += (j-i)
    elif i == j:
        continue
    elif i > j:
        cnt += j
    else:
        continue
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(str, input().split()))
dic = {}
for num in a:
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1
ans = 0
for num in dic:
    if int(num) > dic[num]:
        ans += dic[num]
    else:
        ans += min(dic[num], abs(int(num)-dic[num]))
print(ans)

Submission status: Accepted

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

count = 0
for key in count_a.keys():
    if key < count_a[key]:
        count += count_a[key] - key
    elif key == count_a[key]:
        count += 0
    else:
        count += count_a[key]

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import OrderedDict, deque, Counter


def solve():
    N = int(input())
    A = list(map(int, input().split(" ")))
    count_dict = Counter(A)

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

    print(cnt)


solve()

Submission status: Accepted

Solution code:
m = {}

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

c = 0
for b in a:
    if b in m.keys():
        if m[b] >= b:
            c += 1
        else:
            m[b] += 1
    else:
        m[b] = 1

for k, v in m.items():
    if k > v:
        c += v

print(c)

Submission status: Accepted

Solution code:
import collections

num = int(input())
val = [int(x) for x in input().split()]

cnt = collections.Counter(val)
res = 0
for x in cnt:
    if cnt[x] > x:
        res += cnt[x] - x
    elif cnt[x] < x:
        res += cnt[x]

print(res)

Submission status: Accepted

Solution code:
import sys

line = sys.stdin.readline().strip()
N = int(line)

line = sys.stdin.readline().strip()
a = [int(x) for x in line.split()]

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

r = 0
for k in xs:
    if xs[k] < k:
        r += xs[k]
    elif xs[k] > k:
        r += xs[k] - k

print(r)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
cnt={}
for e in a:
  if e in cnt:
    cnt[e]+=1
  else:
    cnt[e]=1
ans=0
for e in a:
  if cnt[e]==0:
    continue
  else:
    if cnt[e] > e:
      ans+=cnt[e]-e
    elif cnt[e] < e:
      ans+=cnt[e]
    cnt[e]=0
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
dic={}
for n in a:
    if n in dic:
        dic[n]+=1
    else:
        dic[n]=1
ans=0
for k in dic.keys():
    if dic[k]-k>0:
        ans+=dic[k]-k
    elif dic[k]-k==0:
        pass
    else:
        ans+=dic[k]
print(ans)

Submission status: Accepted

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

dic = {}

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

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

	else:
		ans += (value - key)


print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
*a, = map(int, input().split())
M = 10**5+1
b = [0]*(M+1)
for i in range(N):
    b[a[i]] += 1
ans = 0
for i in range(1, M+1):
    if i > b[i]:
        ans += b[i]
    elif i < b[i]:
        ans += b[i]-i
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
*a, = map(int, input().split())
b = [0]*(N+1)
for i in range(N):
    b[a[i]] += 1
ans = 0
for i in range(1, N+1):
    if i > b[i]:
        ans += b[i]
    elif i < b[i]:
        ans += b[i]-i
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
alist = list(map(int,input().split()))
from collections import Counter
adic = Counter(alist)
count = 0
for k,v in adic:
  if int(k) <= v:
    count+=(v-int(k))
  else:
    count+=v
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
alist = list(map(int,input().split()))
from collections import Counter
adic = Counter(alist)
count = 0
for key,value in adic:
  if int(key) <= value:
    count+=(value-int(key))
  else:
    count+=value
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
alist = list(map(int,input().split()))
from collections import Counter
adic = Counter(alist)
count = 0
for key,value in adic:
  if int(key) =< value:
    count+=(value-int(key))
  else:
    count+=value
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
alist = list(map(int,input()))
from collections import Counter
adic = Counter(alist)
count = 0
for key,value in adic:
  if int(key) =< value:
    count+=(value-int(key))
  else:
    count+=value
print(count)

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    a_lst.sort()
    a_set_lst = list(set(a_lst))
    a_set_lst.sort()

    count_lst = []
    count = 1
    if n == 1:
        count_lst.append(count)
    else:
        for i in range(n - 1):
            a1 = a_lst[i]
            a2 = a_lst[i + 1]

            if a1 == a2:
                count += 1
                if i == n - 2:
                    count_lst.append(count)
            else:
                count_lst.append(count)
                count = 1

    minimum = 0
    for i in range(len(a_set_lst)):
        number = a_set_lst[i]
        count = count_lst[i]

        if count < number:
            minimum += count
        else:
            minimum += count - number

    print(minimum)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = input()
A = sorted([int(x) for x in input().split()])
import bisect as bs
ans = 0
f = lambda X, x: bs.bisect_right(X,x) - bs.bisect_left(X.x)
for a in set(A):
    cnt = f(A,a)
    if cnt < a:
        ans += cnt
    else:
        ans += cnt-a
print(ans)

Submission status: Runtime Error

Solution code:

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

if len(numbers)==1:
  print(1)
  exit()
counter=0
counter_2=0
for i in range(len(numbers)):
  if numbers[i]>len(numbers):
    numbers.pop(i)
for i in range(1000):

  if numbers.count(i)==i:
    counter_2+=i
  elif numbers.count(i) != i:
    if numbers.count(i) > i:
      counter+=(numbers.count(i)-i)
    else:
      counter+=numbers.count(i)
    
    counter_2+=numbers.count(i)
  if counter_2==len(numbers):
    break
    
print(counter)

Submission status: Runtime Error

Solution code:
8
2 7 1 8 2 8 1 8

Submission status: Runtime Error

Solution code:
import numpy as np

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

# a_N>N must be removed
remove = np.sum(sequence>N)
sequence = sequence[sequence<=N]

index = np.unique(sequence)

for idx in index(sequence):

    n_idx = np.sum(sequence==idx)
    if n_idx < idx:
        remove += n_idx
    else:
        remove += (n_idx-idx)

print(remove)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = 10**5*[0]
ans = 0

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

for n in range(10**5):
  if B[n]<n:
    ans+=B[n]
  elif n<B[n]:
    ans+=B[n]-n

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
*A, = map(int, input().split())
dic = {}
for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1
for k, v in dic.items():
    if k == v:
        continue
    elif k > v:
        ans += v
    else:
        ans += v - k
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(100001)]
ans=0
for i in range(n):
    l[a[i]]+=1
for i in range(100001):
    if 0<l[i]<i:
        ans+=l[i]
    if i<l[i]:
        t=l[i]-i
        ans+=t
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
A = Counter(list(map(int,input().split())))
keys,counts = zip(*A.most_common())
total = 0
for key,count in zip(keys,counts):
    if key > count:
        total += count
    else:
        total += count-key
print(total)

Submission status: Runtime Error

Solution code:
def resolve():
    from collections import defaultdict
    N = int(input())
    A = [int(i) for i in input().split()]
    dic = defaultdict(int)
    for a in A:
        dic[a] += 1
    ans = 0
    for k, v in dic:
        if k <= v:
            ans += v - k
        else:
            ans += v
    print(ans)


resolve()

Submission status: Runtime Error

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

check = [0] * N
ans = 0

for i in range(N):
  if a[i] > 10**5:
    ans += 1
  else:
    check[a[i]-1] += 1

for j in range(N):
  if j+1 > check[j]:
    ans += check[j]
  elif j + 1 < check[j]:
    ans += check[j] -j - 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
n=l()[0]
A=l()
d={}
for i in range(n):
    if A[i] not in d:
        d[A[i]]=0
    d[A[i]]+=1
anss=0
for k in d:
    if(d[k]<k):
        ans+=k
    else:
        ans+=(d[k]-k)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())
c = Counter(list(map(int, input())))
ans = 0
for k in c:
  ans += d[k] - k if k <= d[k] else d[k]

print(ans)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
a = sorted(list(map(int,input().split())))
A =  collections.Counter(a)
cnt = 0
for i in A:
   # print(i)
    if i[0]<i[1]:
      cnt=cnt+i[1]-i[0]
    if i[0]>i[1]:
      cnt=cnt+i[1]
print(cnt)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
d=[0]*(10**5+1)
ans=0
for i in range(len(a)):
  if d[i]<=10**5:
    d[a[i]]+=1
for i in range(1,len(d)):
  if d[i]>i:
    ans+=d[i]-i
  elif d[i]<i:
    ans+=d[i]
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
d=[0]*(10**5+1)
ans=0
for i in range(len(a)):
  d[a[i]]+=1
for i in range(1,len(d)):
  if d[i]>i:
    ans+=d[i]-i
  elif d[i]<i:
    ans+=d[i]
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
lcount=[0]*10**9
count=0
for i in l:
    lcount[i]+=1
    if lcount[i]>i:
        count+=1
for j in l:
    if lcount[j]<j:
        count+=1
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
c=[0]*(max(a)+1)
for i in range(len(a)):
  c[a[i]]+=1
seta=set(a)
ans=0
for ai in seta:
  if c[ai]==ai:
    pass
  elif c[ai]<ai:
    ans+=c[ai]
  else:
    ans+=c[ai]-ai
print(ans)

Submission status: Runtime Error

Solution code:
import math
import random

line1 = int(input())
line2 = str(input()).split(" ")
keepTrack = dict()
keys = []
keys = list(set(line2))
for element in keys:
    keepTrack[element] = line2.count(element)

sum = 0
for key in keys:
    ##sum += abs()
    if (key < keepTrack[key]):
        sum += -key + keepTrack[key]
    elif (key > keepTrack[key]):
        sum += keepTrack[key]
print(sum)

Submission status: Runtime Error

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

elems = set([])
rem = 0

for i in range(0,N+1):
    a = seq[i]
    if a not in elems:
        elems.add(a)
        c = seq.count(a)
        if (c < a):
            rem += c
        else:
            rem += c-a

print(rem)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
a = Counter(input().split())
ans += 0
for i in range(len(a)):
  if a.keys()[i][1] < int(a.keys()[i][0]):
    ans += a.keys()[i][0]
    
  elif a.keys()[i][1] >int(a.keys()[i][0]):
    ans +=(int(a.keys()[i][0])-a.keys()[i][1])
    
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=0
c=Counter(a)
for u in c.keys():
  if int(u)>c[u]:
    cnt+=v
  else:
    cnt+=c[u]-int(u)
print(cnt)

Submission status: Runtime Error

Solution code:
import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=0
c=Counter(a)
for u,v in c:
  if int(u)>v:
    cnt+=v
  else:
    cnt+=v-int(u)
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
import collections
c = collections.Counter(a)
for i in range(10**9):
  if c[i] < i:
    ans += c[i]
  if c[i] > i:
    ans += c[i]-i
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ans = 0
for num, cnt in c.items():
    if cnt>=num:
        ans += cnt - num
    else:
        ans += cnt
print(ans)

Submission status: Runtime Error

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

n = len(a)
a.sort()
a.append()
ans = 0
i = 0

while i < n:
    cnt = 1
    while a[i] == a[i+1]:
        cnt += 1
        i += 1
    if cnt >= a[i]:
        ans += cnt - a[i]
    else:
        ans += cnt
    i += 1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans=0
lastnum=a[0]
cnt=1
for num in a[1:]:
    if num==lastnum:
        cnt+=1
    else:
        ans+=min(cnt,abs(cnt-lastnum))
        cnt=1
    tmp=lastnum
    lastnum=num

ans+=min(cnt,abs(cnt-tmp))
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
i=0
ans=0
while i<n:
    h=a.count(a[i])
    i+=h
    ans+=abs(h-a[i])
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
i=0
ans=0
while i<n:
  h=a.count(a[i])
  i+=h
  ans=ans+h-a[i]
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
arr = []
out = {}

for i in range(n):
	arr.append(int(input()))
	
	if out.get(arr[-1], False):
		out[arr[-1]] += 1
	else:
		out[arr[-1]] = 1

count = 0
for key in out:
	if key > out[key]:
		count += out[key]
	else:
		count += out[key] - key

print(count)

Submission status: Runtime Error

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

c = Counter(A)
ans = 0
for i, m in c.items():
    if m < i:
        ans += m
    else:
        ans += m - i
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = [0]*max(a)
count = 0
for i in a:
    ans[i-1]+=1
for i in a:
    if ans[i-1] == i:
        pass
    else:
        count+=1
        ans[i-1]-=1
print(count)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    map<int,int> m;
    int n;
    cin >> n;
    rep(i,n){
        int x;
        cin >> x;
        m[x]++;
    }
    int res = 0;
    for(auto i:m){
        if(i.first>i.second){
            res+=i.second;
        }
        else{
            res+=i.second-i.first;
        }
    }
    cout << res << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
cnt = 1
prev = a[0]
#print(a)

for i in range(1, n):
    # print('\n# i: ' + str(i))
    # print('# a[i]: ' + str(a[i]))
    if a[i] == prev:
#        print('same!')
        cnt += 1
    else:
        if cnt == prev:
#            print('good, skip!')
        elif cnt > prev:
#            print('cnt is larger!')
            ans += cnt - prev
        else:
#            print('cnt is smaller!')
            ans += cnt
#        print('ans: ' + str(ans))
        prev = a[i]
        cnt = 1

if cnt > prev:
    ans += cnt - prev
elif cnt < prev:
    ans += cnt

print(ans)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
using namespace std;

long long int CheckDelete(int a, int i){
        if(a == 0 || a==i){
            return 0;
            }
        else{
            if(a < labs(a-i)){
                    return a;
                }
            else{
                    return labs(a-i);
                }
            }

    }

int main(){
    long long int N, CountDelete, Num;
    cin >> N;
    vector<long long int> A(N+1);
    for(long long int i=1; i<N+1; i++){
        cin >> Num;
        if(Num > 100000){
                CountDelete++;
            }
        else{
                A[Num]++;
            }
        }
    for(long long int i=1; i<N+1; i++){
            CountDelete += CheckDelete(A[i], i);
        }
    cout << CountDelete;
    }

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0] * 200000
ans = 0
for i in range(N):
	if A[i] < 200000:
		B[A[i]] += 1
	else:
		ans += 1
for i in range(200000):
	ans += min(B[i], abs(i – B[i]))
print(ans)

Submission status: Runtime Error

Solution code:
import collections

N=int(input())

a_dict=collections.Counter(a)
a=list(a_dict.items())

L=len(a)

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

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

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

Submission status: Runtime Error

Solution code:
from astropy.units import count
n = int(input())
a = list(map(int,input().split()))
a.sort()
v = a[0]
count = 1
result = 0
for i in range(1,n):
    if v == a[i]:
        count += 1
    else:
        if v == count:
            v = a[i]
            count = 1
        else:
            if count > v:
                result += count -v
                v = a[i]
                count = 1
            else:
                result += count
                v = a[i]
                count = 1
if v != count:
    if count > v:
        result += count -v
    else:
        result += count
print(result)

Submission status: Runtime Error

Solution code:
k=[0]*(10**9+1)
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
	k[a[i]-1]+=1
	if k[a[i]-1]>a[i]:
		ans+=1
b=set()
for i in range(n):
	if k[a[i]-1]<a[i]-1 and a[i] not in b:
		ans+=k[a[i]-1]
	b.add(a[i])
print(ans)

Submission status: Runtime Error

Solution code:
k=[0]*(10**9+1)
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
	k[a[i]]+=1
	if k[a[i]]>a[i]:
		ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
c=list(map(int,input().split()))
c = collections.Counter(c)
count=0
for x in c:
    if x==c[x]:
        continue
    elif x>c[x]:
        count+=c[x]
    else:
        count=count+(c[x]-x)
print(count)

Submission status: Runtime Error

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

ans = 0
count = [0] * (10 ** 5)

for i in range(N):
  count[a[i]] += 1
  ans += 1
  if count[a[i]] == a[i]:
    ans -= a[i]

print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
data = sorted(data) + [0]

if N == 1 and data[0] == 1:
    print(0)

elif N == 1 and data[0] != 1:
    print(1)

else:
    ans = 0
    num = data[0]
    cnt = 0
    for i in range(N+1):
        if data[i] == num:
            cnt += 1
        else:
            if cnt < data[i-1]:
                ans += cnt
            else:
                ans += (cnt-data[i-1])
            cnt = 1
            num = data[i]
print(ans)