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
N = int(input())
D = Counter([int(a) for a in input().split()])

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a=[int(i) for i in input().split()]
a = Counter(a)
cnt = 0
for key in a.keys():
    val = a[key]
    if key>val:
        cnt += val
    else:
        cnt += abs(val-key)
print(cnt)

Submission status: Accepted

Solution code:
import collections
N = int(input())
A =list(map(int,input().split()))
col_A = collections.Counter(A)
count = 0
for key,val in col_A.items():
    if key > val:
        count += val
    else:
        count += (val - key)
print(count)

Submission status: Accepted

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

D = {}

for a in A:
    D[a] = D.get(a, 0) + 1

cnt = 0
for k, v in D.items():
    if k < v:
        cnt += v - k
    elif v < k:
        cnt += v
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 k, v in C.items():
    if k <= v:
        cnt += v - k
    else:
        cnt += v
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import numpy as np
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
L = l()
c = Counter(L)
ans = 0
for i,v in c.items():
    if i > v:
        ans += v
    if i < v:
        ans += v-i
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
a.sort()
a.append(0)
ans=0
b=a[0]
c=0
for i in range(N+1):
  if b!=a[i]:
    if c<b:
      ans+=c
    b=a[i]
    c=1
  else:
    if c==b:
      ans+=1
    else:
      c+=1
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc082/tasks/arc087_a
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


from collections import Counter
N = a_int()
A = ints()
# Counterして成り立たない数字を取り除いた数が答え

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

Submission status: Accepted

Solution code:
import collections

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

cnt = collections.Counter(A)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[0]*(n+2)
for i in range(n):
    if a[i]>n:
        b[n+1]+=1
    else:
        b[a[i]]+=1
sm=0
for i in range(1,n+1):
    if b[i]>i:
        sm+=b[i]-i
    elif b[i]<i:
        sm+=b[i]

sm+=b[n+1]
print(sm)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import Counter

n, *a = map(int, read().split())

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
d=dict()
for i in range(n):
    if a[i] not in d:
        d[a[i]]=1
    else:
        d[a[i]]+=1
ans=0
for key in d:
    if key<=d[key]:
        ans+=d[key]-key
    else:
        ans+=d[key]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

from collections import Counter

dic = Counter(a)

ans = 0
for i, j in dic.items():
    if i <= j:
        ans += j - i
    else:
        ans += j

print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

from collections import Counter
c = Counter(a)
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()))

dic = Counter(a)

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

rlt = 0
dic = Counter(As)

for k in dic:
  if dic[k] < k:
    rlt += dic[k]
  elif dic[k] > k:
    rlt += dic[k] - k
    
print(rlt)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
d = Counter(list(map(int, input().split())))
ans = 0
for x, y in d.items():
    if x > y:
        ans += y
    else:
        ans += y-x
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=Counter(list(map(int,input().split())))
cnt=0
for i,j in a.most_common():
  if i<=j:cnt+=j-i
  else:cnt+=j
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input().strip())
    a_list = [int(n) for n in input().strip().split()]
    count = Counter(a_list)
    ans = 0
    for k, v in count.items():
        if v == k:
            continue
        elif v > k:
            ans += v - k
        else:
            ans += v
    return ans


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

Submission status: Accepted

Solution code:
from _collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
a_max = max(a)
l = defaultdict(int)
count = 0
for i in range(n):
    l[a[i]] += 1
    count += 1
    if l[a[i]] == a[i]:
        count -= a[i]
print(count)

Submission status: Accepted

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

Solution code:
from collections import Counter, defaultdict
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
a = LI()
c = Counter(a)
ans = 0
for i, count in c.items():
    if count == i:
        continue
    elif count > i:
        ans += count - i
    else:
        ans += count
print(ans)

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    d = defaultdict(int)
    for a in ipt().split():
        d[int(a)] += 1

    ans = 0
    for dk,dv in d.items():
        if dk > dv:
            ans += dv
        elif dk < dv:
            ans += (dv-dk)
    print(ans)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

for i, j in d.items():
    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 = [int(i) for i in input().split()]

ans = 0
m = Counter(a)
for x, y in m.items():
    if x == y:
        continue
    elif x < y:
        ans += abs(y-x)
    else:
        ans += y
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

ans = 0
for i, c in d.items():
    ans += c - i if c >= i else c
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
dic={}
minus=0
for i in a:
  if i not in dic:
    dic[i]=1
  else:
    dic[i]+=1

for i in dic:
  v=dic[i]
  if i==v:
    continue
  elif i<v:
    minus+=v-i
  else:
    minus+=v

print(minus)

Submission status: Accepted

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

d = dict()
for a in A:
    d.setdefault(a, 0)
    d[a] += 1

