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:
import sys
n=int(sys.stdin.readline().strip("\n"))
num_list=sys.stdin.readline().strip("\n").split(" ")
num_list_1=[]
num_list_2=[]
num=0
for i in range(n):
    if int(num_list[i]) not in num_list_1:
        num_list_1.append(int(num_list[i]))
        num_list_2.append(1)
    else:
        num_list_2[num_list_1.index(int(num_list[i]))]+=1
for i in range(len(num_list_1)):
    if num_list_2[i]>=num_list_1[i]:
        num+=num_list_2[i]-num_list_1[i]
    else:
        num+=num_list_2[i]   
print(num)

Submission status: Time Limit Exceeded

Solution code:
import sys
n=int(sys.stdin.readline().strip("\n"))
num_list=sys.stdin.readline().strip("\n").split(" ")
for i in range(n-1):
    for j in range(n-1):
        if num_list[j]>num_list[j+1]:
            num_list[j],num_list[j+1]=num_list[j+1],num_list[j]
num_list.append('-1')
m=int(num_list[0]);k=1;num=0
for i in range(1,n+1):
    if num_list[i]==num_list[i-1]:
        k+=1
    else:
        if k>=m:
            num+=k-m
        else:
            num+=k
        m=int(num_list[i])
        k=1
print(num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_lst = [int(elem) for elem in input().split()]

keys = list(set(a_lst))
cnt = 0
for k in keys:
  if a_lst.count(k) > k:
    cnt += a_lst.count(k) - k
  elif a_lst.count(k) < k:
    cnt += a_lst.count(k)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    s = set(a)
    ans = 0
    for x in s:
        y = a.count(x)
        if x == y:
            continue
        if x > y:
            ans += y
        else:
            ans += y - x

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

ans = 0
for a in set(A):
    cnt = A.count(a)
    if a == cnt: continue
    elif a < cnt: ans += cnt-a
    elif a > cnt: ans += cnt
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for a in set(A):
    if a == A.count(a): continue
    elif a < A.count(a): ans += A.count(a)-a
    elif a > A.count(a): ans += A.count(a)
print(ans)

Submission status: Time Limit Exceeded

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

a.sort()
amax=a[-1]
amin=a[0]

dn=0
for i in range(amin,amax+1):
    ni=a.count(i)
    if ni>i:
        dn=dn+(ni-i)
    elif ni<i:
        dn=dn+ni

print(dn)

Submission status: Time Limit Exceeded

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

b = list(set(a))
delete = 0

for i in b:
  c = a.count(i)
  if c < i:
    delete += c
  elif c > i:
    delete += c - i
    
print(delete)

Submission status: Time Limit Exceeded

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

delete = 0
b = list(set(a))

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a_l=sorted(map(int,input().split()))
a_s=set(a_l)
cnt = 0

for a1 in a_s:
    cnt1 = a_l.count(a1)
    cnt2 = cnt1 - a1
    if cnt2 >= 0:
        cnt += cnt2
    else:
        cnt += cnt1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
b = [i for i in a if i <= 10**5]
#for i in a:
  #if i > 10**5:
    #break
  #else:
    #b.append(i)
ans = len(a)-len(b)
for i in range(1,10**5+1):
  if b.count(i) == i or 0:
    continue
  elif b.count(i) < i:
    ans += b.count(i)
  elif b.count(i) > i:
    ans += b.count(i)-i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
b = []
for i in a:
  if i > 10**5:
    break
  else:
    b.append(i)
ans = len(a)-len(b)
for i in range(1,10**5+1):
  if b.count(i) == i or 0:
    continue
  elif b.count(i) < i:
    ans += b.count(i)
  elif b.count(i) > i:
    ans += b.count(i)-i
print(ans)

Submission status: Time Limit Exceeded

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

s = set(l)

x=0
for i in s:
    y = l.count(i)
    if i <= y:
        x += y - i
    else:
        x += y

print(x)

Submission status: Time Limit Exceeded

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

s=list(set(l))

x=0
for i in s:
    y = l.count(i)
    if i <= y:
        x += y - i
    else:
        x += y

print(x)

Submission status: Time Limit Exceeded

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

s=list(set(l))

x=0
for i in s:
    if i <= l.count(i):
        x += l.count(i) - i
    else:
        x += l.count(i)

print(x)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = list(map(int,input().split()))
    B = list(set(A))
    ans = 0
    for v in B:
        tmp = A.count(v)
        if tmp < v:
            ans += tmp
        else:
            ans += tmp-v
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

s=set(a)
count=0

for i in s:
    if a.count(i)-i<0:
        count+=a.count(i)
    else:
        count+=a.count(i)-i
print(count)

Submission status: Time Limit Exceeded

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

for i in aa:
	if i == 1:
		ans += a.count(i)-1
	else:
		ans += a.count(i)%i
print(ans)

Submission status: Time Limit Exceeded

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

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 range(len(b)):
    if a.count(b[i]) > b[i]:
        ans += a.count(b[i]) - b[i]
    elif a.count(b[i]) < b[i]:
        ans += a.count(b[i])
print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0
pos = 0

while (pos < N):
    
    cur_value = sequence[pos]
    tmp_cnt = sequence.count(cur_value)
    
    if (tmp_cnt < cur_value):
        cnt += tmp_cnt
    else:
        cnt += tmp_cnt - cur_value
    
    pos += tmp_cnt

print(cnt)

Submission status: Time Limit Exceeded

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

d = {}
for ai in a:
    if ai in d.keys():
        d[ai] += 1
    else:
        d[ai] = 1

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

print(ans)

Submission status: Time Limit Exceeded

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

d = {}
for ai in a:
    if ai not in d.keys():
        d[ai] = 1
    else:
        d[ai] += 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
a.sort()
b = set(a)
ans = 0
for i in b:
    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:
n = int(input())
A = list(map(int, input().split()))

B = set(A)
t = 0
for i in B:
    s = A.count(i)
    if s >= i:
        t += s - i
    else:
        t += s
print(t)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt=0
set_alist=list(set(a))
for i in range(len(set_alist)):
  acount=a.count(set_alist[i])
  if acount!=set_alist[i]:
    if acount>set_alist[i]:
      cnt+=acount-set_alist[i]
    else:
      cnt+=acount
  
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
for t in set(a):
  cnt = a.count(t)
  if t > cnt:
    ans += cnt
  else:
    ans += (cnt -t)

print(ans)

Submission status: Time Limit Exceeded

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

b = list(set(a))
m = len(b)

ans = 0
for i in range(m):
    c = a.count(b[i])
    if b[i] > c: ans += c
    if b[i] < c: ans += c - b[i]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))

