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=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:
    cnt=0
    while True:
      if A.count(a)==a or A.count(a)==0:
        break
      else:
        A.remove(a)
        cnt+=1
    ans+=cnt
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
cnt = {}
for i in range(N):
  if a[i] in cnt.keys():
	  cnt[a[i]] += 1
  else:
      cnt[a[i]] = 1

ans = 0
for i in cnt:
  if cnt[i] > int(i):
      ans += cnt[i] - int(i)
  elif int(i) > cnt[i]:
      ans += cnt[i]

print(ans)

Submission status: Time Limit Exceeded

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

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

del_cnt = 0
for num in count:
  if num < count[num]:
    del_cnt += (count[num] - num)
  elif num > count[num]:
    del_cnt += count[num]

print(del_cnt)

Submission status: Time Limit Exceeded

Solution code:
# C - Good Sequence
N = int(input())
a = list(map(int, input().split()))
count = 0

a.sort(reverse=True)
a_1 = list(set(a))
for i in range(len(a_1)):
    if a_1[i] == a.count(a_1[i]):
        pass
    elif a_1[i] < a.count(a_1[i]):
        count += a.count(a_1[i])-a_1[i]
    else:
        count += a.count(a_1[i])

print(count)

Submission status: Time Limit Exceeded

Solution code:
# C - Good Sequence
N = int(input())
a = list(map(int, input().split()))
count = 0

for i in range(N):
    if a[i] == a.count(a[i]):
        pass
    else:
        a[i] = ''
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
aList = list(map(int, input().split()))
tmp = set(aList)
tmpLst = list(tmp)
ans = 0

for i in tmpLst:
    t1 = aList.count(i)
    t2 = t1 - i
    if t2 > 0:
        ans += t2
    elif t2 < 0:
        ans += t1
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
c19 = 0
for i in range(1,100001):
    ca = a.count(i)
    if ca >= i:
        ans += ca - i
    else:
        ans += ca
    c19 += ca
print(ans + n-c19)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
l = []
ans = 0
for x in a:
    if x not in l:
        num = a.count(x)
        if num > x:
            ans += num-x
        if num < x:
            ans += num
        l.append(x)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
_,*l=map(int,open(0).read().split())
a=0
for i in list(set(l)):
	c=l.count(i)
	a+=c-i*(c>=i)
print(a)

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
lst = [int(i) for i in input().split()]

typ = list(set(lst))
cnt = 0
for i in range(len(typ)):
    k = typ[i]
    c = lst.count(k)
    if c > k:
        cnt += c - k
    elif c < k:
        cnt += c
print(cnt)

Submission status: Time Limit Exceeded

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

aset = set(a)

ans = 0

for i in aset:
    if a.count(i) < i:
        ans += a.count(i)
    else:
        ans += a.count(i) - i

print(ans)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

dic={}
keylist=list(set(a))
cnt=0
for i in range(len(keylist)):
    serchingnum=keylist[i]
    num=a.count(serchingnum)
    if num>=serchingnum:
        cnt+=num-serchingnum
    else:
        cnt+=num
print(cnt)

Submission status: Time Limit Exceeded

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

A_set = list(set(A))
ans = 0
for i in range(len(A_set)):
  nm = A_set[i]
  nm_cnt = A.count(nm)
  if nm > N:
    ans += nm_cnt
    continue
  
  if nm_cnt < nm:
    ans += nm_cnt
  elif nm_cnt > nm:
    ans += nm_cnt - nm
  N -= nm_cnt

print(ans)

Submission status: Time Limit Exceeded

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

A_set = list(set(A))
ans = 0
for i in range(len(A_set)):
  nm = A_set[i]
  nm_cnt = A.count(nm)
  
  if nm > N:
    ans += nm_cnt
    continue
  
  if nm_cnt < nm:
    ans += nm_cnt
  elif nm_cnt > nm:
    ans += nm_cnt - nm
  else:
    continue

print(ans)

Submission status: Time Limit Exceeded

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

A_set = list(set(A))
ans = 0
for i in range(len(A_set)):
  nm = A_set[i]
  nm_cnt = A.count(nm)
  if nm_cnt < nm:
    ans += nm_cnt
  elif nm_cnt > nm:
    ans += nm_cnt - nm
  else:
    continue

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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:
    j=a.count(i)
    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()))
s=set(a)
ans=0
for i in s:
    j=a.count(i)
    if j<i:
        ans+=j
    if i<j:
        ans+=j-i
print(ans)

Submission status: Time Limit Exceeded

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

res = 0

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l1=list(map(int,input().split()))
l2=[]
ans=0
for i in range(n):
    if l1[i] in l2:continue
    l2.append(l1[i])
    if l1[i]<=l1.count(l1[i]):
        ans+=l1.count(l1[i])-l1[i]
    else:
        ans+=l1.count(l1[i])
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
a_as = [0 for _ in range(max(a))]

