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: Wrong Answer

Solution code:
ignore = int(raw_input())
k = map(int, raw_input().split())
copyk = list(k)
times = 0
for i in range(ignore-1):
    if (copyk.count(k[i]) > k[i]):
        counter = (k.count(k[i])-k[i])
        while(counter > 0):
            copyk.remove(k[i])
            counter -= 1
            times += 1
    elif (copyk.count(k[i]) < k[i]):
        while(k[i] in copyk):
            copyk.remove(k[i])
            times += 1

if len(k) == 1:
    print 1
    exit()

print times

Submission status: Wrong Answer

Solution code:
ignore = int(raw_input())
k = map(int, raw_input().split())
copyk = list(k)
times = 0
for i in range(ignore-1):
    if (copyk.count(k[i]) > k[i]):
        counter = (k.count(k[i])-k[i])
        while(counter > 0):
            copyk.remove(k[i])
            counter -= 1
            times += 1
    elif (copyk.count(k[i]) < k[i]):
        while(k[i] in copyk):
            copyk.remove(k[i])
            times += 1

if times == 0:
    print 1
    exit()

print times

Submission status: Wrong Answer

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

from collections import Counter

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

for num in a: cnt[num] += 1

for x, y in cnt.items():
  result += y if x>y else x-y

print result

Submission status: Wrong Answer

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)
    print(ai,ni)
    if ni < ai:
        d += ni
    else:
        d += ni - ai

print(d)

Submission status: Wrong Answer

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 += ai - ni

print(d)

Submission status: Wrong Answer

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

answer=0
count_sum=0
for i in range(N):
  count=a.count(i)
  count_sum+=count
  if count>i:
    answer += count-i
  elif count<i:
    answer += count
answer+=N-count_sum
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.append(1 << 65)
i = 0
ans = 0
while i < n:
    if n <= a[i] + i - 1:
        ans += n - i
        break
    if a[a[i] + i - 1] != a[i]:
        while a[i] == a[i+1]:
            ans += 1
            i += 1
    i = a[i] + i - 1
    while i < n-1 and a[i] == a[i+1]:
        i += 1
        ans += 1
    i += 1

print(ans)

Submission status: Wrong Answer

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

n_dic = {str(i):0 for i in set(numbers)}


for i in numbers:
    n_dic[str(i)] += 1
print(n_dic)    
count = 0

for i,j in n_dic.items():
    if int(i) < j:
        count += j - int(i)
    
    elif int(i) > j:
        count += j
        
print(count)

Submission status: Wrong Answer

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

for i in range(N):
    if a.count(i) > i:
        ans += a.count(i) - i

print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    if a.count(i) > i:
        for j in range(a.count(i)-i):
            a.remove(i)

print(a)

Submission status: Wrong Answer

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

N = int(input())
an = map(int, input().split())

d = {}
for a in an:
    d[a] = d.get(a, 0) + 1

count = 0
for i, v in d.items():
    diff = abs(i - v)
    count += min(diff, v)


print(count)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
a = raw_input().split()
c = 0

for i in a:
	if N < int(i):
		c+=1
		continue
	if int(i) != a.count(i):
		c+=1
		a.remove(i)
print c

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
a = raw_input().split()
c = 0

for i in a:
	c += 1 if N < int(i) or int(i) != a.count(i) else 0
print c

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    l = list(map(int,input().split(" ")))
    dic = {}
    count = 0
    for i in l:
        try:
            dic[i] += 1
        except Exception:
            dic[i] = 1

    for j in dic.items():
        count += j[1] - j[0] if j[1] > j[0] else j[0]
    print(count)


if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
list = [int(a) for a in input().split()]
dict = dict()
for i in range(N):
    if list[i] in dict:
        dict[list[i]] += 1
    else:
        dict[list[i]] = 1
count = 0
for i, j in dict.items():
#    print(i, j) 
    if i <= j:
        count += j - i
    else:
        count += i - j
              
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
list = [int(a) for a in input().split()]
dict = dict()
for i in range(N):
    if list[i] in dict:
        dict[list[i]] += 1
    else:
        dict[list[i]] = 1
count = 0
for i, j in dict.items():
    if i <= j:
        count += j - i
    else:
        count += i               
print(count)

Submission status: Wrong Answer

Solution code:
n = input()
str = input()
nums = str.split()
num_dict = {}
for num in nums:
    if num in num_dict:
        num_dict[num] += 1
    else:
        num_dict[num] = 1
result = 0
for k, v in num_dict.items():
    if int(k) > v:
        result += v
    elif int(k) < v:
        result += (int(k) - 1)

print(result)

