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: Time Limit Exceeded

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

A = set(a)
ans = 0

for i in A:
    test = a.count(i)
    if test < i:
        ans += test
    elif test > i:
        ans += test - i
    else:
        pass

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
B = list(set(A[:]))
count = 0

for i in B:
    j = A.count(i)
    if j > i:
        count += j-i
    elif j < i:
        count += j
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
B = list(set(A[:]))
dict = defaultdict(int)
for i in range(len(B)):
    dict[B[i]] = A.count(B[i])
count = 0
for k, v in dict.items():
    if k > v:
        count += v
    elif k < v:
        count += v-k
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
input();a=list(map(int,input().split()))
print(sum([a.count(i) if (i-a.count(i))>(a.count(i)-i) else abs(i-a.count(i)) for i in set(a)]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
for i in set(a):
    if i <= a.count(i):
        n -= i
print(n)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
l = IL()
setl = list(set(l))
lenl = len(setl)
ans = 0
if len(l) == 0:
	pass
else:
	for i in range(lenl):
		num = setl[i]
		tmp = l.count(num)
		if tmp < num:
			ans += tmp
		else:
			ans += tmp-num

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
l = IL()
setl = list(set(l))

ans = 0
if len(l) == 0:
	pass
else:
	for i in range(len(setl)):
		tmp = l.count(setl[i])
		if tmp < setl[i]:
			ans += tmp
		else:
			ans += tmp-setl[i]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
c = 0
d = 0
for i in range(n):
  if a[i] != c:
    if a.count(a[i]) >= a[i]:
      d += a.count(a[i]) - a[i]
    else:
      d += a.count(a[i])
    c = a[i]
print(d)

Submission status: Time Limit Exceeded

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

# c(i)をiのaにおける個数とする
res = 0

for i in set(a):
    # aにおけるiの個数
    ci = a.count(i)
    # c(i) > iの時は c(i) = i になるまで取り除くしかない
    if ci > i:
        res += ci - i
    # c(i) < iの時は，ci個取り除く
    elif ci < i:
        res += ci

print(res)

Submission status: Time Limit Exceeded

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

# c(i)をiのaにおける個数とする
res = 0

for i in set(a):
    # aにおけるiの個数
    ci = a.count(i)
    # c(i) > iの時は c(i) = i になるまで取り除くしかない
    if ci > i:
        res += ci - i
    # c(i) < iの時は，ci個取り除く
    elif ci < i:
        res += ci

print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
A = set(a)
cnt = 0
for i in A:
    k = a.count(i)
    if k<i:
        cnt += k
    else:
        cnt += k-i
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = input()

data = map(int,raw_input().split())
data.sort()

ans = 0
i = 0
while i < N:
    count = data.count(data[i])
    if count < data[i]:
        ans += count
    else:
        ans += count-data[i]
    i += count;

print ans

Submission status: Time Limit Exceeded

Solution code:
N = input()

data = map(int,raw_input().split())
data.sort()

ans = 0
pnum = -1
for i in data:
    if pnum != i:
        count = data.count(i)
        if count < i:
            ans += count
        else:
            ans += count-i
        pnum = i

print ans

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = input()
a = np.array([int(i) for i in input().split()])

a_unique = np.unique(a)

out = 0
for i in a_unique:
    count = np.sum(a==i)
    if(count < i):
        out += count
    else:
        out += count - i

print(out)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = input()
a = np.array([int(i) for i in input().split()])

a_unique = np.unique(a)

out = 0
for i in a_unique:
    count = np.sum(a==i)
    if(count==i):
        out += 0
    elif(count < i):
        out += count
    else:
        out += count - i

print(out)

Submission status: Time Limit Exceeded

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

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

print(rem)

Submission status: Time Limit Exceeded

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

rem = 0
d = [0]

for i in range(N):
    if not(a[i] in d):
        d.append(a[i])
        if a.count(a[i]) < a[i]:
            rem += a.count(a[i])
        elif a.count(a[i]) > a[i]:
            rem += a.count(a[i])-a[i]
print(rem)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Num = list(map(int,input().split()))
ki = []
count = 0
for i in range(N):
    if Num[i] in ki:
        pass
    else:
        c = Num.count(Num[i])
        if c > Num[i]:
            count+=(c-Num[i])
        elif c < Num[i]:
            count+=c
        else:
            pass
        ki.append(Num[i])
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input(). split()))
ans = 0
b = set(a)

