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:
n = int(input())
b = {}
ans = 0
for i in input().split():
    i = int(i)
    if(i in b):
        b[i] += 1
    else:
        b[i] = 1
for c in b:
    if(c < b[c]):
        ans += b[c] - c
    elif(c > b[c]):
        ans += b[c]
print(ans)

Submission status: Accepted

Solution code:
MAX = 10**5
count = [0]*(MAX+1)
c = 0
N = int(input())
A = list(map(int,input().split()))
for a in A:
    if a > MAX:
        continue
    count[a] += 1
for i in range(1,N+1):
    if count[i] >= i:
        c += i
print(N-c)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
summe = {k: len(list(g)) for k, g in itertools.groupby(A)}
cnt = 0
for k, v in summe.items():
    if k < v:
        cnt += v - k
    elif k > v:
        cnt += v
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
prog = list(map(int, input().split()))
prog.sort()
prog_dict = {}
ans = 0

for i in range(n):
    if prog[i] not in prog_dict:
        prog_dict[prog[i]] = 1
    else:
        prog_dict[prog[i]] += 1

keys = list(prog_dict.keys())
for i in range(len(prog_dict)):
    if keys[i] > prog_dict[keys[i]]:
        ans += prog_dict[keys[i]]
    else:
        ans += prog_dict[keys[i]] - keys[i]

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
src = list(map(int,input().split()))
ctr = Counter(src)

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

Submission status: Accepted

Solution code:
import collections

n = int(input())
array = [int(x) for x in input().split()]
_dict = collections.Counter(array)

res = 0
for i, j in _dict.items():
    if i != j:
        if i > j:
            res += j
        else:
            res += abs(i-j)
print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())
from collections import Counter

N = int(input())
A = Counter(inpl())
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import os
import sys

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

d = {}
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i] = 1

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

print(ans)
exit(0)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]
c = Counter(a)
ck = list(c.keys())
cv = list(c.values())
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

sort_dict = collections.Counter(a_list)
remove_counter = 0
for key, value in sort_dict.items():
    if value < key:
        remove_counter += value
    else:
        remove_counter += (value - key)     
print(remove_counter)

Submission status: Accepted

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

sort_dict = {}
for i in sort_a_list:
    if i not in sort_dict.keys():
        sort_dict[i] = [i]
    else:
        sort_dict[i].append(i)
        
remove_counter = 0
for key, value in sort_dict.items():
    if len(value) < key:
        remove_counter += len(value)
    elif len(value) == key:
        pass
    else:
        remove_counter +=(len(value) - key)
        
print(remove_counter)

Submission status: Accepted

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

  print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N=int(input())
a=list(map(int,input().split()))
A=list(set(a))
ans=0
count = Counter(a)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

els = {}

for num in a:
    if num in els.keys():
        els[num] += 1
    else:
        els[num] = 1

total = 0

for k, v in els.items():
    total += v if int(k) > v else (v - int(k)) if int(k) < v else 0

print(total)

Submission status: Accepted

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

els = {}

for num in a:
    if num in els.keys():
        els[num] += 1
    else:
        els[num] = 1

total = 0

for k, v in els.items():
    total += v if int(k) > v else (v - int(k)) if int(k) < v else 0

print(total)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
cnt = Counter(map(int, input().split()))
print(sum(v - k if v >= k else v for k, v in cnt.items()))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a = [int(i) for i in input().split()]
s = set(a)
c = Counter(a)

cnt = 0
for i in s:
    if c[i] < i:
        cnt += c[i]
    else:
        cnt += c[i]-i
print(cnt)

Submission status: Accepted

Solution code:
import collections as c

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

d = c.Counter()
for i in a:
    d[i] += 1

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

print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

anset = list(set(an))

andict = {}

for i in range(len(an)):
    if an[i] in andict:
        andict[an[i]] = andict[an[i]] + 1
    else:
        andict.update({an[i]:1})

counter = 0

for i ,j in andict.items():
    if i == j :
        None
    elif i > j:
        counter = counter + j
    elif i < j:
        counter = counter + j - i
    
        
print(counter)

Submission status: Accepted