Submission status: Wrong Answer

Solution code:
n = input()
str = input()
nums = str.split()
num_dict = {}
for num in nums:
    if num in num_dict:
        num_dict[num] += 1
    else:
        num_dict[num] = 1
result = 0
for k, v in num_dict.items():
    if int(k) > v:
        result += v
    elif int(k) < v:
        result += int(k)

print(result)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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)
print(c)
#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: Wrong Answer

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に要素を大きさ順にかぶらず入れる
c = list(set(b))
c = np.array(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: Wrong Answer

Solution code:
import collections
N = int(input())
P = list(map(int,input().split()))
ans = 0
P.sort()
print(P)
cnt = collections.Counter(P)
for i in cnt:
    s = cnt[i]
    if s > i:
        t =  s - i
        ans += t
    elif s < i:
        ans += s
print(ans)

Submission status: Wrong Answer

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+= s[j]-dic[j] if s[j]>dic[j] else dic[j]
    print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())
n=list(map(int,input().split()))
m=np.array(n)
ans=0

for i in range(max(n)):
    num = len(np.where(m==i)[0])
    if(num>0):ans += i-num

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

np.sort(a_l)

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

print(r)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

total = 0

for i in range(n):
    if a[i] > 10**5:
        total = n - i
        a = a[0:i]
        break

a = np.array(a)

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

print(total)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

np.sort(a_l)

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: Wrong Answer

Solution code:
import numpy as np

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

total = 0

for i in range(n):
    if a[i] > 10**5:
        total = n - i
        a = a[0:i]
        break

a = np.array(a)

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

print(total)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

total = 0

for i in range(n):
    if a[i] > 10**5:
        total = n - i
        a = a[0:i]
        break

a = np.array(a)

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: Wrong Answer

Solution code:
debug = False
if debug:
    a = [3, 3, 3, 3, 3, 3, 3, 3]
    N = len(a)
else:
    N = int(input())
    a = list(map(int, input().split()))

assert len(a) == N
d = {}
for ai in a:
    if ai in d:
        d[ai] += 1
    else:
        d[ai] = 1
s = 0
for k, v in d.items():
    t = min(abs(k - v), v)
    s += t

print(s)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=input().split(" ")
L.sort()
#print(L)
L1=list(map(int,L))
#print(L1)
toremove=0
a=1
while a<10000:
 kazu_a=L.count(str(a))
 if kazu_a<int(a):
  toremove+=kazu_a
 if kazu_a>int(a):
  toremove+=kazu_a-int(a)
 #print(str(a),kazu_a)
 a+=1
print(toremove)
'''
import collections
s1 = 'すもももももももものうち'
count_L = collections.Counter(L)
print(count_L )
'''

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# print(n)
# print(a)

num = 0
for k, v in a.most_common():
    num += abs(k - v)

print(num)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(a)
k = list(c.keys())
v = list(c.values())

count = 0
for i in range(len(k)):
    if k[i] < v[i]:
        count = v[i] - k[i]
    elif k[i] > v[i]:
        count = v[i]

print(count)

Submission status: Wrong Answer

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

counter = [0]*(10**5+3)
ans = 0
for i in range(N):
    if a[i] < 10^5 + 1:
        counter[a[i]] += 1
    else:
        ans += 1
for i in range(10**5+3):
    if counter[i] < i:
        ans += counter[i]
 #       print(counter[i])
    else:
        ans += counter[i] - i
 #       print(counter[i]-i)
print(ans)

Submission status: Wrong Answer

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(10**5+1):
for i in range(1, 10):
    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

print(total)

Submission status: Wrong Answer

Solution code:
n, lis = int(input()), list(map(int, input().split()))
m = {}
torinozoku = 0
for l in lis:
    if l not in m:
        m[l] = 1
    else:
        if m[l]>=l:
            torinozoku+=1
        else:
            m[l]+=1
for k,v in m.items():
    if k is not v:
        torinozoku+=v