for i in b:
    ai = a.count(i)
    if ai > i:
        ans += ai - i
    if ai < i:
        ans += ai

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = set(A)
ans = 0
for i in B:
    index = A.count(i)
    if(index > i):
        ans+=index - i
    elif(index < i):
        ans+=index
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = list(set(A))
ans = 0
for i in B:
    index = A.count(i)
    if(index > i):
        ans+=index - i
    elif(index < i):
            ans+=index
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
cnt = 0
ind = 1
while A != []:
  A = list(map(lambda x: x - 1, A))
  if(0 in A):
    zero = A.count(0)
    if(zero > ind):
      cnt += abs(zero - ind)
    elif(zero < ind):
      cnt += zero
    A = filter(lambda n: n != 0, A)
  ind += 1
print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0
ind = 1
while A != []:
  A = list(map(lambda x: x - 1, A))
  if(0 in A):
    zero = A.count(0)
    if(zero > ind):
      cnt += abs(zero - ind)
    elif(zero < ind):
      cnt += zero
    for _ in range(zero):
      A.remove(0)
  ind += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
check = list(set(A))
num = 0
for c in check:
  cnt = A.count(c)
  if c < cnt:
    num += abs(cnt- c)
  elif c > cnt:
    num += cnt
print(num)

Submission status: Time Limit Exceeded

Solution code:
def abc082_c():
    _ = int(input())
    a = list(map(int, input().split()))
    ans = 0

    for val in set(a):
        num = a.count(val)
        if num >= val:
            ans += (num-val)
        else:
            ans += num

    print(ans)


abc082_c()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
dic = {}
i_list = []
for a in a_list:
    dic[a] = 0
for a in a_list:
    dic[a] += 1
for i in a_list:
    if i not in i_list:
        i_list.append(i)
ans = 0
for i in i_list:
    p = dic[i] - i 
    if p >= 0:
        ans += p
    else:
        ans += dic[i]
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()] 
a_unique = list(set(a))
count = 0
for i in a_unique:
    check = i - a.count(i)
    if check < 0:
        count += abs(check)
    elif check > 0:
        count += i - check
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()] 
count = 0
for i in range(100000):
    if a.count(i) > 0:
        check = i - a.count(i)
        if check < 0:
            count += abs(check)
        elif check > 0:
            count += i - check
for i in a:
    if i > 100000:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# Good Sequence
n = int(input())
a = list(map(int, input().split()))
a_ = set(a)
p = 0
for i in a_:
    if a.count(i) < i:
        p += a.count(i)
    elif a.count(i) > i:
        p += a.count(i) - i
print(p)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
b = set()
for i in range(n):
    if a[i] in b:
        continue
    else:
        if a.count(a[i]) < a[i]:
            ans += a.count(a[i])
        elif a.count(a[i]) > a[i]:
            ans += a.count(a[i])-a[i]
        b.add(a[i])
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
br = set(ar)
count = 0
c = 0
while c != len(br):
    for r in br:
        if ar.count(r) == r:
            c += 1
        else:
            if r < ar.count(r):
                count += ar.count(r) - r
            else:
                count += ar.count(r)
            c += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