Solution code:
# ABC082C
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
B = set(A)
C = Counter(A)
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
t, i, j = 0, 0, 1

a.sort()
while True:
    if i >= len(a):
        break

    if len(a) > 1:
        while a[i] == a[j]:
            j += 1

            if j == len(a):
                break

    if a[i] > j - i:
        t += j - i
    elif a[i] < j - i:
        t += j - i - a[i]

    i = j

print(t)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = Counter(list(map(int,input().split()))).most_common()
S = 0
for i,c in A:
    if i == c:
        continue
    elif i > c:
        S += c
    else:
        S += c-i
print(S)

Submission status: Accepted

Solution code:
from collections import Counter

def goodify(a):
    nums = Counter(a)
    bads = 0
    for k, v in nums.items():
        if v >= k:
            bads += v - k
        else:
            bads += v
    return bads


if __name__ == '__main__':
    _ = input()
    a = Counter(map(int, input().split()))
    print(goodify(a))

Submission status: Accepted

Solution code:
from collections import Counter

input()
A = map(int, input().split())
B = Counter(A)

count = 0
for key, value in B.items():
    count += value - key if value >= key else value

print(count)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(input().split())
counter = Counter(a)
count = 0
for name, cnt in counter.most_common():
    name = int(name)
    if name > cnt:
        count += cnt
    if name < cnt:
        count += cnt-name
print(count)

Submission status: Accepted

Solution code:
N = int(input())
As = map(int, input().split())
cnt = {}
for a in As:
    if a in cnt:
        cnt[a] += 1
    else:
        cnt[a] = 1
ret = 0
for i in set(cnt.keys()):
    if i < cnt[i]:
        ret += cnt[i] - i
    elif cnt[i] < i:
        ret += cnt[i]
print(ret)

Submission status: Accepted

Solution code:
N=int(input())
s,ans={},0
for i in list(map(int,input().split())):
    s[i]=s.get(i,0)+1
for c,v in s.items():
    if c<v:
        ans+=v-c
    if c>v:
        ans+=v
print(ans)

Submission status: Accepted

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

   a.sort()
   a.append(0)
   b = 0
   c = 0
   count = 0
   for a in a:
      if a != b:
         if b < c:
            count += c - b
         elif b > c:
            count += c
         b = a
         c = 1
      else:
         c += 1
   return count

print(main())

Submission status: Accepted

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

a_=Counter(a)
num=0
for key in a_.keys():
    if key>a_[key]:
        num+=a_[key]
    elif key<a_[key]:
        num+=a_[key]-key
    else:
        continue
print(num)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(a)

result = 0
for num in c.keys():
    if num < c[num]:
        result += c[num] - num
    elif num > c[num]:  # numbers of appearance is less than the number. needs to delete all
        result += c[num]

print(result)

Submission status: Accepted

Solution code:
input()
d = {}
for x in input().split():
    x = int(x)
    d[x] = d.get(x, 0) + 1
c = 0
for k, v in d.items():
    if k > v: c += v
    elif k < v: c += (v - k)
print(c)

Submission status: Accepted

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

ans=0
for i in dict.keys():
  count=dict[i]
  if count>i:
    ans+=count-i
  elif count<i:
    ans+=count

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
n=int(input())
arr=list(map(int,input().split()))
dd=defaultdict(int)
for a in arr:
    dd[a]+=1
ans=0
for key in dd.keys():
    if key>dd[key]:
        ans+=dd[key]
    elif key<dd[key]:
        ans+=dd[key]-key
print(ans)

Submission status: Accepted

Solution code:
input()
r = {}
for i in map(int, input().split()):
    a = r.get(i, 0)
    r[i] = a + 1

print(sum(v - (k if v >= k else 0) for k, v in r.items()))

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    count = 0

    from collections import Counter
    counted_a = Counter(a)

    for x in counted_a:
        if counted_a[x] >= x:
            count += counted_a[x] - x
        else:
            count += counted_a[x]

    print(count)

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    count = 0

    from collections import Counter
    counted_a = Counter(a)

    for x in counted_a:
            if counted_a[x] >= x:
                count += counted_a[x] - x
            else:
                count += counted_a[x]

    print(count)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