for x in a:
    a_as[x-1] += 1

for i,cnt in enumerate(a_as):
    if cnt == 0 or cnt == i+1:
        continue
    elif cnt > i+1:
        ans += cnt - (i+1)
    else:
        ans += cnt
    
print(ans)

Submission status: Time Limit Exceeded

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

a.sort()
i = 0
ans = 0

seen = []

while i < N:
    x = a[i]
    if x in seen:
        ans += 1
        i += 1
        continue
    else:
        seen.append(x)

    cnt = 1
    j = 1
    flag = True
    while j < x and i+j < N and flag:
        if a[i+j] != x:
            flag = False
        else:
            cnt += 1
        j += 1
            
    if not flag or cnt != x:
        ans += cnt
    i += cnt

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
A=[int(i) for i in input().split()]
list_a=copy.deepcopy(A)
set_A=set(list_a)
ans=0
for i in set_A:
    a=A.count(i)
    if a<i:
        ans+=a
    elif i<a:
        ans+=a-i

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
A=sorted([int(i) for i in input().split()])
list_a=copy.deepcopy(A)
set_A=set(list_a)
ans=0
for i in set_A:
    a=A.count(i)
    if a<i:
        ans+=a
    elif i<a:
        ans+=a-i

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
AA=list(set(A))
ans=0
for a in AA:
    aa=A.count(a)
    if aa>=a:
        ans+=aa-a
    else:
        ans+=aa
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
for i in set(a):
	if i <= a.count(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()))
A_list = list(set(A))
count = 0

for c in A_list:
    C = A.count(c)
    if C >= c:
        count += C - c
    else:
        count += C

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=input()
a=list(map(int,input().split()))
a.sort()
#print(a)
i=0
ans=0
while i!=len(a):
    x=a[i]
    x1=a.count(x)
    if x<x1:
        ans=ans+x1-x
    elif x>x1:
        ans=ans+x1
    else:
        pass
    i=i+x1
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):
	cnt = a.count(i)
	if i < cnt: ans+=cnt-i
	elif i > cnt: ans += cnt
print(ans)

Submission status: Time Limit Exceeded

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

d = {}
for ai in a:
  if not ai in d:
    d[ai] = a.count(ai)

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

print(cnt)

Submission status: Time Limit Exceeded

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

l = []
cnt = 0
for i in range(n):
  if not a[i] in l:
    tmp = a.count(a[i])
    if a[i] > tmp:
      cnt = cnt + tmp
    elif a[i] < tmp:
      cnt = cnt + tmp - a[i]
    l.append(a[i])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = {}
for ai in a:
  if not ai in d:
    d[ai] = a.count(ai)

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = {a: A.count(a) for a in set(A)}
ans = 0
for k, v in A.items():
    if k > v:
        ans += v
    elif k < v:
        ans += v - k
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = {a: A.count(a) for a in A}
ans = 0
for k, v in A.items():
    if k > v:
        ans += v
    elif k < v:
        ans += v - k
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = sorted([int(x) for x in input().split()])
i,ans = 0,0
while i < N:
    c = a.count(a[i])
    if c > a[i]:
        ans += c-a[i]
    elif c < a[i]:
        ans += c
    i += c

print(ans)

Submission status: Time Limit Exceeded

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

c = 0

for i in a:
    if a.count(i) < i:
        a.remove(i)
        c += 1
    
for i in a:
    if a.count(i) > i:
        a.remove(i)
        c += 1
        
print(c)

Submission status: Time Limit Exceeded

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

setA = list(set(A))

d = {a: A.count(a) for a in setA}


#print(d)
r = 0
for k, v in d.items():
    if v > k:
        r += v - k
    elif k > v:
      	r += v

print(r)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

a.sort()
pullout = 0
#print(a)

for i in range(1,max(a)+1):
    numi = bisect.bisect_right(a,i) - bisect.bisect_left(a,i)
    #print(i,numi)
    if numi == 0 or numi == i:
        continue
    elif numi > i:
        pullout += numi - i
    elif numi < i:
        pullout += numi

print(pullout)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
hoge=list(map(int,input().split()))
nokosu=0
huga=list(set(hoge))
for i in range(len(huga)):
  kaz=huga[i]
  if(hoge.count(kaz)>=kaz):
    nokosu+=kaz
print(n-nokosu)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
hoge=list(map(int,input().split()))
nokosu=0
for i in range(n):
  kaz=i+1
  if(hoge.count(kaz)>=kaz):
    nokosu+=kaz
print(n-nokosu)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
li = list(set(a))
a.sort()
li.sort()
count = 0
for i in range(len(li)):
    tmp1= a.count(li[i])
    tmp2 = li[i]
    if tmp1 > tmp2:
        count += tmp1-tmp2
    elif tmp2 > tmp1:
        count += tmp1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
