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: Accepted

Solution code:
def main():
    N = int(input())
    cnt = {}
    for c in map(int, input().split()):
        if c not in cnt:
            cnt[c] = 0
        cnt[c] += 1
    ans = 0
    for k in cnt:
        if k <= cnt[k]:
            ans += cnt[k]-k
        else:
            ans += cnt[k]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import collections

n=int(input())

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

X=collections.Counter(A)
K=list(X.keys())
V=list(X.values())
cnt=0
for i in range(len(X)):
    if K[i]>V[i]:
        cnt+=V[i]
    elif K[i]<V[i]:
        cnt+=V[i]-K[i]

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
counter = {}
for x in a:
    if x not in counter:
        counter[x] = 1
    else:
        counter[x] += 1
ret = 0
for i, c in counter.items():
    if c >= i:
        ret += c-i
    else:
        ret += c
print(ret)

Submission status: Accepted

Solution code:
N=int(input())
d={}
for i in map(int,input().split()):d[i]=d.get(i,0)+1
r=0
for k,v in d.items():r+=v if v<k else v-k
print(r)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
ans=0
a=list(map(int,input().split()))
d = Counter(a)
for k in d:
    val = d[k]
    if val>=k:
        ans+=val-k
    else:
        ans+=val
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

L = []
for i in dic.keys():
    if dic[i] >= i:
       L.append(dic[i]-i)
    else:
       L.append(dic[i])

print(sum(L))

Submission status: Accepted

Solution code:
import bisect

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

a.sort()
bp = bisect.bisect_right( a, 1e+5 )

ans = 0
ans += len( a[bp:] )

num = [0] * (100001)
for i in a[:bp]: num[i] += 1

for i in range(len(num)):
    if num[i] > i: ans += num[i] - i
    if num[i] < i: ans += num[i]

print( ans )

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
res = 0
for k, v in c.items():
    if v < k:
        res += v
    else:
        res += v-k
print(res)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
cnt = 0
for k, v in Counter([int(i) for i in input().split()]).items():
    if v > k:
        cnt += v - k
    elif v < k:
        cnt += v
print(cnt)

Submission status: Accepted

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

B = Counter(A).most_common()
for k, v in B:

    if k < v:
        count += v-k
    elif k > v:
        count += v
print(count)

Submission status: Accepted

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

A.sort()
B = []
B.append([A[0], 1])
for i in range(1, n) :
    if A[i] != A[i-1] :
        B.append([A[i], 1])
    else :
        B[-1][1] += 1
#print(B)

ans = 0
for i in range(len(B)) :
    if B[i][0] < B[i][1] :
        ans += B[i][1] - B[i][0]
    elif B[i][0] > B[i][1] :
        ans += B[i][1]

print(ans)

Submission status: Accepted

Solution code:
#ABC082C
N=int(input())
A=list(map(int,input().split()))
sA=set(A)
ans=0
d={}
for s in sA:
	d[s]=0
for a in A:
	d[a]+=1
for s in sA:
	if d[s]-s>=0:
		ans+=min(d[s],d[s]-s)
	else:
		ans+=d[s]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n=int(input())
l=list(map(int,input().split()))
a=Counter(l)
c=a.most_common()
m=len(c)
ans=0
for i in range(m):
  x=c[i][0]
  y=c[i][1]
  if x>y:
    ans+=y
  elif x<y:
    ans+=y-x
print(ans)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random
n = int(input())

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


count_dic = {}
for a in A:
    if a in count_dic:
        count_dic[a] += 1
    else:
        count_dic[a] = 1

ans = 0

for key in count_dic.keys():
    if count_dic[key] == key:
        pass
    elif count_dic[key]<key:
        ans += count_dic[key]
    else:
        ans += count_dic[key]-key
        count_dic[key] = key


print(ans)

Submission status: Accepted

Solution code:
import collections as c
a=c.Counter(list(map(int,open(0).read().split()[1:])))
print(sum([[v-k,v][k>v] for k,v in a.items()]))