b = [0] * (N + 1)
ans = 0
for i in range(N):
    if a[i] <= N:
        b[a[i]] += 1
    else:
        ans += 1

for i in range(N + 1):
    if b[i] < i:
        ans += b[i]
    else:
        ans+= b[i] - i
print(ans)

Submission status: Accepted

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

n = arr_data[0][0]
arr = arr_data[1]

#print(n,arr)

hash01={}

for v in arr:
    
    cnt =hash01.get(int(v),0)+1
    hash01[int(v)] = cnt
    
#print(hash01)

cnt=0

for k,v in hash01.items():
    
#    print(k,v)
    
    if(k>v):
        
        cnt+=v
        
    elif(k<v):
        
        cnt+=v-k
        
print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter

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

count = Counter(A)

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

print(ans)

Submission status: Accepted

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()

dic = {}

for num in a:
    if num in dic:
        dic[num] += 1
    else:
        dic[num] = 1

ans = 0
for key,value in dic.items():
    if key > value:
        ans += value
    else:
        ans += (value - key)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

counter = Counter(a)

cnt = 0
for num , how_many in counter.most_common():
    if num > how_many:
        cnt += how_many
    elif num < how_many:
        cnt += how_many - num

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

count = collections.Counter()

for i in a:
    count[i] += 1

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

Submission status: Accepted

Solution code:
import collections

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

count = collections.Counter()

for a in A:
    count[a] += 1
    
ans = 0

for num, c in count.items():
    if num < c:
        ans += c - num
    elif num > c:
        ans += c
    else:
        continue
        
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(raw_input())
c = Counter(map(int, raw_input().split()))
s = 0
for k,v in c.items():
    if v < k:
        s += v
    else:
        s += v - k
print s

Submission status: Accepted

Solution code:
N = int(input())
tmp = input().split()
dict = {}

for n in range(N):
    if tmp[n] in dict:
        dict[tmp[n]] += 1
    else:
        dict[tmp[n]] = 1
count = 0
for k,v in dict.items():
    if int(k) ==v:
        continue
    elif int(k) > v:
        count +=v
    else:
        count += (v-int(k))
print(count)

Submission status: Accepted

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

num_list = {}
for i in a:
    if i in num_list:
        num_list[i] += 1
    else:
        num_list[i] = 1


count_rem = 0
for i in num_list:
    if i > num_list[i]:
        count_rem += num_list[i]
    elif i < num_list[i]:
        count_rem += num_list[i] - i

print(count_rem)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = {}
for i in a:
    b[i] = b.get(i,0)+1
s =0
for i in b.keys():
    c = b[i]
    if(c<i):
        s += c
    elif(c>i):
        s += c-i
print(s)

Submission status: Accepted

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

for i in a:
    m[i] = m.get(i, 0) + 1

result = 0
for i in m.keys():
    v = m.get(i, 0)
    if v >= i:
        result += v - i
    else:
        result += v
print(result)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
a.append(-1)

count=1
ans=0

for i in range(0,n):
    if a[i+1]==a[i]:
        count += 1
    else:

        if count > a[i]:
            ans += count - a[i]
        elif count < a[i]:
            ans += count

        count = 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
set_a=set(a)
import collections
count=0
data=collections.Counter(a)
for i,j in data.items():
    if i<j:
        count+=j-i
    elif j<i:
        count+=j
print(count)

Submission status: Accepted

Solution code:
import collections
A=int(input())
N=list(map(int,input().split()))
dic=dict(collections.Counter(N))
cnt=0

for i,j in dic.items():
    tmp=j-i
    if i>j:
        cnt+=j
    elif i<j:
        cnt+=j-i
print(cnt)

Submission status: Accepted

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]
  if(i>n):
    dlt+=1
    push+=1
  else:
    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: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
count_delete = 0
count_dict = collections.Counter(a)
for k, v in count_dict.items():
    if k != v:
        if k > v:
            count_delete += v
        else:
            count_delete += min(v-k, v)