print(torinozoku)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(str, input().split()))
dic = {}
for num in a:
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1
ans = 0
for num in dic:
    ans += min(dic[num], abs(int(num)-dic[num]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import collections
from sys import exit
from itertools import product

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
a = li()

sa = set(a)

ans = 0
for i in sa:
    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 = list(map(int, input().split()))
A = sorted(A)
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 = list(set(a))
num = 0
for i in b:
    if i < a.count(i):
        num += (a.count(i)-i)
    elif a.count(i) < i:
        num += a.count(i)
print(num)

Submission status: Time Limit Exceeded

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

cnt = 0
for i in set(A):
  I = A.count(i)
  if I == i:
    continue
  elif I > i:
    cnt += I - i
  else:
    cnt += I
  
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
c_num = set(a)
c_num = list(c_num)
c_cnt = [0]*(len(c_num))

for i in a:
    index = c_num.index(i)
    c_cnt[index] += 1

for i, x in enumerate(c_num):
    c_cnt[i] -= x

ans = 0

for i, x in zip(c_num, c_cnt):
    if x > 0:
        ans += x
    elif x < 0:
        ans += i + x

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input());a=input().split();d={}
for i in a:
  if int(i)==a.count(i):
    continue
  if i not in d:
    d[i]=min(a.count(i),abs(int(i)-a.count(i)))
print(sum([i for i in d.values()]))

Submission status: Time Limit Exceeded

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

s = set(a)

ans = 0

for x in s:
    c = a.count(x)
    if c > x:
        ans += c - x
    if c < x:
        ans += c

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = list(map(int, input().split()))
arr_s = set(arr)

ans = 0
for i in arr_s:
  tmp = arr.count(i) - i
  if i == 0:
    continue
  elif tmp > 0:
    ans += tmp
  elif tmp < 0:
    ans += arr.count(i)
    
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
sequence.sort()
for i in list(set(sequence)):
    num = sequence.count(i)
    if num == 0:
        pass
    elif i > num:
        ans += num
    else:
        ans += num - i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = list(map(int, input().split()))
arr_s = set(arr)

ans = 0
for i in arr_s:
  if i == 0:
    continue
  tmp = arr.count(i) - i
  if tmp > 0:
    ans += tmp
  if tmp < 0:
    ans += arr.count(i)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = list(map(int, input().split()))
  
ans = 0
memo = []
for i in arr:
  if i == 0 or i in memo:
    continue
  tmp = arr.count(i) - i
  if tmp > 0:
    ans += tmp
    memo.append(i)
  if tmp < 0:
    ans += arr.count(i)
    memo.append(i)
    
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_LI = sorted(map(int, input().split()))
A_SET = set(A_LI)
ans = 0
for a in A_SET:
    cnt = A_LI.count(a)
    if cnt < a:
        ans += cnt
    else:
        ans += cnt - a
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
cnt = 0
for i in range(len(a)):
    k,v=a.most_common()[i][0],a.most_common()[i][1]
    if v-k < 0:
        cnt += v
    else:
        cnt += v-k
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N = int(input())
    A = [int(i) for i in input().split()]
    if len(A) == 0:
        print(0)
        return
    As = set(A)
    ans = 0
    for a in As:
        cnt = A.count(a)
        if a <= cnt:
            ans += cnt - a
        else:
            ans += cnt
    print(ans)



resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
while len(A) > 0:
  a = A[0]
  c = A.count(a)
  if c < a:
    ans += c
  elif c > a:
    ans += c-a
  while A[0] == a:
    if len(A) > 1:
      A.pop(0)
    else:
      A.pop(0)
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
ans,n = 0,int(input())
a_list = list(map(int,input().split()))
a_set = set(a_list)
a_dict = {val:a_list.count(val) for val in a_set}
for key,value in a_dict.items():
    if value>key:
        ans += value-key
    elif value<key:
        ans += value
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import collections

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

ac = collections.Counter(a)
ans = 0

for i in range(a[0],a[-1]+1):
    if ac[i] < i:
        ans += ac[i]
    else:
        ans += ac[i] - i

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
a = list(map(int,input().split()))
ma = max(a)
mi = min(a)

ac = collections.Counter(a)
ans = 0

for i in range(mi,ma+1):
    if ac[i] < i:
        ans += ac[i]
    else:
        ans += ac[i] - i

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
aN=list(map(int,input().split()))
aN.sort()
count =0
a_set=set(aN)
for a in a_set:
  acount=aN.count(a)
  if a <= acount:
    count+=acount-a
  else:
    count+=acount
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):
    temp = a.count(i)
    if temp > i:
        ans += temp - i
    elif temp < i:
        ans += temp

print(ans)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
a = list(map(int,input().split()))
a.sort()
array = []
sum = 0
for i in range(len(a)):
    if a[i] not in array:
        array.append(a[i])

for i in range(len(array)):
    if a.count(array[i]) >= array[i]:
        sum += a.count(array[i]) - array[i]
    else:
        sum += a.count(array[i])
print(sum)

Submission status: Time Limit Exceeded

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

a_set = set(a)
a_map = {i:a.count(i) for i in a_set}
print(sum([cnt-i if i < cnt else cnt for i, cnt in a_map.items() if i != cnt]))

Submission status: Time Limit Exceeded

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

set_A = set(A)