Submission status: Accepted

Solution code:
from collections import Counter
input();a=Counter(list(map(int,input().split())))
print(sum([v if k>v else v-k for k,v in a.items()]))

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
d={}
for i in a:d[i]=d.get(i,0)+1
print(sum(d[i]-i*(d[i]>=i)for i in d))

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split());d={}
for i in a:d[i]=d.get(i,0)+1
print(sum(d[i]-i*(d[i]>=i)for i in d))

Submission status: Accepted

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

Submission status: Accepted

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

d = {}
for a in A:
  if(a in d):
    d[a] += 1
  else:
    d[a] = 1
cnt = 0
for k, v in d.items():
  if(k > v):
    cnt += v
  elif(k < v):
    cnt += v - k
print(cnt)

Submission status: Accepted

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

N = I()
l = IL()
cl = collections.Counter(l)

key = list(cl.keys())
value = list(cl.values())

ans = 0
for i in range(len(key)):
	k = int(key[i])
	v = value[i]
	if k <= v:
		ans += v-k
	else:
		ans += v

print(ans)

Submission status: Accepted

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

res = 0

num = [0]*(N)
cnt = [0]*(N)

for i in range(N):
    if A[i] > N:
        res += 1
    else:
        cnt[A[i]-1] += 1

for i in range(N):
    if cnt[i] < i+1:
        res += cnt[i]
    else:
        res += cnt[i] - (i+1)

print(res)

Submission status: Accepted

Solution code:
from sys import stderr, setrecursionlimit
from collections import Counter
setrecursionlimit(2147483647)
def getint():
    return int(input())
def getints():
    return [int(i) for i in input().split()]
def getintlines(n=1):
    res = []
    for _ in range(n):
        res.append(getint())
    return res
def getintslines(n=1):
    res = []
    for _ in range(n):
        res.append(getints())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getint()
a = Counter(getints())
debug(a)
ans = 0

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

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
L.append(0)
ans = 0
k = L[0]
cnt = 0
for i in range(N+1):
  if k == L[i]:
    cnt += 1
  else:
    if cnt >= k:
      ans += cnt-k
    else:
      ans += cnt
    cnt = 1
    k = L[i]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
counter = Counter(a)
ans = 0
for i,j in counter.items():
  if i <= j:
    ans += j - i
  else:
    ans += j
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
b={}
for i in range(N):
    if a[i] in b:
        b[a[i]]+=1
    else:
        b[a[i]]=1
cnt=0
for i in b:
    if b[i]>i:
        cnt+=b[i]-i
    elif b[i]<i:
        cnt+=b[i]
print(cnt)

Submission status: Accepted

Solution code:
import collections
n, a = int(input()), list(map(int, input().split()))
c = collections.Counter(a)
ans = 0
for k in c:
    if c[k] >= k:
        ans += (c[k] - k)
    else:
        ans += c[k]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
C=Counter(A)
ans=0
for i in C.keys():
    if i>C[i]:
        ans+=C[i]
    elif i<C[i]:
        ans+=C[i]-i
print(ans)

Submission status: Accepted

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

count = [0] * (10 ** 5 + 1)
ans = 0
for i in a:
    if i <= 10 ** 5:
        count[i] += 1
    else:
        ans += 1
for i,j in enumerate(count):
    if (j - i) >= 0:
        ans += j - i
    else:
        ans += j
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
A=Counter(list(map(int,input().split())))
ans=0
for i,j in A.items():
  if j-i<0:
    ans+=j
  else:
    ans+=min((j-i),j)
print(ans)

Submission status: Accepted

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

d = {}
for i in range(N):
  if(A[i] not in d):
    d[A[i]] = 1
  else:
    d[A[i]] += 1
cnt = 0
for k, v in d.items():
  if(k != v):
    if(k > v):
      cnt += v
    else:
      cnt += v - k
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 0
cnt = [0,] * 100001
for i in range(n):
    if a[i] > 100000:
        ans += 1
    else:
        cnt[a[i]] += 1