print(count_delete)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    n = int(sys.stdin.readline())
    a = map(int, sys.stdin.readline().split())

    d = {}
    for e in a:
        if e not in d:
            d[e] = 1
        else:
            d[e] += 1

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

    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def C_Good_Sequence():
    N=int(input())
    a=list(map(int, input().split()))
    count={}
    ans=0
    
    for num in a:
        count[num]= count.get(num,0)+1

    for num in count:
        if num > count[num]:
            ans += count[num]
        elif num < count[num]:
            ans += count[num]-num
    
    print(ans)
   
C_Good_Sequence()

Submission status: Accepted

Solution code:
def main():
    x = int(input())

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

    B = {}
    count = 1
    a = -1
    for i in A:
        if a == i:
            count += 1
        elif a >= 0:
            B.update({a:count})
            count = 1

        a = i

    B.update({a:count}) 

    count = 0
    for key in B.keys():
        val = B.get(key)
        diff = val - key

        if diff >= 0:
            count += diff
        else:
            count += val

    print (count)


if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

n_rmv = 0
A.sort()
A.append(0)

i = 0
while i < len(A):
    if A[i] == 0: break
    try:
        tmp = A[i]
        if A[i+A[i]-1] != A[i]:
            while tmp == A[i]:
                n_rmv += 1
                i += 1
        else:
            i += A[i]
            while tmp == A[i]:
                n_rmv += 1
                i += 1
    except IndexError:
        n_rmv += len(A[i:-1])
        break
print(n_rmv)

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    N = int(input())
    A = list(map(int, input().split()))
    D = defaultdict(lambda: 0)

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

    r = 0
    for k,v in D.items():
        if k < v:
            r += v - k
        elif k > v:
            r += v

    print(r)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = map(int,input().split())
dic={}

ans=0
for i in a:
	dic.setdefault(i,0)
	dic[i]+=1
for a,b in dic.items():	
	if b-a>=0:
		ans += b-a
	else:
		ans += b
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

count=Counter(a)
outrange=0
flow=0

for i in range(n):
    if (a[i]>n):
        outrange+=1

for i in range(1,n+1):
    if (count[i]>i):
        flow+=count[i]-i
    elif (count[i]<i):
        flow+=count[i]

print(flow+outrange)

Submission status: Accepted

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

dic = {}
for num in l:
    dic.setdefault(num, 0)
    dic[num]+=1

result = 0
for k, v in dic.items():
    if k > v:
        result = result + v
    elif k < v:
        result += (v - k)

print(result)

Submission status: Accepted

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

import sys

n = int(raw_input().split()[0])
a = [int(e) for e in raw_input().split()]
d = dict()
#print n
#print a

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

n = 0
for k, v in d.iteritems():
    if k > v:
        n += v
    elif v > k:
        n += (v - k)
        
sys.stdout.write('%d\n' % n)
sys.stdout.flush()

Submission status: Accepted

Solution code:
from collections import Counter
a = int(input())
l = list(map(int, input().split()))
#i = 1

c=Counter(l)
d = dict(c)
kv = []
for k,v in d.items():
    if k>v:
        kv.append(v)
    elif k<v:
        t = v-k
        kv.append(t)
s = sum(kv)
print(s)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = {}
    total = 0
    for i, a in enumerate(A):
        b = B.get(a, 0)
        if b == 0:
            B[a] = 1
        else:
            B[a] += 1

    for i in B:
        if B[i] == 0:
            continue
        if B[i] == i:
            continue
        elif B[i] > i:
            total += B[i] - i
        else:
            total += B[i]
    print(total)
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
now = a[0]
ans = 0
count = 0
for i in range(n):
    if(now != a[i]):
        if(count < now):
            ans += count
        now = a[i]
        count = 0
    count += 1
    if(count > now):
        ans += 1
    if(i == n - 1):
        if(count < now):
            ans += count
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
counter = Counter(map(int, input().split()))

sum = 0

for a, cnt in counter.items():
    if a > cnt:
        sum += cnt
    else:
        sum += cnt - a

print(sum)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
counter = Counter(map(int, input().split()))

sum = 0

for a, cnt in counter.most_common():
    if a > cnt:
        sum += cnt
    else:
        sum += cnt - a

print(sum)

Submission status: Accepted

Solution code:
num = int(input())
num_dict = {}
nums = [int(i) for i in input().split()]
count = 0