counter = 0
AN = set(A)
A = np.array(A)

for i in AN:
    if len(A[A==i]) < i:
        counter += len(A[A == i])
    else:
        counter += (len(A[A == i]) - i)

print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
L = list(set(l))
count = 0
for x in L:
  num = l.count(x)
  if num == x:
    continue
  elif num > x:
    count += num - x
  else:
    count += num
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline

n = int(input())
l = list(map(int, input().split()))
L = list(set(l))
count = 0
for x in L:
  if l.count(x) == x:
    continue
  elif l.count(x) > x:
    count += l.count(x) - x
  else:
    count += l.count(x)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
L = list(set(l))
count = 0
for x in L:
  if l.count(x) == x:
    continue
  elif l.count(x) > x:
    count += l.count(x) - x
  else:
    count += l.count(x)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
d={}
l=[]
for i in range(n):
    if l.count(a[i])==0:
        d[a[i]]=1
        l.append(a[i])
    else:
        d[a[i]]+=1

ans=0
for i in range(len(l)):
    if d[l[i]]>l[i]:
        ans+=d[l[i]]-l[i]
    elif d[l[i]]<l[i]:
        ans+=d[l[i]]
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

A.sort()

ans = 0
while True:
    count = A.count(A[0])
    if count > A[0]:
        ans += count - A[0]
    elif count < A[0]:
        ans += count
    A = A[count:]
    if len(A) == 0:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = set(a)
b = list(b)
x = [0 for i in range(len(b))]
for i in a:
    y = b.index(i)
    x[y] += 1
ans = 0
for i,j in zip(b,x):
    if j < i:
        ans += j
    else:
        ans += j - i
print(ans)

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:
    x = a.count(i) 
    if x < i:
        count += x
    else:
        count += x - i
print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import collections
N=int(input())
A=list(map(int,input().split()))
c = collections.Counter(A)
ans=0
n=len(set(A))
for i in range(n):
    a=int(c.most_common()[i][0])
    b=c.most_common()[i][1]
    if a <= b:
        ans+=b-a
    else:
        ans+=b
print(ans)

Submission status: Time Limit Exceeded

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

A_set = set(A)
ans = 0

for a in A_set:
    count = A.count(a)
    if count >= a:
        ans += count - a
    else:
        ans += count

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
d = defaultdict(int)
N = int(input())
A = [int(i) for i in input().split()]
a = A.count
for i in set(A):
  d[i] = a(i)
cnt = 0
for i, j in d.items():
  if i < j:
    cnt += j-i
  elif i > j:
    cnt += j   
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
d = defaultdict(int)
N = int(input())
A = [int(i) for i in input().split()]
B = set(A)
for i in B:
  for j in A:
    if i == j:
      d[i] += 1