for i in range(100001):
    if cnt[i] > i:
        ans += cnt[i] - i
    elif cnt[i] < i:
        ans += cnt[i]
print(str(ans))

Submission status: Accepted

Solution code:
N = input()

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

count = []
num = []
pnum = -1
counter = -1

for i in data:
    if pnum != i:
        pnum = i
        num.append(i)
        count.append(1)
        counter += 1
    else:
        count[counter] += 1

ans = 0

for i in range(len(num)):
    if count[i] < num[i]:
        ans += count[i]
    else:
        ans += count[i]-num[i]

print ans

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
c = Counter(map(int, input().split()))
ans = 0

for k in c.keys():
    ans += c[k] if c[k] < k else c[k]-k
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


def solve(N, As):
    c = Counter(As)
    ans = 0
    for k, v in c.items():
        if k < v:
            ans += v - k
        elif k == v:
            pass
        else:
            ans += v
    return ans

if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

Submission status: Accepted

Solution code:
import numpy as np
from collections import Counter

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

x = Counter(a)
out = 0
for i in x:
    if(x[i] < i):
        out += x[i]
    else:
        out += x[i] - i

print(out)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
from collections import defaultdict
d = defaultdict(int)

for a in A:
    d[a]+=1

ans=0
for k in d.keys():
    if d[k]>k:
        ans+=d[k]-k
    elif d[k]<k:
        ans+=d[k]
print(ans)

Submission status: Accepted

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

import collections as coll
cnt = coll.Counter(L)
ans = 0
for x in cnt.items():
    if x[0] > x[1]:
        ans += x[1]
    elif x[0] < x[1]:
        ans += x[1] - x[0]
print(ans)

Submission status: Accepted

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

kazu = {}

for i in range(len(a)):
  if a[i] not in kazu:
    kazu[a[i]]=1
  else:
    kazu[a[i]]+=1

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

Submission status: Accepted

Solution code:
from collections import Counter

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

C = Counter(a)
ans = 0

for i in C:
    if C[i] > i:
        ans += C[i]-i
    elif C[i] < i:
        ans += C[i]

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter as C
N = int(input())
A = [int(a) for a in input().split()]
X = C(A)
ans = 0
for x in X:
    ans += X[x] if X[x] < x else X[x] - x
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = {}
for a in A:
    if a not in B:
        B[a] = 1
    else:
        B[a] += 1
num = 0
for k, v in B.items():
    if k <= v:
        num += v - k
    else:  # k > v
        num += v
print(num)

Submission status: Accepted

Solution code:
from collections import Counter

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

count = 0
for k, v in A.items():
    if k < v:
        count += v - k
    elif k > v:
        count += v
        
print(count)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)

ans = 0
for i,v in c.items():
    if v > i:
        ans += v - i  
    elif v < i:
        ans += v
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
ans = 0
for a, cnt in Counter(A).items():
  if a < cnt:
    ans += cnt - a
  elif a > cnt:
    ans += cnt
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

def inpl(): return list(map(int, input().split()))

N = int(input())

ans = 0
for k, v in Counter(inpl()).items():
    if k < v:
        ans += v - k
    elif k > v:
        ans += v
print(ans)

Submission status: Accepted

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

from collections import Counter
C = Counter(A).most_common()

ans = 0
for (k,v) in C:
    if v<k:
        ans += v
    elif v>k:
        ans += v-k

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
ans = 0
for num, cnt in Counter(a).items():
    if num < cnt:
        ans += cnt-num
    elif num > cnt:
        ans += cnt
print(ans)

Submission status: Accepted

Solution code:
n = map(int, input().split())
a = list(map(int, input().split()))
d = dict()
finish = []
ans = 0
for x in a:
    if x in finish:
        ans += 1
    else:
        try: d[x] += 1
        except: d[x] = 1
        if d[x] == x:
            finish.append(x)
            del d[x]
print(ans + sum(list(d.values())))

Submission status: Accepted

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

dic = {}
for i in a:
    dic[i] = 0