c = 0
for i, count in d.items():
    rem = count - i
    if rem < 0:
        c += count
    else:
        c += rem
print(c)

Submission status: Accepted

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


resolve()

Submission status: Accepted

Solution code:
from collections import Counter

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

C = Counter(A)

ans = 0
for x,c in C.items():
  t = c
  if c >= x:
    t = min(t,c-x)
  ans += t
  
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
a = list(input().split())
seq = [int(a[i]) for i in range(N)]
Cons = Counter(seq)

num = list(Cons.items())
count = 0

for i in range(len(num)):
    dif = int(num[i][1]) - int(num[i][0])
    count += (dif if dif >= 0 else int(num[i][1]))

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 20200612_yorukatsu_e.py
import collections
N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
ans = 0
for i,v in C.items():
    # print(i,v)
    if i!=v:
        if i<v:
            ans += v-i
        else:
            ans += v
print(ans)

Submission status: Accepted

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

a = Counter(a)
cnt = 0
for k, v in a.items():
    if k == v:
        continue
    elif 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()))
c = Counter(a)
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:
import collections
N = int(input())
a = list(map(int,input().split()))
ans = 0
c = collections.Counter(a)

key = list(c.keys())


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

Submission status: Accepted

Solution code:
from collections import defaultdict

ans,n = 0,int(input())
a_list = list(map(int,input().split()))
a_dict = defaultdict(int)
for i in range(n):
    a_dict[a_list[i]]+=1
for key,value in a_dict.items():
    if value>key:
        ans += value-key
    elif value<key:
        ans += value
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
dict={}
count=0
for i in a:
  if i not in dict:
    dict[i] = 1
    continue
  dict[i] += 1
for i,j in dict.items():
  if i > j:
    count += j
  elif i < j:
    count += j-i
print(count)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
ls = list(map(int,input().split()))
c = Counter(ls)
p = 0
for s,t in c.items():
    if s > t:
        p += t
    elif s < t:
        p += t - s
print(p)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a_li = list(map(int,input().split()))
a_counter = Counter(a_li)
a_most = a_counter.most_common()
ans = 0
for s in a_most:
    dum = s[1] - s[0]
    if dum < 0:
        ans += s[1]
    elif dum > 0:
        ans += dum
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = []
c = {}
ans = 0
for i in range(n):
  if a[i] in c:
    c[a[i]] += 1
  else:
    c[a[i]] = 1
    b.append(a[i])
  
for i in range(len(b)):
  temp=c[b[i]]
  temp2=b[i] 
  if temp > temp2:
    ans += temp-temp2
  elif temp < temp2:
    ans += temp
  
  
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 i in c:
  if i < c[i]:
    ans+=c[i]-i
  elif i > c[i]:
    ans+=c[i]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
from collections import Counter
ans = 0
for k,v in Counter(A).items():
    if v!=k and k>v:
        ans+=v
    elif v!=k and k<v:
        ans+=v-k
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

import collections
c = collections.Counter(A)
ans = 0
for k in c.keys():
    if c[k] > k:
        ans += c[k] - k
    elif c[k] < k:
        ans += c[k]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
as_ = map(int, input().strip().split())

d = defaultdict(int)

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

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

print(counts)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc082/tasks/arc087_a
from collections import Counter
n = int(input())
nums = [int(i) for i in input().split()]
c = Counter(nums)


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

Submission status: Accepted

Solution code:
n = int(input())

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

import collections

c = collections.Counter(al)

res = 0
temp =0
for i in range(1,n+1):
    if c[i] ==0:
        pass
    elif c[i] ==i:
        temp += c[i]
        pass
    else:
        temp += c[i]
        if c[i] >i:
            res += c[i]-i
        else :
            res +=c[i]

res += (n-temp)
print(res)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = list(map(int, read().split()))

dic = {}
ans = 0

for i in range(n):
  ans += 1
  try:
    dic[a[i]] += 1
    if dic[a[i]] == a[i]:
      ans -= a[i]
  except KeyError:
    dic[a[i]] = 1
    if dic[a[i]] == a[i]:
      ans -= a[i]

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = Counter(map(int, input().split()))
cnt = 0

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

print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter

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

cnt = Counter(a)
ans = 0
for key, val in cnt.items():
    if val < key:
        ans += val
    else:
        ans += val - key

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 a in c:
    if c[a]-a>=0:
        cnt+=min(c[a]-a,c[a])
    else:
        cnt+=c[a]
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

b = collections.Counter(a)

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
al = list(map(int,input().split()))
C = Counter(al)

ans = 0
for i in C.keys():
    if i in C:
        if C[i] == i:
            continue
        elif C[i] > i:
            ans += C[i] - i
        else:
            ans += C[i]