for i in range(num):
    if nums[i] in num_dict.keys():
        num_dict[nums[i]] += 1
    else:
        num_dict[nums[i]] = 1

for key, value in num_dict.items():
    if key < value:
        count += (value - key)
    elif key > value:
        count += value

print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc082/tasks/arc087_a

"""
import sys
from sys import stdin
from collections import Counter
input = stdin.readline


def solve(A):
    ans = 0
    for v, f in Counter(A).most_common():
        if v > f:
            ans += f
        elif f > v:
            ans += (f - v)
    return ans


def main(args):
    N = int(input())
    A = [int(x) for x in input().split()]
    ans = solve(A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
counter=Counter(map(int,input().split()))
print(sum(c-num if c>=num else c for num,c in counter.items()))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
cnt = Counter(map(int, input().split()))
print(sum(v - k if v >= k else v for k, v in cnt.items()))

Submission status: Accepted

Solution code:
from collections import Counter

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

ans = 0
counter = Counter(A)
for i, c in counter.most_common():
    if c < i:
        ans += c
    else:
        ans += c - i
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(lambda: 0)
N = int(input())
a = list(map(int, input().split()))
for tmp_a in a:
    d[tmp_a] += 1
key_list = list(d.keys())
key_list.sort()
counter = 0
for key in key_list:
    if d[key]>=key:
        counter += d[key]-key
    else:
        counter += d[key]

print(counter)

Submission status: Accepted

Solution code:
N=int(input())
l=input().split(' ')
l.sort()
count=0
i=0
while i <len(l):
    p=1
    while p < int(l[i]):
        if p+i == len(l):
            del l[i:i+p]
            count+=p
            p=0
            break
        elif l[i]!=l[i+p]:
            del l[i:i+p]
            count += p
            p=0
            break
        else:
            p+=1
    if p != 0:
        while i+p < N:
            if l[i] == l[i+p]:
                p+=1
            else:
                break
        del l[i+int(l[i]):i+p]
        count += p-int(l[i])
        i += int(l[i])
print(count)

Submission status: Accepted

Solution code:
n = int(input())
a = []
a =  list(map(int, input().split()))
d = {}
c = 0
for x in a:
    d[x] = d.get(x, 0) + 1
for y,z in d.items():
    if y < z:
        c += z-y
    if y > z:
        c += z
print(c)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())

s=input().split()
c=Counter(s)
count=0
for i in c:
    if int(i)>c[str(i)]:
        count+=int(c[str(i)])
    elif int(i)<c[str(i)]:
        count+=int(c[str(i)])-int(i)
    else:
        continue
print(count)

Submission status: Accepted

Solution code:
def foo(xs):
    d = {}
    for x in xs:
        d[x] = d.get(x, 0) + 1
    
    count = 0
    for k, v in d.items():
        if k > v:
            count += v
        elif k < v:
            count += (v - k)
        elif k == v:
            pass
        else:
            pass
    return count



if __name__ == "__main__":
    n = input()
    xs = map(int, input().split())
    print(foo(xs))

Submission status: Accepted

Solution code:
N = input()
a = map(int, raw_input().split())
numbers = {}
for i in range(N):
    numbers[a[i]] = numbers.get(a[i], 0) + 1
ans = 0
for k, v in numbers.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()))
dic = {}
for elem in a:
    if elem not in dic:
        dic[elem] = 1
    else:
        dic[elem] += 1

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

print(ans)

Submission status: Accepted

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

a.sort()
a.append(0)

T=[]
j=0
t=0
s=0
for i in range(N):
    j+=1
    if a[i] != a[i+1]:
        if j-s > a[i]:
            t+=(j-s)-a[i]
        elif j-s < a[i]:
            t += j-s
        s=j

print(t)

Submission status: Accepted

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)]

d = 0

a_unique = {}

for i in range(0,len(a)):
    if a[i] in a_unique:
        a_unique[a[i]] += 1
    else:
        a_unique[a[i]] = 1

for ai in a_unique.keys():
    if a_unique[ai] >= ai:
        d += a_unique[ai] - ai
    else:
        d += a_unique[ai]

print(d)