for val in a:
    dic[val] += 1

ans = 0
for key,val in dic.items():
    if key < val:
        ans += val - key
    elif key >val:
        ans += val


print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
data = {}
ans = 0
for i in a:
    if i not in data:
        data[i] = 1
    else:
        data[i] += 1

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

print(ans)

Submission status: Accepted

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

while index <= n-1:
    x = A[index]
    j = index+1
    while True:
        if A[j] != x:
            if j-index < x:
                ans += j-index
                index = j
                break
            elif j-index == x:
                index = j
                break
            elif j-index > x:
                ans += j-index-x
                index = j
                break
        else:
            j += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=Counter(input().split())
count=0
keys,counts=zip(*a.most_common())
for i,j in zip(keys,counts):
    i=int(i)
    if i>j:
        count+=j
    elif i<j:
        count+=j-i
print(count)

Submission status: Accepted

Solution code:
import sys
N = int(input())

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

dic = {}
for ak in a:
    if not(ak in dic):
        dic[ak] = 1
    else:
        dic[ak] += 1
ans = 0
for k in dic.keys():
    if(dic[k] - k > 0):
        ans+=dic[k] - k
    elif(dic[k] - k < 0):
        ans+=dic[k]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

a = Counter(a)

total = 0

for k, v in a.items():
    if k > v:
        total += v
    else:
        total += v-k

print(total)

Submission status: Accepted

Solution code:
import collections

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

num = collections.Counter(a).most_common()

for a, b in num:
    if b < a:
        ans += b
    elif a < b:
        ans += b-a
print(ans)

Submission status: Accepted

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

d = {}
for i in range(N):
  if(a[i] not in d):
    d[a[i]] = 1
  else:
    d[a[i]] += 1
cnt = 0
for k, v in d.items():
  if(k > v):
    cnt += v
  elif(k < v):
    cnt += v - k
print(cnt)

Submission status: Accepted

Solution code:
import collections
N = input()
a = map(int, raw_input().split())

c = collections.Counter(a)
res = 0
for k, v in c.items():
  if k > v:
    res += v
  elif k < v:
    res += v - k
print res

Submission status: Accepted

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

for i in range(n):
    if a[i] not in b:
        b[a[i]] = 1
    else:
        b[a[i]] += 1
count = 0
for i in b:
    if b[i] < i:
        count += b[i]
    else:
        count += b[i] - i

print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    N = int(input())
    sa = input().split(' ')
    a = [int(s) for s in sa]

    d = dict()
    for k in a:
        if k in d:
            d[k] = d[k] + 1
        else:
            d[k] = 1

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


    print(c)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def abc082_c():
    from collections import Counter

    _ = int(input())
    a = list(map(int, input().split()))
    ans = 0
    a_count = Counter(a)

    for num in a_count:
        if num <= a_count[num]:
            ans += (a_count[num] - num)
        else:
            ans += a_count[num]

    print(ans)


abc082_c()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    n = int(input())
    aa = list(map(int, input().split()))
    counts = Counter(aa)
    res = sum(v if v < k else v - k for k, v in counts.items())
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

res = 0
for k, v in summary.items():
    if k > v:
        res += v
    else:
        res += min(v - k, v)

print(res)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
count = {}
ans = 0
for i in a:
    if i not in count:
        count[i] = 1
    else:
        count[i] += 1
for i,c in count.items():
    if i > c:
        ans += c
    elif i < c:
        ans += c - i
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
ans=0
n=int(input())
a=list(map(int,input().split()))
a_tmp=dict(Counter(a).most_common())
for i,j in a_tmp.items():
    i=int(i)
    j=int(j)
    if i==j:
        pass
    elif i<j:
        ans+=j-i
    else:
        ans+=j
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()] 
count = {}
ans = 0
for i in a:
    if i not in count:
        count[i] = 1
    else:
        count[i] += 1
for i,c in count.items():
    if i > c:
        ans += c
    elif i < c:
        ans += c - i
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
c = Counter(A).items()
count = 0
for e in c:
    num = e[1] - e[0]
    if num < 0:
        count += e[1]
    else:
        count += num