cnt = 0
for i, j in d.items():
  if i < j:
    cnt += j-i
  elif i > j:
    cnt += j   
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=set(a)
ans=0
for i in s:
  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:
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
for i in set(a):
    if a.count(i) - i < 0:
        ans += a.count(i)
    else:
        ans += a.count(i) - i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
removal=0
B=set(A)
for i in B:
  if A.count(i)-i<0:
    removal+=A.count(i)
  else:
    removal+=A.count(i)-i
print(removal)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
while len(A) > 0:
    count = 0
    for i in A:
        if i == A[0]:
            count += 1
        else:
            break
    if count >= A[0]:
        ans += count - A[0]
    else:
        ans += count
    A = A[count:]

print(ans)

Submission status: Time Limit Exceeded

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

while len(a)>0:
  item=a[0]
  t=a.count(item)
  #print(item,t,a)
  if t>item:
    cnt+=t-item
  elif t==item:
    pass
  else:
    cnt+=t
  del a[0:t]
  #print("after",a)
  
print(cnt)

Submission status: Time Limit Exceeded

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

while len(a)>0:
  item=min(a)
  t=a.count(item)
  #print(item,t,a)
  if t>item:
    cnt+=t-item
  elif t==item:
    pass
  else:
    cnt+=t
  del a[0:t]
  #print("after",a)
  
print(cnt)

Submission status: Time Limit Exceeded

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


b=set(a)

cnt=0

for item in b:
  t=a.count(item)
  if t>item:
    cnt+=t-item
  elif t==item:
    pass
  else:
    cnt+=t
    
print(cnt)

Submission status: Time Limit Exceeded

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

a.sort()
b=set(a)

cnt=0

for item in b:
  t=a.count(item)
  if t>item:
    cnt+=t-item
  elif t==item:
    pass
  else:
    cnt+=t
    
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy

num_list = []
def num_count(j):
    if j in set(num_list):
        return True
    else:
        num = a_copy.count(j)
        if j == num:
            num_list.append(j)
            return True
        else:
            return False

n = int(input())
a = list(map(int, input().split()))
a_copy = copy.copy(a)
del_count = 0

for i in range(n):
    if num_count(a[i]) == False:
        a_copy.remove(a[i])
        del_count += 1

print(del_count)

Submission status: Time Limit Exceeded

Solution code:
import copy

num_list = []
def num_count(j):
    if j in num_list:
        return True
    else:
        num = a_copy.count(j)
        if j == num:
            num_list.append(j)
            return True
        else:
            return False
        

n = int(input())
a = list(map(int, input().split()))
a_copy = copy.copy(a)
del_count = 0

for i in range(n):
    try:
        if num_count(a[i]) == False:
            a_copy.remove(a[i])
            del_count += 1
        else:
            pass
    except:
        pass

print(del_count)

Submission status: Time Limit Exceeded

Solution code:
import copy

num_list = []
def num_count(j):
    if j in num_list:
        return True
    else:
        num = a_copy.count(j)
        if j == num:
            num_list.append(j)
            return True
        else:
            return False
        

n = int(input())
a = list(map(int, input().split()))
a_copy = copy.copy(a)
del_count = 0

for i in range(n):
    try:
        if num_count(a[i]) == False:
            a_copy.remove(a[i])
            del_count += 1
            i -= 1
        else:
            pass
    except:
        pass

print(del_count)

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 range(len(b)):
	cnt = a.count(b[i])
	if (cnt > b[i]):
		ans += cnt - b[i]
	elif (cnt < b[i]):
		ans += cnt