for num in set_A:
    count_num = A.count(num)

    #望ましい数より大きい場合
    if count_num >= num:
        ans += count_num - num
    #望ましい数より小さい場合は0まで削る。
    else:
        ans += count_num

print(ans)

Submission status: Time Limit Exceeded

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

max_A = max(A)
set_A = set(A)

for num in set_A:
    count_num = A.count(num)

    #望ましい数より大きい場合
    if count_num >= num:
        ans += count_num - num
    #望ましい数より小さい場合は0まで削る。
    else:
        ans += count_num

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
 
cnt = 0
A_set = set(A)
for i in A_set:
    diff = A.count(i) - i
    if diff >= 0:
        cnt += diff
    else:
        cnt += A.count(i)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
	total = input()
	a = list(int(x) for x in input().split())
	a.sort()
	cntItem = 0
	cntRem = 0
	i = 0

	while i < int(total):
		cntItem = a.count(a[i])
		if a[i] < cntItem:
			cntRem+= cntItem - a[i]
		elif a[i] > cntItem:
			cntRem+= cntItem
		i+= cntItem
    
	print(cntRem)


if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def myAnswer(N:int,A:list) -> int:
   dic = {}
   counter = 0
   for a in A:
      if(a in dic.keys()):
         if(dic[a]==a):
            counter += 1
         else:
            dic[a]+= 1
      else:
         dic[a] = 1
   for key,value in dic.items():
      if(value < key):
         counter += value
   return counter

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A))
if __name__ == '__main__':
   main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
a = list(map(int,input().split()))
ac = Counter(a)
an = len(ac)

cnt = 0
for i in range(an):
  num, count = ac.most_common()[i]
  if count > num:
    cnt += count - num
  elif count < num:
    cnt += count

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

x = set(a)

res = 0

for i in x:
    if (a.count(i) >= i):res += (a.count(i) - i)
    else:res += a.count(i)

print(res)

Submission status: Time Limit Exceeded

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

ans = 0
for e in seta:
    ce = a.count(e)
    if e < ce:
        ans += ce - e
    elif e > ce:
        ans += ce

print(ans)

Submission status: Time Limit Exceeded

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

el = []
for e in seta:
    el.append([e, a.count(e)])

ans = 0
for n, c in el:
    if c > n:
        ans += c - n
    elif c < n:
        ans += c

print(ans)

Submission status: Time Limit Exceeded

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

num_set = set()
for a_i in a:
    if a_i in num_set:
        continue
    num_set.add(a_i)

ans = 0
for num in num_set:
    num_of_num = a.count(num)
    # print(num, num_of_num)
    if num == num_of_num:
        continue
    if num_of_num < num:
        ans += num_of_num
        continue
    ans += num_of_num-num

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#4
#入力
N=int(input())
A=list(map(int,input().split()))

#デバッグ関連
debug=1#0:本番,1:デバッグ

def pront(*n):
    if debug==1:
        print(n)

#処理
A.sort()

x=0
while len(A)!=0:
    y=A.count(A[0])
    if y<A[0]:
        x+=y
    else:
        x+=y-A[0]
    A=A[y:]
print(x)

Submission status: Time Limit Exceeded

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

#https://atcoder.jp/contests/abc082/tasks/abc082_c
length = int(input())
a = [int(i) for i in input().split()]

count = 0
for i in range(length):
	if(i+1 <= a.count(i+1)):
		count += i+1
print(length - count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

line1 = int(input())
line2 = str(input()).split(" ")
for index in range(len(line2)):
    line2[index] = int(line2[index])

keepTrack = dict()
keys = []
keys = list(set(line2))
for element in keys:
    keepTrack[element] = line2.count(element)

sum = 0
for key in keys:
    ##sum += abs()
    if (key < keepTrack[key]):
        sum += -key + keepTrack[key]
    elif (key > keepTrack[key]):
        sum += keepTrack[key]
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math

line1 = int(input())
line2 = str(input()).split(" ")
for index in range(len(line2)):
    line2[index] = int(line2[index])

keepTrack = dict()
keys = []
for element in line2:
    if element in keys:
        keepTrack[element] += 1
    else:
        keepTrack[element] = 1
        keys.append(element)
sum = 0
for key in keys:
    ##sum += abs()
    if (key < keepTrack[key]):
        sum += -key + keepTrack[key]
    elif (key > keepTrack[key]):
        sum += keepTrack[key]
print(sum)

Submission status: Time Limit Exceeded

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

elems = set(seq)
rem = 0

for i in elems:
    c = seq.count(i)
    if (c < i):
        rem += c
    else:
        rem += c-i

print(rem)