print(count)

Submission status: Accepted

Solution code:
# Good Sequence
n = int(input())
a = list(map(int, input().split()))
count = {}
ans = 0
for i in a:
    if i not in count:
        count[i] = 1
    else:
        count[i] += 1
for i, c in count.items():
    if i > c:
        ans += c
    elif i < c:
        ans += c - i
print(ans)

Submission status: Accepted

Solution code:
import collections

n = int(input())

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

arr3 = collections.Counter(arr)

flg = 1
ans = 0

for i,j in arr3.items():
	if i != j:
		if i < j:
			ans += j - i
		else:
			ans += j
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
ans = 0 
c = Counter(list(map(int, input().split())))

for key, value in c.items():
    if key < value:
        ans += value-key
    elif key > value:
        ans += value
print(ans)

Submission status: Accepted

Solution code:
import collections

def main() :
	N = int(input())
	li = [int(i) for i in input().split()]

	c = collections.Counter(li)

	total_count = 0
	for key in c.keys() :
		count = c[key]

		if (count == key) :
			continue
		elif (count > key) :
			total_count += (count - key)
		else  :
			# all remove
			total_count += count

	print(total_count)


main()

Submission status: Accepted

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

count = {}
for i in A:
    if i not in count:
        count[i] = 1
    else:
        count[i] += 1

ans = 0
for i, j in count.items():
    if i > j:
        ans += j
    elif i < j:
        ans += j - i

print(ans)

Submission status: Accepted

Solution code:
import collections

N = int(input())
a = [int(i) for i in input().split(" ")]
c = collections.Counter(a)
ans = 0

for key,val in c.items():
    d = val
    if val >= key:
        d = min(val-key,val)
    ans += d

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
cnt=0
L=[0 for i in range(100005)]
for i in range(N):
    if A[i]<=100000:
        L[A[i]]+=1
    else:
        cnt+=1
    
for j in range(100002):
    
    if L[j]==j:
        pass
    elif L[j]<j:
        cnt+=L[j]
    elif L[j]>j:
        cnt+=L[j]-j
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
table={}
for _ in input().split():
    i = int(_)
    if i in table.keys():
        table[i] += 1
    else:
        table[i] = 1
ans = 0
for k, v in table.items():
    if k > v:
        ans += v
    else:
        ans += v-k
print(ans)

Submission status: Accepted

Solution code:
import collections
count = 0
N = int(input())
a = list(map(int,input().split(" ")))
c = collections.Counter(a)
C = c.most_common()
for i in C:
    A = i[0]
    B = i[1]
    if A < B:
        count += B-A
    elif A == B:
        continue
    else:
        count += B
print(count)

Submission status: Accepted

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

a.sort()

ans = 0
for i, ai in enumerate(a):
    # init
    if i == 0:
        view = ai
        cnt = 0
    elif ai > view:
        if cnt > view: ans += cnt - view
        elif cnt < view: ans += cnt
        view = ai
        cnt = 0
    # count up
    cnt += 1
else:
    if cnt > view: ans += (cnt - view)
    elif cnt < view: ans += cnt

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
a.append(-1)
cost = 0
target = a[0]
start = 0
# print(a)
for i in range(len(a)):
    # print("target:{} start:{} i:{}".format(target, start, i))
    localCost = 1000000
    if a[i] != target:
        if i - start == target:
            localCost = 0
        elif i - start > target:
            localCost = i - start - target
        cost += min(localCost, i - start)
        start = i
        target = a[i]
        # print("local:{} cost:{}".format(min(localCost, i - start), cost))
print(cost)

Submission status: Accepted

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

Submission status: Accepted

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

ac = collections.Counter(a)

ans = 0
for i in ac.keys():
    if ac[i] < i:
        ans += ac[i]
    else:
        ans += (ac[i] - i)

print(ans)

Submission status: Accepted

Solution code:
import collections

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