l=set(L)
ls=list(l)
#print(len(l))
ans=0
for i in range(len(l)):
    if L.count(ls[i])>ls[i]:
        ans+=L.count(ls[i])-ls[i]
    elif L.count(ls[i])<ls[i]:
        ans+=L.count(ls[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = 0
if n==0 and len(a)==0:
  print(n)
elif n==0:
  print(len(a))
else:
  for i in set(a):
    if a.count(i)>i:
      b += a.count(i)-i
    elif a.count(i)<i:
      b += a.count(i)
  print(b)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
ans = 0
for a in A[::-1]:
    if A.count(a) != a:
        A.remove(a)
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

ans = n
for x in set(a):
    if a.count(x) >= x:
        ans -= x

print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0

b = set(a)

for i in b:
    c = a.count(i)
    if c > i:
        cnt += c - i
    elif c == i:
        continue
    else:
        cnt += c

print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0

b = set(a)

for i in b:
    if a.count(i) > i:
        cnt += a.count(i) - i
    elif a.count(i) == i:
        continue
    else:
        cnt += a.count(i)

print(cnt)

Submission status: Time Limit Exceeded

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

l=[]
ans=0

for i in a:
    if not i in l:
        l.append(i)

for i in l:
    if a.count(i)<i:
        ans+=a.count(i)
    elif a.count(i)>i:
        ans+=a.count(i)-i
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
T = list(set(A))
L = []
for i in range(len(T)) :
    ti = T[i]
    t = A.count(ti)
    if t < ti :
        L.append(t)
    else :
        L.append(t - ti) 
print(sum(L))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
T = list(set(A))
L = []
for i in range(len(T)) :
    if A.count(T[i]) < T[i] :
        L.append(A.count(T[i]))
    else :
        L.append(A.count(T[i]) - T[i])
print(sum(L))

Submission status: Time Limit Exceeded

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

for ai in set_a:
  ai_count = a.count(ai)
  if ai_count >= ai:
  	ans += ai_count - ai  
  else:
    ans += ai_count

print(ans)

Submission status: Time Limit Exceeded

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

for ai in set_a:
  ai_count = a.count(ai)
  ans += ai_count - ai if ai_count >= ai else ai_count

print(ans)

Submission status: Time Limit Exceeded

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

for ai in set_a:
    ans += a.count(ai) - ai if a.count(ai) >= ai else a.count(ai)

print(ans)

Submission status: Time Limit Exceeded

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

if __name__ == "__main__":
    N = int(input())
    a_list = list(map(int, input().split()))
    ans = 0

    # 初期設定
    ans = 0
    a_set = set(a_list)

    for a in a_set:
        c = a_list.count(a) # 要素の出現回数をカウントする
        if c < a:
            ans += c
        elif c > a:
            ans += c-a
    print(ans)

Submission status: Time Limit Exceeded

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

dic = {}
for i in a:
    dic.update({i:a.count(i)})
#print(dic)
k = list(dic.keys())

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=list(map(int,input().split()))
a_s=set(a)
count = 0
for i in a_s:
    a_c=a.count(i)
    if a_c > i:
        count += a_c-i
    elif a_c < i:
        count += a_c
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
dic = {}
for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
ans = 0
for i in set(a):
    n = a.count(i)
    if n < i:
        ans += n
    else:
        ans += n-i
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

c = 0
d = 0 #i

while d <= n-1:
    s = a.count(a[d])
    if a[d] > s:
        c += s
    else:
        c += s-a[d]
    d = d + s
    
print(c)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=input()
a=a.rstrip().split(" ")
list1=[]
for i in range(N):
    list1.append(int(a[i]))
#print(list1)
lists=[]
for k in range(len(list1)):
    if list1[k] in lists:
        pass
    else:
        lists.append(list1[k])
#print(lists)
cnt=0
for j in range(len(lists)):
    if lists[j]>list1.count(lists[j]):
        cnt+=list1.count(lists[j])
    elif lists[j]<list1.count(lists[j]):
        cnt+=list1.count(lists[j])-lists[j]
print(cnt)

Submission status: Time Limit Exceeded

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

sum_num = 0
for a_i in set(a):
	a_count_a_i  = a.count(a_i)
	sum_num += a_count_a_i - a_i if a_i <= a_count_a_i else a_count_a_i
print(sum_num)

Submission status: Time Limit Exceeded

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

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

    a_set = set(a_list)
    min_cnt = 0
    for i in a_set:
        cnt = a_list.count(i)
        if cnt - i >= 0:
            min_cnt += cnt - i
        else:
            min_cnt += cnt

    print(min_cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
h = list(map(int, input().split()))
a = set(h)
s = 0
for i in a:
    while h.count(i) != i and h.count(i) != 0:
        h.remove(i)
        s += 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
h = list(map(int, input().split()))
h.sort()
a = set(h)
s = 0
for i in a:
    while h.count(i) != i and h.count(i) != 0:
        h.remove(i)
        s += 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
h = list(map(int, input().split()))
a = list(set(h))
s = 0
l = len(a)
if n == 1 and h[0] == 1:
    print(0)
elif n == 1 and h[0] != 1:
    print(1)
else:
    while l > 0:
        if h.count(a[l-1]) == a[l-1]:
            a.pop()
        elif h.count(a[l-1]) != a[l-1]:
            h.remove(a[l-1])
            s += 1
            if h.count(a[l-1]) == 0:
                a.pop()
        l = len(a)
        
    print(s)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
h = list(map(int, input().split()))
a = set(h)
s = 0
for i in a:
    while h.count(i) != i and h.count(i) != 0:
        h.remove(i)
        s += 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
h = list(map(int, input().split()))
a = set(h)
s = 0
for i in a:
    while h.count(i) != i and h.count(i) != 0:
        h.remove(i)
        s += 1
print(s)

Submission status: Time Limit Exceeded

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

count=0
for i in b:
    if a.count(i)==i:
        pass
    elif a.count(i)>i:
        for j in range(a.count(i)-i):
        	a.remove(i)
        	count+=1
    else:
        for j in range(a.count(i)):
        	a.remove(i)
        	count+=1
print(count)

Submission status: Time Limit Exceeded

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

count=0
for i in b:
    if a.count(i)==i:
        pass
    elif a.count(i)>i:
            count+=1*(a.count(i)-i)
    else:
            count+=1*a.count(i)
print(count)

Submission status: Time Limit Exceeded

Solution code:
input()
S=list(map(int,input().split()))
ans=0
for x in set(S):
    cnt=S.count(x)
    ans+=cnt-x*(cnt>=x)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = input()
arr = list(map(int, input().split()))
ar = [0 for i in range(max(arr))]
for i in arr:
    ar[i - 1] += 1
res = 0
for i in range(len(ar)):
    if ar[i] > i + 1:
        res += ar[i] - i - 1
    if ar[i] < i + 1:
        res += ar[i]
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = []
n = 0
for i in a:
  if i in b:
    pass
  elif a.count(i) == i:
    b.append(i)
  elif a.count(i) < i:
    b.append(i)
    n += a.count(i)
  else:
    b.append(i)
    n += a.count(i) - i
print(n)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
L = list(set(a))
res = 0

for i in L:
    X = a.count(i)
    if X < i:
        res += X
    
    else:
        res += X - i

print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
L = list(set(a))
res = 0

for i in L:
    if a.count(i) < i:
        res += a.count(i)
    
    else:
        res += a.count(i) - i

print(res)

Submission status: Time Limit Exceeded

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

for i in range(N):
    X = a.count(i+1)
    if a[i] > N:
        res += 1
        
    elif X < i+1:
        res += X
        i = i  + X
        
    else:
        res += X - (i+1)
        i = i  + X
        
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(int(i) for i in input().split())  
list = []
count = 0

for i in range(N):
    if S[i] not in list:
        num = S[i:].count(S[i])
        if num < S[i]:
            count += num
        elif num > S[i]:
            count += (num-S[i])
    list.append(S[i])

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(int(i) for i in input().split())  
list = []
count = 0

for i in range(N):
    if S[i] not in list:
        num = S.count(S[i])
        if num < S[i]:
            count += S.count(S[i])
        elif num > S[i]:
            count += (num-S[i])
    list.append(S[i])

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(int(i) for i in input().split())  
list = []
count = 0

for i in range(N):
    if S[i] not in list:
        if S.count(S[i]) < S[i]:
            count += S.count(S[i])
        elif S.count(S[i]) > S[i]:
            count += (S.count(S[i])-S[i])
        list.append(S[i])

print(count)

Submission status: Time Limit Exceeded

Solution code:
input()
l = list(map(int,input().split()))
m = set(l)
a = 0
for i in(m):
    while l.count(i) != i:
        if l.count(i) == 0:
            break
        l.remove(i)
        a += 1
        
print(a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
erase_cnt = 0
a_unique = list(set(a))

for x in a_unique:
    if a.count(x) >= x:
        erase_cnt += a.count(x) - x
    else:
        erase_cnt += a.count(x)

    a.remove(x)    

print(erase_cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
erase_cnt = 0
a_unique = list(set(a))

for x in a_unique:
    if a.count(x) >= x:
        erase_cnt += a.count(x) - x
    else:
        erase_cnt += a.count(x)

print(erase_cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
count=0
now=0
for i in range (N):
    counting=A.count(A[i])
    if A[i]==now:
        pass
    elif counting>A[i]:
        count+=A.count(A[i])-A[i]
    elif counting<A[i]:
        count+=counting
    now=A[i]
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
count=0
now=0
for i in range (N):
    if A[i]==now:
        pass
    elif A.count(A[i])>A[i]:
        count+=A.count(A[i])-A[i]
    elif A.count(A[i])<A[i]:
        count+=A.count(A[i])
    now=A[i]
print(count)

Submission status: Time Limit Exceeded

Solution code:
b = []
count = []
def sarch(num):
    for i in range(len(b)):
        if num == b[i]:
            return i
    b.append(num)
    count.append(0)
    return len(b) - 1
    
N = input()
a = list(map(int, input().split()))
ans = 0
for i in range(len(a)):
    if a[i] != 0:
        count[sarch(a[i])] += 1
for i in range(len(count)):
    if b[i] > count[i]:
        ans += count[i]
    elif b[i] < count[i]:
        ans += (count[i] - b[i])
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in A:
    num = a.count(i)
    if num>i:
        ans+=num-i
    elif num<i:
        ans+=num

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
s = list(set(a))
cnt = 0
for i in s:
    if a.count(i) == i:
        continue
    elif a.count(i) < i:
        cnt += a.count(i)
    else:
        cnt += a.count(i)-i
print(cnt)

Submission status: Time Limit Exceeded

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

ans = 0
for k in B:
    if k < A.count(k):
        ans += A.count(k)-k
    elif k > A.count(k):
        ans += A.count(k)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=list(map(int,input().split()))
t=list(set(s))
ans=0
for i in range(len(t)):
    u=s.count(t[i])-t[i]
    if u<0:
        ans+=s.count(t[i])
    if u>0:
        ans+=u
print(ans)

Submission status: Time Limit Exceeded

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

   a.sort()
   b = []
   c = []
   for a in a:
      if (a in b)==False:
         b.append(a)
         c.append(1)
      else:
         c[-1] += 1

   count = 0
   for i in range(len(b)):
      if b[i] < c[i]:
         count += c[i] - b[i]
      elif b[i] > c[i]:
         count += c[i]
   return count

print(main())

Submission status: Time Limit Exceeded

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

   a.sort()
   b = []
   c = []
   for i in range(len(a)):
      if (a[i] in b)==False:
         b.append(a[i])
         c.append(1)
      else:
         c[-1] += 1

   count = 0
   for i in range(len(b)):
      if b[i] < c[i]:
         count += c[i] - b[i]
      elif b[i] > c[i]:
         count += c[i]
   return count

print(main())

Submission status: Time Limit Exceeded

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

ans=0
for i in a_uniq:
  count=a.count(i)
  if count>i:
    ans+=count-i
  elif count<i:
    ans+=count

print(ans)

Submission status: Time Limit Exceeded

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

ans=0
for i in a_uniq:
  if a.count(i)>i:
    ans+=a.count(i)-i
  elif a.count(i)<i:
    ans+=a.count(i)

print(ans)

Submission status: Time Limit Exceeded

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

# AtCoder Beginner Contest
# Problem C

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

    for x in set(a):
        elements_count = a.count(x)

        if (elements_count >= x) and (x <= 10 ** 5):
            count += elements_count - x
        else:
            count += elements_count

    print(count)

Submission status: Time Limit Exceeded

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

# AtCoder Beginner Contest
# Problem C

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

    for x in set(a):
        elements_count = a.count(x)

        if elements_count >= x:
            count += elements_count - x
        else:
            count += elements_count

    print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
a.sort()
a_key = list(set(a))
ans = 0
for num in a_key:
    if a.count(num) < num:
        ans += a.count(num)
    else:
        ans += a.count(num) - num
print(ans)