print(ans)

Submission status: Accepted

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

x = {}

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


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


print(ans)

Submission status: Accepted

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

from collections import Counter

c = Counter(a)

cnt=0
for i in c.items():
    if i[0]==i[1]:
        continue
    elif i[0]>i[1]:
        cnt+=i[1]
    elif i[0]<i[1]:
        cnt+=(i[1]-i[0])

print(cnt)

Submission status: Accepted

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
ans=0
for k in d:
    if(d[k]<k):
        ans+=d[k]
    else:
        ans+=(d[k]-k)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


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

Submission status: Accepted

Solution code:
from collections import Counter

N,*a = map(int, open(0).read().split())
c = Counter(a)
ans = 0
for x in c.items():
    if x[1] >= x[0]:
        ans += x[1] - x[0]
    else:
        ans += x[1]
print(ans)

Submission status: Accepted

Solution code:
import collections

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

ac = collections.Counter(a)
ans = 0

for i in s:
    if ac[i] < i:
        ans += ac[i]
    else:
        ans += ac[i] - i

print(ans)

Submission status: Accepted

Solution code:
#import numpy as np
n = int(input())
a = list(map(int,input().split()))
base = [0]*n
ans = 0

for i in range(n):
  if a[i] > n:
    ans += 1
  else:
    base[a[i]-1] += 1
    
for i in range(n):
  if base[i] == 0:
    continue
  elif base[i] == i+1:
    continue
  elif (base[i] < i+1) and (0 < base[i]):
    ans += base[i]
  elif i+1 < base[i]:
    ans += (base[i] - (i+1))
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

d = {}
ans = 0

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

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

print(ans)

Submission status: Accepted

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

for i in a:
  if i not in dict:
    dict[i] = 1
  else:
    dict[i] += 1
    
for k,v in dict.items():
  if k > v:
    ans += v
  else:
    ans += v-k
    
print(ans)

Submission status: Accepted

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

arr=collections.Counter(a)
ans=0
for i in arr:
    if i<=arr[i]:
        ans+=(arr[i]-i)
    else:
        ans+=arr[i]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=Counter(input().split())
ans=0
for i,j in a.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())
aaa = list(map(int, input().split()))
cnt_a = Counter(aaa)
ans = 0
for key in cnt_a.keys():
    value = cnt_a[key]
    if key > value:
        ans += value
    elif key < value:
        ans += value - key
    else:
        continue
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
c = Counter(input().split())
ans = 0
for q, w in c.items():
    q, w = int(q), int(w)
    ans += w - q if q < w else (w if q != w else 0)
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 key in C.keys():
    if key > C[key]:
        ans += C[key]
    elif key < C[key]:
        ans += C[key]-key
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
aN=list(map(int,input().split()))
dic={}
for a in aN:
  if a in dic:
    dic[a] += 1
  else:
    dic[a] = 1
ans=0
for k,v in dic.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()))

from collections import Counter

z = Counter(a)

i,j,temp = (0,0,0)
for tu in z.items():
    i,j = tu
    if i>j:
        temp+=j
    elif i<j:
        temp+=j-i
    else:
        continue

print(temp)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
b = list(map(int, input().split()))
cntr = Counter(b)

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

Submission status: Accepted

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

num_count = {}
for num in a:
    if num in num_count:
        num_count[num] += 1
    else:
        num_count[num] = 1
ans = 0
for key in num_count:
    if key < num_count[key]:
        ans += num_count[key] - key
    elif key > num_count[key]:
        ans += num_count[key]
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N = INT()
a = LIST()

A = defaultdict(int)

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

#print(A)
ans = 0
for key in A.keys():
	if key > A[key]:
		ans += A[key]
	else:
		ans += A[key] - key

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N = INT()
a = LIST()

A = Counter(a)
#print(A)
ans = 0
for key, value in A.items():
	if key > value:
		ans += value
	else:
		ans += value - key

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N = INT()
a = LIST()

A = Counter(a)
#print(A)
ans = 0
for x in A:
	if x > A[x]:
		ans += A[x]
	else:
		ans += A[x] - x

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

count_num = dict()
for num in L:
  if num not in count_num:
    count_num[num] = 1
  else:
    count_num[num] += 1

removals = 0
for k, v in count_num.items():
  if k == v:
    continue
  elif k < v:
    removals += (v - k)
  else:
    removals += v

print(removals)

Submission status: Accepted

Solution code:
from collections import Counter

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

a_c = Counter(A)

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

Submission status: Accepted

Solution code:
from collections import Counter

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

print(ans)

Submission status: Accepted

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

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

ans=0
for key,number in dic.items():
    if number<key:
        ans+=number
    else:
        ans+=number-key
print(ans)