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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
a = na()
a_lis = list(set(a))
count = 0
ans = [0]*len(a_lis)
for i in range(len(a_lis)):
    count = a.count(a_lis[i])
    if count > a_lis[i]:
        ans[i] = count - a_lis[i]
    elif count < a_lis[i]:
        ans[i] = count

if sum(ans) < n:
    print(sum(ans))
else:
    print(n)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
x2,answer = set(x),0
for j in x2:
	if x.count(j) < j : answer += x.count(j)
	elif x.count(j) > j: answer += x.count(j)-j
print(answer)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
x.sort()
z,answer = [],0
for j in x:
	if j not in z and x.count(j) < j : answer += x.count(j)
	elif j not in z and x.count(j) > j: answer += x.count(j)-j
	z.append(j)
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
x = [int(i) for i in input().split()]
y = copy.deepcopy(x)
for j in x:
	if x.count(j)<j:
		while y.count(j) != 0: y.remove(j)
	elif x.count(j)>j:
		while y.count(j) != j: y.remove(j)
print(len(x)-len(y))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in set(arr):
    cnt = arr.count(i)
    if cnt != i:
        if i < arr.count(i):
            ans += (abs(cnt - i))
        else:
            ans += cnt
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
set_a=list(set(a))
set_a.sort()
count=0
for i in set_a:
    if i<a.count(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=list(map(int,input().split()))
set_a=set(a)
count=0
for i in set_a:
    if i<a.count(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=list(map(int,input().split()))
set_a=list(set(a))
count=0
for i in set_a:
    if i<a.count(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=list(map(int,input().split()))
dlt=0
push=0
a.sort()
k=0
while(1):
    i=a[k+push]
    j=a.count(i)
    push+=j
    if(j>i):dlt+=j-i
    elif(i>j):dlt+=j
    if(k+push>=n):break
print(dlt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
dlt=0
already=[]
for i in a:
  if(i not in already):
    already.append(i)
    j=a.count(i)
    if(j>i):dlt+=j-i
    elif(i>j):dlt+=j

print(dlt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
dlt=0
while(len(a)):
  i=a[0]
  j=a.count(i)
  if(j>i):dlt+=j-i
  elif(i>j):dlt+=j
  for k in range(j):a.remove(i)
print(dlt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
dlt=0
while(len(a)):
  i=a[0]
  j=a.count(i)
  if(j>i):dlt+=j-i
  elif(i>j):dlt+=j
  while(i in a):a.remove(i)
print(dlt)

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

Submission status: Time Limit Exceeded

Solution code:
def C_Good_Sequence():
    N=int(input())
    a=list(map(int, input().split()))
    b=set(a)
    b=list(b)
    count=0
    ans=0 
    c=[]
    
    for i in b:
        for j in range(N):
            if a[j]==i:
                count += 1
        c.append(count)
        count=0

    for i in range(len(b)):
        if c[i]<b[i]:
            ans += c[i]
        elif c[i] >b[i]:
            ans += c[i]-b[i]
    print(ans)
   
C_Good_Sequence()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
nums=list(map(int,input().split(" ")))
ap=[]

for i in nums:
  ap.append(i)
b=list(set(ap))
co=0
for i in b:
  if ap.count(i)-i>=0:
	  co+=ap.count(i)-i
  else:
    co+=ap.count(i)
print(co)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sum = 0

for a in set(a_list):
    cnt = a_list.count(a)
    if a > cnt:
        sum += cnt
    else:
        sum += cnt - a

print(sum)

Submission status: Time Limit Exceeded

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

sum = 0

for a in set(a_list):
    cnt = a_list.count(a)
    if a > cnt:
        sum += cnt
    else:
        sum += cnt - a

print(sum)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
nums=input().split()
counter=Counter(nums).most_common()
k=0
for num, c in counter:
    num=int(num)
    if num==c:
        continue
    elif num>c:
        for v in range(c):
            nums.remove(str(num))
            k+=1
    else:
        for v in range(c-num):
            nums.remove(str(num))
            k+=1   

print(k)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
nums=input().split()
nums_uniq=[]

for n in nums:
    if n not in nums_uniq:
        nums_uniq.append(n)

k=0
for p in nums_uniq:
    if nums.count(p)==int(p):
        continue
    elif nums.count(p)>int(p):
        while nums.count(p)>int(p):
            nums.remove(p)
            k+=1
    else:
        while nums.count(p)>0:
            nums.remove(p)
            k+=1
print(k)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
nums=input().split()
nums_uniq=[]

for n in nums:
    if n not in nums_uniq:
        nums_uniq.append(n)

#print('uniqnum',nums_uniq)
k=0
for p in nums_uniq:
    if nums.count(p)==int(p):
        continue
    elif nums.count(p)>int(p):
        while nums.count(p)>int(p):
            #print('remove',p)
            nums.remove(p)
            k+=1
    else:
        while nums.count(p)>0:
            #print('remove',p)
            nums.remove(p)
            k+=1
print(k)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
nums=input().split()
firstl=len(nums)
nums.sort()
nums_uniq=[]

for n in nums:
    if n not in nums_uniq:
        nums_uniq.append(n)

#print('uniqnum',nums_uniq)
s=0
for num in nums_uniq:
    s+=int(num)
if len(nums)-s>0:
    print(len(nums)-s)
else:
    k=0
    for p in nums_uniq:
        if nums.count(p)==int(p):
            continue
        else:
            if nums.count(p)>int(p):
                while nums.count(p)>int(p):
                    #print('remove',p)
                    nums.remove(p)
                    k+=1
            else:
                while nums.count(p)>0:
                    #print('remove',p)
                    nums.remove(p)
                    k+=1
    print(k)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
count = 0
a =  list(map(int, input().split()))
while len(a) != 0:
    b = 0
    b = a.count(a[0])
    c = 0
    c = a[0]
    if c > b:
        count += b
    if c < b:
        count += b - c
    while a.count(c) != 0:
        a.remove(c)    
print (count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
count = 0
b = 0
a =  list(map(int, input().split()))
while len(a) != 0:
    b = a.count(a[0])
    if a[0] > b:
        count += b
    if a[0] < b:
        count += b - a[0]
    a = [item for item in a if item is not a[0]]
print (count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
#put a_i into list
list_a_i = list(sorted(map(int, input().split())))
remove = 0
while len(list_a_i) >=1:
    #count number of list_a_i[1]
    x = list_a_i.count(list_a_i[0])
    if x > list_a_i[0]:
        remove += x - list_a_i[0]
    elif x < list_a_i[0]:
        remove += x
    for i in range(x):
        list_a_i.remove(int(list_a_i[0]))
print(remove)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
#put a_i into list
list_a_i = list(sorted(map(int, input().split())))
remove = 0
while len(list_a_i) >=1:
    x = 0
    #count number of list_a_i[1]
    for j in range(len(list_a_i)):
        if list_a_i[0] == list_a_i[j]:
            x += 1
    if x > list_a_i[0]:
        remove += x - list_a_i[0]
    elif x < list_a_i[0]:
        remove += x
    for i in range(x):
        list_a_i.remove(int(list_a_i[0]))
print(remove)

Submission status: Time Limit Exceeded

Solution code:
ignore = int(raw_input())
k = map(int, raw_input().split())
copyk = list(set(k))
counter = 0

for i in xrange(len(copyk)):
    if (k.count(copyk[i]) > copyk[i]):
        counter+=k.count(copyk[i]) - copyk[i]
    if k.count(copyk[i]) < copyk[i]:
        counter+=k.count(copyk[i])

print counter

Submission status: Time Limit Exceeded

Solution code:
ignore = int(raw_input())
k = map(int, raw_input().split())
copyk = list(set(k))
counter = 0


for i in xrange(len(copyk)):
    while(k.count(copyk[i]) > copyk[i]):
        k.remove(copyk[i])
        counter += 1
    if k.count(copyk[i]) < copyk[i]:
        while(copyk[i] in k):
            k.remove(copyk[i])
            counter += 1


print counter

Submission status: Time Limit Exceeded

Solution code:
ignore = int(raw_input())
k = map(int, raw_input().split())
copyk = list(set(k))
counter = 0


for i in range(len(copyk)):
    while(k.count(copyk[i]) > copyk[i]):
        k.remove(copyk[i])
        counter += 1
    if k.count(copyk[i]) < copyk[i]:
        while(copyk[i] in k):
            k.remove(copyk[i])
            counter += 1


print counter

Submission status: Time Limit Exceeded

Solution code:
N = input()
a = input().split()

for i in range(0,len(a)):
    a[i] = int(a[i])

a.sort()
list = [a[0]]
for i in range(0,len(a)-1):
    if a[i] != a[i+1]:
        list.append(a[i+1])

minusList = []
for i in range(0,len(list)):
    if a.count(list[i]) > list[i]:
        minusList.append(a.count(list[i]) - list[i])
    elif a.count(list[i]) < list[i]:
        minusList.append(a.count(list[i]))

print(sum(minusList))

Submission status: Time Limit Exceeded

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

n = int(input())

alist = list(map(int, input().split()))
result = 0

for i in set(alist):
    if alist.count(i) > i:
        result += alist.count(i) - i
    elif alist.count(i) < i:
        result += alist.count(i)
print(result)

Submission status: Time Limit Exceeded

Solution code:
# C - Good Sequence
# coding: utf-8

N = int(raw_input())
a = map(int, raw_input().split())
result = 0

while a != []:
  first_num = a[0]
  first_count = a.count(first_num)
  result += first_count if first_num > first_count else first_count-first_num
  a = [num for num in a if num is not first_num]

print result

Submission status: Time Limit Exceeded

Solution code:
import math

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

def f7(seq):
    seen = set()
    seen_add = seen.add
    return [ x for x in seq if x not in seen and not seen_add(x)]

a_unique = f7(a)

d = 0

for ai in a_unique:
    ni = a.count(ai)
    if ni < ai:
        d += ni
    else:
        d += ni - ai

print(d)

Submission status: Time Limit Exceeded

Solution code:
import math

N = input()
a = list(map(int, input().split()))
a_unique = list(set(a))
d = 0

for ai in a_unique:
    ni = a.count(ai)
    if ni < ai:
        d += ni
    else:
        d += ni - ai

print(d)

Submission status: Time Limit Exceeded

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

s=set(a)

c=0
for i in s:
    t=a.count(i)
    if(t-i>=0):
        c+=(t-i)
    else:
        c+=t

print(c)

Submission status: Time Limit Exceeded

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

s=set(a)

c=0
for i in s:
    t=a.count(i) - i
    if(t>=0):
        c+=t
    else:
        c+=a.count(i)

print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

place = [0 for _ in range(1000000000)]
counter = 0
max = 0

for i in series:
    place[i] += 1
    if i > max:
        max = i
    
for j in range(len(place)):
    if place[j] > j:
        counter += place[j] - j
    elif j > place[j]:
        counter += place[j]
        
print(counter)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
N = int(input())
a_i = list(map(int, input().split()))
s = set(a_i)
rtn = 0
for a in s:
    cnt = a_i.count(a)
    if cnt > a:
        rtn += cnt-a
    elif cnt < a:
        rtn += cnt
print(rtn)

Submission status: Time Limit Exceeded

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

def count(num, counter_list):
    isFound = False
    for item in counter_list:
        if item[0] == num:
            item[1] += 1
            isFound = True
            break
    if not isFound:
        counter_list.append([num, 1])

def calc(list):
    result = 0
    for item in list:
        cmp_count = item[1] - item[0]
        result += cmp_count if cmp_count >= 0 else item[1]
    return result

def main():
    counter_list = []
    for i in range(N):
        count(A[i], counter_list)
    ans = calc(counter_list)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

lis.sort()

Ans = 0

p = 0

while(True):
	
	if p >= N:
		break
	
	if lis[p] > lis.count(lis[p]):
		Ans += lis.count(lis[p])
		p += lis.count(lis[p])
		continue
	
	if lis[p] == lis.count(lis[p]):
		p += lis.count(lis[p])
		continue
	
	if lis[p] < lis.count(lis[p]):
		Ans += lis.count(lis[p]) - lis[p]
		p += lis.count(lis[p])
		
print(Ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans=0
for i in set(a):
	x = a.count(i)
	if x-i>=0:
		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 i in range(max(a),0,-1):
	x = a.count(i)
	if x-i>=0:
		ans += x-i
	else:
		ans += x
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from collections import Counter
import collections
a = list(map(int,input().split()))
b = list(map(int,input().split()))
#値を大きさ順に並べる
b = sorted(b)
l = Counter(b)
#dに大きさ順に出てきた数を入れる
d = np.array([])
d = np.append(d,list(l.values()))
c = np.array([])
c = np.append(c,list(l.elements()))
c = list(c)
c =sorted(set(c), key=c.index)
#cに要素を大きさ順にかぶらず入れる
e = [d[i]-c[i] if d[i] - c[i]>=0 else d[i] for i in range(len(c))]
print(int(sum(e)))

Submission status: Time Limit Exceeded

Solution code:
def compare(a, A):
    R=0
    for i in range(0, len(A)):
        if(a==A[i]):
            R+=1
        elif(a<A[i]):
            break
    return R

def result(R,a):
    if(R==a):
        return 0
    elif(a<R):
        return R-a
    return R

N = int(input())

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

R=0
C=compare(a[0],a)
R+=result(C,a[0])
T=C

for i in range(1, N):
    if(a[i] != a[i-1]):
        C=compare(a[i],a[T:])
        R+=result(C,a[i])
        T+=C


print(R)

Submission status: Time Limit Exceeded

Solution code:
def compare(a, A):
    R=0
    for i in range(0, len(A)):
        if(a==A[i]):
            R+=1
        elif(a<A[i]):
            break
    return R

def result(R,a):
    if(R==a):
        return 0
    elif(a<R):
        return R-a
    return R

N = int(input())

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

R=0
T=compare(a[0],a)
R+=result(T,a[0])

for i in range(1, N):
    if(a[i] != a[i-1]):
        C=compare(a[i],a[T:])
        R+=result(C,a[i])
        T+=C

print(R)

Submission status: Time Limit Exceeded

Solution code:
def compare(a, A):
    R=0
    for i in range(0, len(A)):
        if(a==A[i]):
            R+=1
        elif(a<A[i]):
            break
    return R

def result(R,a):
    if(R==a):
        return 0
    elif(a<R):
        return R-a
    return R

N = int(input())

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

R=0
R+=result(compare(a[0],a),a[0])
T=compare(a[0],a)

for i in range(1, N):
    if(a[i] != a[i-1]):
        C=compare(a[i],a[T:])
        R+=result(C,a[i])
        T+=C


print(R)

Submission status: Time Limit Exceeded

Solution code:
def compare(a, A):
    R=0
    for i in range(0, len(A)):
        if(a==A[i]):
            R+=1
        elif(a<A[i]):
            break
    return R

def result(R,a):
    if(R==a):
        return 0
    elif(a<R):
        return R-a
    return R

N = int(input())

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

R=0
R+=result(compare(a[0],a),a[0])
T=compare(a[0],a)

for i in range(1, N):
    if(a[i] != a[i-1]):
        R+=result(compare(a[i],a[T:]),a[i])
        T+=compare(a[i],a)


print(R)

Submission status: Time Limit Exceeded

Solution code:
def compare(a, A):
    R=0
    for i in range(0, len(A)):
        if(a==A[i]):
            R+=1
        elif(a<A[i]):
            break
    return R

def result(R,a):
    if(R==a):
        return 0
    elif(a<R):
        return R-a
    return R

N = int(input())

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

R=0
T=1
R+=result(compare(a[0],a),a[0])

for i in range(1, N):
    if(a[i] != a[i-1]):
        R+=result(compare(a[i],a[T:]),a[i])
        T+=compare(a[i],a)


print(R)

Submission status: Time Limit Exceeded

Solution code:
def compare(a, A):
    R=0
    for i in range(0, len(A)):
        if(a==A[i]):
            R+=1

    if(R==a):
        return 0
    elif(a<R):
        return R-a
    return R

N = int(input())

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

R=0
R+=compare(a[0],a)

for i in range(1, N):
    if(a[i] != a[i-1]):
        R+=compare(a[i],a)

print(R)

Submission status: Time Limit Exceeded

Solution code:
N = input()
list = [int(a) for a in input().split()]
count = 0
stack = []
for i in list:
    if stack.count(i) == 0:
        if i > list.count(i):
            count += list.count(i)
        else:
            count += list.count(i) - i
        stack.append(i)                           
print(count)

Submission status: Time Limit Exceeded

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

for i in list(set(a)):
    count_of_i = a.count(i)
    if count_of_i < i:
        ans += count_of_i
    else:
        ans += count_of_i - i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__=="__main__":
    N = int(input())
    l = list(map(int,input().split(" ")))
    v = []
    c = []
    count = 0
    for i in l:
          if i not in v:
              v.append(i)
              c.append(1)
          else:
              c[v.index(i)]+=1
    for j in range(len(v)):
        count+= c[j]-v[j] if c[j]>=v[j] else c[j]
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
num=sorted(input().split())
mynum=set(num)
r=0
for item in mynum:
  a=num.count(item)
  if int(item)<a:
    r+=a-int(item)
  elif int(item)>a:
    r+=a
print(r)

Submission status: Time Limit Exceeded

Solution code:
if __name__=="__main__":
    N = int(input())
    l = list(map(int,input().split(" ")))
    s = list(set(l))
    dic = {i:0 for i in range(len(s))}
    count = 0
    for i in l:
          dic[s.index(i)] +=1
    for j in range(len(dic)):
        count+= dic[j]-s[j] if s[j]<=dic[j] else dic[j]
    print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
T = list(map(int, input().split()))
T.sort()

result = 0

T_uniq = list(set(T))

for i in T_uniq:
  count = T.count(i)
  T.remove(i)
  if count > i:
    result += count - i
  elif  count < i:
    result += count

print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
num=sorted(input().split())
mynum=set(num)
r=0
for item in mynum:
  if int(item)<num.count(item):
    r+=num.count(item)-int(item)
  elif int(item)>num.count(item):
    r+=num.count(item)
print(r)

Submission status: Time Limit Exceeded

Solution code:
if __name__=="__main__":
    N = int(input())
    l = list(map(int,input().split(" ")))
    s = list(set(l))
    count = 0
    for i in s:
        if l.count(i)<i:
            count+=l.count(i)
        if l.count(i)>i:
            count+=l.count(i)-i
    print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
T = list(map(int, input().split()))
T.sort()

result = 0

T_uniq = list(set(T))

for i in T_uniq:
  count = T.count(i)
  T.remove(i)
  if count > i:
    result = result + count - i
  elif  count < i:
    result = result + count

print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys
s_ls = list(map(int, sys.stdin.read().split("\n")[1].split()))
s_set = list(set(s_ls))
delete_count = 0
for i in s_set:
    ct = s_ls.count(i)
    if ct < i:
        delete_count += ct
    elif ct > i:
        delete_count += ct - i
print(delete_count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
T = list(map(int, input().split()))
T.sort()

result = 0

T_uniq = list(set(T))

for i in T_uniq:
  count = T.count(i)
  if count > i:
    result = result + count - i
  elif  count < i:
    result = result + count

print(result)

Submission status: Time Limit Exceeded

Solution code:
if __name__=="__main__":
    N = int(input())
    l = list(map(int,input().split(" ")))
    count = 0
    visited_list = []
    for i in l:
        if i not in visited_list:
            visited_list.append(i)
            if l.count(i)<i:
                count+=l.count(i)
            if l.count(i)>i:
                count+=l.count(i)-i
    print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
T = list(map(int, input().split()))

result = 0

T_uniq = list(set(T))

for i in T_uniq:
  count = T.count(i)
  T.remove(i)
  if count > i:
    result = result + count - i
  elif  count < i:
    result = result + count

print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys
s_ls = sorted(list(map(int, sys.stdin.read().split("\n")[1].split())))
s_set = list(set(s_ls))
delete_count = 0
for i in s_set:
    ct = s_ls.count(i)
    if ct < i:
        delete_count += ct
    elif ct > i:
        delete_count += ct - i
print(delete_count)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
T = list(map(int, input().split()))

result = 0

T_uniq = list(set(T))

for i in T_uniq:
  count = T.count(i)
  if count > i:
    result = result + count - i
  elif  count < i:
    result = result + count

print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

result = 0

T_uniq = list(set(T))

for i in T_uniq:
  count = T.count(i)
  if count > i:
    result = result + count - i
  elif  count < i:
    result = result + count

print(result)

Submission status: Time Limit Exceeded

Solution code:
if __name__=="__main__":
    N = int(input())
    l = list(map(int,input().split(" ")))
    count = 0
    for i in l:
        if l.count(i)<i:
            count+=l.count(i)
            while i in l:
                l.remove(i)
        if l.count(i)>i:
            count+=l.count(i)-i
            while i in l:
                l.remove(i)
    print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8
N = int(input())
a = input().split()
a_ = list(map(int, a))

back_a = list(map(lambda x:x*0, list(range(N))))
back_a2 = []
back_i = 0
back_i2 = 0
for i in range(N):
    a_count = a.count(a[i])
    if back_a2.count(a[i]) == 0:
        if a_count > int(a[i]):
            back_i2 += a_count - int(a[i]) 
            back_a2.append(a[i])
        if a_count < int(a[i]):
            back_i2 += a_count
            back_a2.append(a[i])

print(back_i2)

Submission status: Time Limit Exceeded

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

a_l.sort()

r = 0
i = 0
while 0 != len(a_l):
    c = a_l.count(a_l[i])
    if c > a_l[i]:
        r += c - a_l[i]
    elif c != a_l[i]:
        r += c
    a_l = a_l[c:]

print(r)

Submission status: Time Limit Exceeded

Solution code:
input()
ls = list(map(int,input().split()))
n = 0
for i in set(ls):
    while True:
        if ls.count(i) == 0 or ls.count(i) == i:
            break
        ls.remove(i)
        n += 1
print(n)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
lastcheck = -1
for i in a:
    if i == lastcheck:
        continue
    else:
        count_of_i = a.count(i)
        if count_of_i < i:
            ans += count_of_i
        else:
            ans += count_of_i - i
        lastcheck = i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8
N = int(input())
a = input().split()
a_ = list(map(int, a))

back_a = list(map(lambda x:x*0, list(range(N))))

back_i = 0
back_i2 = 0
for i in range(N):
    a_count = a.count(a[i-back_i])
    if a_count > int(a[i-back_i]):
        del a[i-back_i]
        back_i += 1
       # back_i2 += 
    if a_count < int(a[i-back_i]):
        del a[i-back_i]
        back_i += 1

print(back_i)

Submission status: Time Limit Exceeded

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

res = 0

a.sort()
cnt = 0
nex = 0
find = a[0]
for i in range(len(a)):
  find = a[nex]
  for v in a[nex:]:
    if v == find:
      cnt += 1
      nex += 1
    else:
      break
  if cnt >= find:
    res += cnt - find
  else:
    res += cnt
  cnt = 0
  if nex > len(a) - 1:
    break

print(res)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a = [int(i) for i in input().split()]
a = np.array(a)

total = 0

for i in range(1, (10**5)+1):
    cnt = np.where(a==i)[0].size
    num = 0
    if cnt == i or cnt == 0:
        pass
    elif cnt > i:
        total += (cnt - i)
    else:
        num = i - cnt
        if num < cnt:
            total += num
        else:   
            total += cnt

cnt_upper = np.where(a>10**5)[0].size
total += cnt_upper

print(total)

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8
N = int(input())
a = input().split()
a_ = list(map(int, a))

back_a = list(map(lambda x:x*0, list(range(N))))

back_i = 0
for i in range(N):
    if a.count(a[i-back_i]) > int(a[i-back_i]):
        del a[i-back_i]
        back_i += 1
    if a.count(a[i-back_i]) < int(a[i-back_i]):
        del a[i-back_i]
        back_i += 1

print(back_i)