li = list(set(a))
a.sort()
li.sort()
count = 0
for i in range(len(li)):
    tmp1= a.count(li[i])
    tmp2 = li[i]
    if tmp1 > tmp2:
        count += tmp1-tmp2
    elif tmp2 > tmp1:
        count += tmp1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
li = list(set(a))
a.sort()
li.sort()
count = 0
for i in range(len(li)):
    if a.count(li[i]) > li[i]:
        count += a.count(li[i])-li[i]
    elif li[i] > a.count(li[i]):
        count += a.count(li[i])
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

counter_remove = 0
counter = dict()
counter_keys = []
for i in range(n):
    if a[i] not in counter_keys:
        counter_keys.append(a[i])
        counter[str(a[i])] = 1
    else:
        if counter[str(a[i])] < a[i]:
            counter[str(a[i])] += 1
        else:
            counter_remove += 1

# remove small
for key in counter_keys:
    if counter[str(key)] < int(key):
        counter_remove += int(counter[str(key)])

print(counter_remove)

Submission status: Time Limit Exceeded

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

ans = 0
for i in set(a):
  c = a.count(i)
  if c >= i:
    ans += i
print(n - ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in set(a):
  c = a.count(i)
  if c >= i:
    ans += c - i
  else:
    ans += c
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

if N == 1:
  print(1 if int(input()) != 1 else 0)
  exit()

a = [int(x) for x in input().split()]
 
b = list(set(a))

c = []
for i in b:
  if a.count(i)-i < 0:
    c.append(a.count(i))
  else:
    c.append(a.count(i)-i)

print(sum(c))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


N = int(input())
a_list = list(map(int, input().split()))
a_list_unique = list(set(a_list))
cnt = 0
for i in a_list_unique:
    a_dict = a_list.count(i)
    if i <= a_dict:
        cnt +=  a_dict - i
    else:
        cnt += a_dict
print(cnt)

Submission status: Time Limit Exceeded

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


N = int(input())
a_list = list(map(int, input().split()))
a_list_unique = list(set(a_list))
cnt = 0
a_dict = {}
for i in a_list_unique:
    a_dict[i] = a_list.count(i)
    if i <= a_dict[i]:
        cnt +=  a_dict[i] - i
    else:
        cnt += a_dict[i]
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a_list = list(map(int, input().split()))
a_list_unique = list(set(a_list))
cnt = 0
a_dict = {}
for i in a_list_unique:
    a_dict[i] = a_list.count(i)
    if i <= a_dict[i]:
        cnt +=  a_dict[i] - i
    else:
        cnt += a_dict[i]
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a_list = list(map(int, input().split()))
a_list.sort()
cnt = 0
for i in range(N):
    if a_list[i] > N:
        cnt += len(a_list[i:])
        break
for i in range(1, N+1):
    if a_list.count(i) > i:
        cnt += a_list.count(i) - i
    elif a_list.count(i) < i:
        cnt += a_list.count(i)
    else:
        pass
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
d =  {}
a = list(map(int,input().split()))
for i in range(N):
    if a[i] not in d.keys():
        d[a[i]] = 1
    else:
        d[a[i]] +=1
ans = 0
for k,v in d.items():
    if v < k:
        ans += v
    else:
        ans += abs(v-k)
print(ans)

Submission status: Time Limit Exceeded

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

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

print(str(ans))

Submission status: Time Limit Exceeded

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

for i in range(len(aa)):
    cnt=a.count(aa[i])
    if cnt>aa[i]:
        ans+=cnt-aa[i]
    elif cnt<aa[i]:
        ans+=cnt

print(str(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for s in S:
    tmp=L.count(s)
    if tmp>s:
        ans+=tmp-s
    elif tmp<s:
        ans+=tmp

print(ans)

Submission status: Time Limit Exceeded

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

check = []

ans = 0
for i in a:
    if i not in check:
        check.append(i)
        tmp = a.count(i)
        if tmp < i:
            ans += tmp
        else:
            ans += tmp - i

print(ans)

Submission status: Time Limit Exceeded

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

b = list(set(a))

ans = 0
for i in b:
    tmp = a.count(i)
    if tmp < i:
        ans += tmp
    else:
        ans += tmp - i

print(ans)

Submission status: Time Limit Exceeded

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

b = list(set(a))

ans = 0
for i in b:
    if a.count(i) < i:
        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()))


checked = []
ans = 0
for i in a:
  if i not in checked:
    #多すぎる場合はその数になるまで取り除く
    if a.count(i) >= i:
      ans += a.count(i) - i
    else:
      #その値以下の数しかないので配列から取り除く
      ans += a.count(i)
    checked.append(i) 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
ctr=0
el=[]
for i in range(n):
    if a[i] not in el:
        num=a.count(a[i])
        el.append(a[i])
        if a[i]>num:
            ctr+=num
        else:
            ctr+=num-a[i]
print(ctr)

Submission status: Time Limit Exceeded

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

list = []
for x in a_n:
    if list == []:
        list.append([x,1])
    else:
        counter = 0
        for y in list:
            if y[0] == x:
                y[1] += 1
                counter = 1220
        if counter == 0:
            list.append([x,1])

counter = 0
for y in list:
    if y[0] > y[1]:
        counter += y[1]
    elif y[0] < y[1]:
        counter += y[1] - y[0]
print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
d =  {}
a = list(map(int,input().split()))
for i in range(N):
    if a[i] not in d.keys():
        d[a[i]] = 1
    else:
        d[a[i]] +=1
ans = 0
for k,v in d.items():
    if v < k:
        ans += v
    else:
        ans += abs(v-k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(map(int,input().split()))
t = {}
o = 0
for i in range(n):
    if s[i] not in t.keys():
        t[s[i]] = 1
    else:
        t[s[i]] += 1

for i,j in t.items():
    if i > j:
        o += j
    else:
        o += j - i

print(o)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(map(int,input().split()))
t = []
r = []
m = []
o = 0
for i in range(n):
    if s[i] not in t:
        t.append(s[i])
        r.append(1)
        m.append(0)
    else:
        r[t.index(s[i])] += 1
    
    p = t.index(s[i])
    if r[p] - t[p] >= 0 and m[p] == 0:
        m[p] = 1
        r[p] -= t[p]

print(sum(r))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
s = list(map(int,input().split()))
s1 = np.array(s)
t,r = np.array([]),np.array([])
o = 0
for i in range(n):
    if s[i] not in t:
        t = np.append(t,s[i])
        r = np.append(r,1)
    else:
        p = np.where(t == s[i])
        r[p] += 1

for i in range(len(t)):
    q = r[i] - t[i]
    if q >= 0:
        o += q
    else:
        o += r[i]

print(int(o))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(map(int,input().split()))
t = []
r = []
o = 0
for i in range(n):
    if s[i] not in t:
        t.append(s[i])
        r.append(1)
    else:
        p = t.index(s[i])
        r[p] += 1

for i in range(len(t)):
    q = r[i] - t[i]
    if q >= 0:
        o += q
    else:
        o += r[i]

print(o)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
max_a = max(a)
score = 0
for i in range(max_a):
	i_count = a.count(i + 1)
	if i_count != 0:
		if  i_count < i + 1:
			score += i_count
		elif i_count > i + 1:
			score += i_count - (i + 1)

print(score)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
max_a = max(a)
score = 0
for i in range(max_a):
	i_count = a.count(i + 1)
	if  i_count < i + 1:
		score += i_count
	elif i_count > i + 1:
		score += i_count - (i + 1)

print(score)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
A = list(set(a))
c = 0
ac = 0
for i in range(len(A)):
    ac = a.count(A[i])
    if ac >= A[i]:
        c += ac - A[i]
    elif ac > 0:
        c += ac
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
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 LSR(n): return [LS() for i in range(n)]
mod = 1000000007
 
#A
"""
a, b = LI()
print((a+b+1)//2)
"""
 
#B
"""
a = S()
a = a[:-1]
b = S()
b = b[:-1]
a.sort()
b.sort(reverse=True)
if a < b:
    print("Yes")
else:
    print("No")
"""
 
#C
n = I()
a = LI()
seta = set(a)
ans = 0
for i in seta:
    x = a.count(i)
    if x != 0 and x >= i:
        ans += x - i
    else:
        ans += x
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
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 LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
"""
a, b = LI()
print((a+b+1)//2)
"""

#B
"""
a = S()
a = a[:-1]
b = S()
b = b[:-1]
a.sort()
b.sort(reverse=True)
if a < b:
    print("Yes")
else:
    print("No")
"""

#C
n = I()
a = LI()
seta = set(a)
ans = 0
for i in seta:
    x = a.count(i)
    if x != 0 and 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
_a = set(a)
for x in _a:
    y = a.count(x)
    if y < x:
        ans += y
    elif y > x:
        ans += y - x
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

dic = list(set(a))
count = 0
for x in dic:
    if a.count(x) > x:
        count+= a.count(x) - x
    elif a.count(x) < x:
        count += a.count(x)
print(count)

Submission status: Time Limit Exceeded

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

dic = []
count = 0
for x in a:
    if x not in dic:
        dic.append(x)
        if a.count(x) > x:
            count+= a.count(x) - x
        elif a.count(x) < x:
            count += a.count(x)
print(count)

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=[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())
li_a = input().split()

result = 0
for i in set(li_a):
    cnt = li_a.count(i)
    if cnt > int(i):
        result += cnt - int(i)
    elif cnt < int(i):
        result += cnt

print(result)