print (ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
c=0
for x in b:
  c=a.count(x)
  if c>=int(x):
    for i in range(int(x)):
      a.remove(x)
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums = list(map(int, input().split(" ")))
counts = dict(zip(nums,[nums.count(i) for i in nums]))
res = 0
for i,j in counts.items():
	if i > j:
		res = res + j
	elif j > i:
		res = res + (j - i)
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_lst  = sorted(list(map(int, input().split())))
                                                                                                                                                                                                                                              
idx = 0
count = 0
for i in range(N):
    try:
        a = A_lst[idx]
    except IndexError:
        break
    a_count = A_lst.count(a)
    if a_count < a:
        count += a_count
    elif a_count > a:
        count += a_count - a
    idx += a_count
print(count)

Submission status: Time Limit Exceeded

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

count = 0
for i in set(A_lst):                                                                                                                                                                                                                          
    j = A_lst.count(i)
    if (i-j) > 0:
        count += j
    elif (i-j) < 0:
        count += j-i
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_lst  = list(map(int, input().split()))
A_set = list(set(A_lst))
A_count = [A_lst.count(a) for a in A_set]                                                                                                                                                                                                     

x = sum([j for i, j in zip(A_set, A_count) if (i-j) > 0])
y = sum([j-i for i, j in zip(A_set, A_count) if (i-j) < 0])
print(x+y)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def test():
    n = int(input())
    a = np.array(list(map(int,input().split())))
    b = set(a)
    ans = 0
    for i in b:
        c = sum(a==i)
        if c > i:
            ans += c - i
        elif c < i:
            ans += c
    print(ans)


if __name__ == "__main__":
    test()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
b=list(set(a))
num=[]
for i in range(len(b)):
  if a.count(b[i])>b[i]:
    num.append(a.count(b[i])-b[i])
  elif a.count(b[i])<b[i]:
    num.append(a.count(b[i]))
print(sum(num))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
b=A[:]
b=set(b)
cnt=len(A)
for j in b:
  x=A.count(j)
  if x==j:
    x=0
  elif x>j:
    for k in range(1,x-j+1):
      A.remove(j)
  elif x<j:
    for l in range(1,x+1):
      A.remove(j)
print(cnt-len(A))

Submission status: Time Limit Exceeded

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

s_a = set(a)
c_a = []
for i in s_a:
    c_a.append(a.count(i))
d_a = list(zip(s_a, c_a))

ans = 0
for i in d_a:
    if i[0] > i[1]:
        ans += i[1]
    if i[1] > i[0]:
        ans += i[1] - i[0]

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:
  tmp = a.count(i)
  if tmp!=i:
    if tmp<i:
      ans+=tmp
    else:
      ans+=tmp-i
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
aList = list(map(int, input().split()))
aLen = len(aList)
aSet = sorted(list(set(aList)))
aSum = 0
for a in aSet:
    aCount = aList.count(a)
    if aCount > a:
        aSum += aCount - a
    if aCount < a:
        aSum += aCount
    # aLen -= aCount
    # if a > aLen:
    #     aSum += aLen
    #     break

print(aSum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
aList = list(map(int, input().split()))
aSet = list(set(aList))
aSum = 0
for a in aSet:
    aCount = aList.count(a)
    if aCount > a:
        aSum += aCount - a
        continue
    if aCount == a:
        continue
    if aCount < a:
        aSum += aCount
        continue
print(aSum)

Submission status: Time Limit Exceeded

Solution code:
import collections
import copy
ans=0
N=int(input())
a = [int(i) for i in input().split()] 
b = copy.deepcopy(a)
c = list(set(b))
l=len(c)
for i in range(l):
    x=a.count(c[i])
    if c[i]>x:
        ans+=x
    else:
        ans+=x-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))
cnt = 0
for i in range(len(b)):
  c = a.count(b[i])
  if b[i] <= c:
    cnt += c - b[i]
  else:
    cnt += c
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
 
b=list(set(a))
c=0
for i in b:
    nc=0
    for j in range(len(a)):
        if a[j]==i:
          nc+=1
        else:
          nc+=0    
    c+= nc-i if nc-i>=0 else nc
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
 
b=list(set(a))
c=0
for i in b:
    nc=0
    for j in range(len(a)):
        if a[j]==i:
          nc+=1
        else:
          nc+=0    
    er = nc - i
    if er<0:
        c+= er+i
    else:
        c+=er
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
 
b=list(set(a))
c=0
for i in range(len(b)):
    er = a.count( b[i] ) - b[i]
    if er<0:
        c+= er + b[i]
    else:
        c+=er
print(c)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
 
b=list(set(a))
c=0
for i in range(len(b)):
    er = a.count( b[i] ) - b[i]
    if er<0:
        c+= a.count( b[i] )
    else:
        c+=er
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

b=list(set(a))
c=0
for i in range(len(b)):
    er = a.count( b[i] ) - b[i]
    if er<0:
        er = a.count( b[i] )
    c+=er
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

a.sort()
b=list(set(a))
c=0
for i in range(len(b)):  
  if a.count( b[i] ) != b[i]:
    er = a.count( b[i] ) - b[i]
    if er<0:
      er = a.count( b[i] )
    if er>0:
      for j in range(er):
        a.remove( b[i] )
        c+=1
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans=0
for a in set(A):
  cnt=A.count(a)
  if cnt==a:
    continue
  elif cnt<a:
    ans+=cnt
  else:
    ans+=min(cnt-a,cnt)
print(ans)

Submission status: Time Limit Exceeded

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

ans=0
for a in set(A):
  if A.count(a)==a:
    continue
  elif A.count(a)<a:
    ans+=A.count(a)
  else:
    ans+=min(A.count(a)-a,A.count(a))
print(ans)