dic = collections.Counter(a).most_common()
for a, b in dic:
    if a <= b:
        ans += b-a
    else:
        ans += b
print(ans)

Submission status: Accepted

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

a.sort()
sym = 0
symc = 0
delc = 0
for i in range(n):
    if i == 0 and n == 1:
        if a[i] == 1:
            delc = 0
        else:
            delc = 1
    elif i == 0:
        sym = a[i]
        symc += 1
    elif a[i] != a[i - 1]:
        if symc < a[i - 1]:
            delc += symc
        elif symc > a[i - 1]:
            delc += symc - a[i - 1]
        sym = a[i]
        symc = 1
        if i == n - 1:
            if symc < a[i]:
                delc += symc
            elif symc > a[i]:
                delc += symc - a[i]
    elif i == n - 1:
        symc += 1
        if symc < a[i]:
            delc += symc
        elif symc > a[i]:
            delc += symc - a[i]
    else:
        symc += 1

print(delc)

Submission status: Accepted

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

n=int(input())
l=list(map(int,input().split()))
s=collections.Counter(l)
#print(s)
a=0
for k,v in s.items():
    if k>v:
        a+=v
    else:
        a+=v-k
print(a)

Submission status: Accepted

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

n=int(input())
l=list(map(int,input().split()))
li=collections.Counter(l)
#print(li)
a=0
for k,v in li.items():
    if k>v:
        a+=v
    else:
        a+=v-k
print(a)

Submission status: Accepted

Solution code:
def 解():
    iN = int(input())
    dA = {}
    for a in map(int,input().split()):
        if a in dA:
            dA[a] += 1
        else:
            dA[a] = 1
    iC = 0
    for k,v in dA.items():
        if k > v:
            iC += v
        elif k < v:
            iC += v - k
    print (iC)
解()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
    if a[i] in d:
        d[a[i]] += 1
    else:
        d[a[i]] = 1
ans = 0
for i in d:
    if d[i] < i:
        ans += d[i]
    if d[i] > i:
        ans += d[i] - i
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mapa = {}
for i in range(n):
    if a[i] in mapa:
        mapa[a[i]] += 1
    else:
        mapa[a[i]] = 1
count = 0
for i in mapa:
    if i < mapa[i]:
        count += mapa[i] - i
    elif i > mapa[i]:
        count += mapa[i]
print(count)

Submission status: Accepted

Solution code:
import collections
N = int(input())
a = [int(i) for i in input().split()]
hint = collections.Counter(a)
b = hint.most_common()
ans = 0
for val, num in b:
    if val > num:
        ans += num
    elif val < num:
        ans += num-val
print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a =list(map(int,input().split()))
col = collections.Counter(a)
a = set(a)
cnt = 0
for letter in a:
    if col[letter]>letter:
        cnt += col[letter] - letter
    elif col[letter]<letter:
        cnt += col[letter]
print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
D = defaultdict(int)

for i in range(N):
    D[A[i]] += 1

delete = 0
for d in D:
    if d < D[d]:
        delete += D[d] - d
    elif d > D[d]:
        delete += D[d]
print(delete)

Submission status: Accepted

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

Submission status: Accepted

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

result = {}
for b in B:
    result[b] = 0
for a in A:
    result[a] += 1

count = N
for b in B:
    if result[b] >= b:
        count -= b

print(count)

Submission status: Accepted

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

dict = {}
for a in an:
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1

remove_num = 0

for k,v in dict.items():
    if k > v:
        remove_num += v
    else:
        remove_num += v - k

print(remove_num)

Submission status: Accepted

Solution code:
N = int(input())
a_list = list(map(int, input().split( )))
import collections
a_c=collections.Counter(a_list)

#それを値とカウントで分ける
a_val, a_count=zip(*a_c.most_common())

ans =0
for i in range(len(a_val)):
	if a_val[i] > a_count[i]:
		ans += a_count[i]
	elif a_val[i] < a_count[i]:
		ans += a_count[i] - a_val[i]

print(ans)