input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
from collections import Counter n,k = list(map(int, input().split())) a = list(map(int, input().split())) count = Counter(a) t = len(count) ans = 0 for i in sorted(count.values()): if t <= k: break ans += i t -= 1 print(ans)
from collections import Counter n,k = list(map(int, input().split())) a = list(map(int, input().split())) cnt = Counter(a) l = len(cnt) t = l-k ans = 0 for i in sorted(cnt.values()): if t <= 0: break t -= 1 ans += i print(ans)
p03495
import sys # A,B,C = [int(n) for n in input().split()] N,K = [int(n) for n in input().split()] # S = str(input()) # T = str(input()) bucket = [0]*(N+1) A = [int(n) for n in input().split()] dic = {} for a in A: if not(a in dic): dic[a]=1 else: dic[a]+=1 val = sorted(dic.values()) # print(val) rc = len(val) - K ans = 0 for r in range(rc): ans += val[0] val = val[1:] print((ans if ans >=0 else 0))
import sys # A,B,C = [int(n) for n in input().split()] N,K = [int(n) for n in input().split()] # S = str(input()) # T = str(input()) bucket = [0]*(N+1) A = [int(n) for n in input().split()] dic = {} for a in A: if not(a in dic): dic[a]=1 else: dic[a]+=1 val = sorted(dic.values()) # print(val) rc = len(val) - K ans = 0 for r in range(rc): ans += val[r] print((ans if ans >=0 else 0))
p03495
n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = [0]*200000 c = [] ans = 0 for x in a: b[x-1] += 1 for x in b: if x > 0: c.append(x) c.sort() y = len(c) - k if y > 0: ans = sum(c[:y]) print(ans)
n,k = list(map(int,input().split())) a = list(map(int,input().split())) b = [0]*(n+1) for x in a: b[x]+=1 b.sort(reverse=1) print((sum(b[k:])))
p03495
N, K = list(map(int, input().split())) A = list(map(int, input().split())) C = list(set(A)) B = len(C) x = B - K #種類の差 ans = 0 figure_list = [0] * B if x<=0: print('0') else: for i in range(B): stock = int(C[i]) counter = 0 for ii in range(N): if stock == A[ii]: counter += 1 figure_list[i] = counter figure_list = sorted(figure_list) for i in range(B-K): ans += figure_list[i] print(ans)
#【註】N 個のボールと K 種類の整数 N, K = list(map(int, input().split())) #【註】ボールに書かれている数 A_1...A_N A = list(map(int, input().split())) #【註】何種類あるか?を set で取得 C = list(set(A)) # 数字の種類数 B = len(C) # 元々の種類と目的の種類の差 x = B - K #----- #【註】「文字:回数」という辞書を使って、ループを最小限にします。 d = {} #【解説】A のそれぞれの要素について for i in A: #【解説】もし辞書に既に登録されていれば、その値(出現回数)に 1 を足す if i in d: d[i] += 1 #【解説】そうでなければ、辞書にキーを登録して値(出現回数)を 1 にする else: d[i] = 1 #【解説】辞書を値でソートすると、出現回数が小さい順に並ぶ d = sorted(list(d.items()), key=lambda x:x[1]) ans = 0 count = 0 if x<=0: print('0') else: #【解説】辞書からキーと値を取り出し for key, value in d: #【解説】取り出した玉の数に value を足す ans = ans + value #【解説】何種類取り出したか、の値に 1 を足す count = count + 1 #【解説】もし x 種類取り出しが完了したら ans を出力 if count == x: print(ans) break
p03495
from collections import Counter import sys N, K = list(map(int, input().split())) a_lis = [int(_) for _ in input().split()] count = 0 counter = sorted(list(Counter(a_lis).items()), key=lambda x: x[1]) while len(counter) > K: count += counter[0][1] del counter[0] if len(counter) == K: print(count) sys.exit() print((0))
from collections import Counter import sys N, K = list(map(int, input().split())) a_lis = [int(_) for _ in input().split()] counter = sorted(list(Counter(a_lis).items()), key=lambda x: x[1]) if len(counter) > K: ans_list = counter[:len(counter) - K] count = sum([item[1] for item in ans_list]) print(count) sys.exit() print((0))
p03495
N,K = list(map(int,input().split())) A = list(map(int,input().split())) import collections c = collections.Counter(A) ans = 0 while len(c) > K: n = c.most_common()[-1][0] ans += c[n] del c[n] print(ans)
N,K = list(map(int,input().split())) A = list(map(int,input().split())) import collections c = collections.Counter(A) print((N - sum([pair[1] for pair in c.most_common(K)])))
p03495
# _*_ coding:utf-8 _*_ # Atcoder_Beginnger_Contest081-C # TODO https://atcoder.jp/contests/abc081/tasks/arc086_a import collections as col def solveProblem(neededBallKind,BallsList): AsListCounter = col.Counter(BallsList) allBallKind = len(AsListCounter) sortCounter = sorted(list(AsListCounter.items()),reverse=False,key=lambda x:x[1]) replaceBallCount = 0 replaceBallKind = allBallKind-neededBallKind if replaceBallKind <= 0: answer = 0 else: for k,v in sortCounter: replaceBallCount = replaceBallCount + v replaceBallKind = replaceBallKind - 1 if replaceBallKind <= 0: break answer = replaceBallCount return answer if __name__ == '__main__': _,K = list(map(int,input().strip().split(' '))) AsList = list(map(int,input().strip().split(' '))) solution = solveProblem(K,AsList) print(("{}".format(solution)))
# Problem: atcoder.jp/contests/abc081/tasks/arc086_a # Python 1st Try import sys # from collections import defaultdict import collections as col # import pprint # import heapq,copy # from collections import deque def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def solver(ALLNUM, KIND, ball_numbers): result = 0 # prp = pprint.pprint counter_result = col.Counter(ball_numbers) ball_num_len = len(counter_result) counter_result_sorted = sorted(list(counter_result.items()), key=lambda x: x[1]) # prp(counter_result_sorted) if ball_num_len <= KIND: return 0 reduce_kind = ball_num_len - KIND # prp(reduce_kind) for _, ballCount in counter_result_sorted: result += ballCount reduce_kind = reduce_kind - 1 # prp(reduce_kind) if reduce_kind <= 0: break return result if __name__ == "__main__": N, K = MI() Ai = list(map(int, sys.stdin.readline().split())) # print(Ai) print(("{}".format(solver(N, K, Ai))))
p03495
# Problem: atcoder.jp/contests/abc081/tasks/arc086_a # Python 1st Try import sys # from collections import defaultdict import collections as col # import pprint # import heapq,copy # from collections import deque def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def solver(ALLNUM, KIND, ball_numbers): result = 0 # prp = pprint.pprint counter_result = col.Counter(ball_numbers) ball_num_len = len(counter_result) counter_result_sorted = sorted(list(counter_result.items()), key=lambda x: x[1]) # prp(counter_result_sorted) if ball_num_len <= KIND: return 0 reduce_kind = ball_num_len - KIND # prp(reduce_kind) for _, ballCount in counter_result_sorted: result += ballCount reduce_kind = reduce_kind - 1 # prp(reduce_kind) if reduce_kind <= 0: break return result if __name__ == "__main__": N, K = MI() Ai = list(map(int, sys.stdin.readline().split())) # print(Ai) print(("{}".format(solver(N, K, Ai))))
# Problem: https://atcoder.jp/contests/abc081/tasks/arc086_a # Python 2nd Try import sys from collections import Counter # import heapq,copy # from collections import deque def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def solver(givenBall, selectKind, ball_num): result = 0 summary_Ball = Counter(ball_num) # print("{}".format(list(summary_Ball.values()))) sortedCount = sorted(list(summary_Ball.values())) # print(sortedCount) ballAllKind = len(sortedCount) changeNumberKind = ballAllKind - selectKind if changeNumberKind <= 0: result = 0 else: for j in range(0, changeNumberKind, +1): result += sortedCount[j] return result if __name__ == "__main__": N, K = MI() Ai = LI() print(("{}".format(solver(N, K, Ai))))
p03495
import collections N,K = list(map(int,input().split(" "))) A = list(map(int,input().split(" "))) count = collections.Counter(A) if len(list(count.values())) <= K: print((0)) else: ans = 0 for i in range(len(list(count.values())) - K): ans += count.most_common()[-(i+1)][1] print(ans)
import collections N,K = list(map(int,input().split(" "))) A = list(map(int,input().split(" "))) count = collections.Counter(A) num = len(count)-K a = sorted(count.values()) print((sum(a[:num])))
p03495
n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list() for i in range(n): b.append(a.count(i+1)) c = [i for i in b if i != 0] c.sort() if len(c) - k > 0: print((sum((c[0:len(c)-k])))) else: print((0))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = [0]*n for i in range(n): b[a[i]-1] += 1 c = [i for i in b if i != 0] c.sort() if len(c) - k > 0: print((sum((c[0:len(c)-k])))) else: print((0))
p03495
N, K = [int(x) for x in input().split()] A = [int(x) for x in input().split()] X = set(A) L = len(X) S= [] for x in X: n = A.count(x) S.append(n) S = sorted(S) ans = sum(S[:max(0,L - K)]) print(ans)
N, K = [int(x) for x in input().split()] A = [int(x) for x in input().split()] X = [0] * N for i in range(N): X[A[i] - 1] += 1 X = sorted(X, reverse=True) S = sum(X[:K]) ans = N - S print(ans)
p03495
import collections N, K = list(map(int, input().split())) A = list(map(int, input().split())) counter = 0 collection = collections.Counter(A) k = len(collection) if k > K: change_n = k - K for i in range(change_n): min_k = collection.most_common()[-1-i][1] counter += min_k print(counter)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) counter = 0 dic = {} for a in A: if a in list(dic.keys()): dic[a] += 1 else: dic[a] = 1 k = len(dic) v = sorted(dic.values()) if k > K: change_n = k -K for i in range(change_n): min_k = v[i] counter += min_k print(counter)
p03495
# -*- coding: utf-8 -*- # AtCoder Beginner Contest # Problem C if __name__ == '__main__': from collections import Counter ball_count, kind_count = list(map(int, input().split())) ball_numbers = Counter(list(map(int, input().split()))) sorted_ball_numbers = sorted(list(ball_numbers.items()), key=lambda x: x[1]) ball_number_key_count = len(list(ball_numbers.keys())) need_rewritten_count = 0 diff_count = ball_number_key_count - kind_count if diff_count > 0: for i, (key, value) in enumerate(sorted_ball_numbers): if diff_count > i: need_rewritten_count += value print(need_rewritten_count)
# -*- coding: utf-8 -*- # AtCoder Beginner Contest # Problem C if __name__ == '__main__': from collections import Counter ball_count, kind_count = list(map(int, input().split())) ball_numbers = Counter(list(map(int, input().split()))) sorted_ball_numbers = sorted(ball_numbers.values()) print((sum(sorted_ball_numbers[:-kind_count])))
p03495
import collections def solve(n, k, a_list): counter = collections.Counter() for i in a_list: counter[i] += 1 key_num = len(list(counter.keys())) if key_num > k: tmp = sorted(list(counter.items()), key=lambda x: x[1]) ans = sum([v for k, v in tmp[: key_num - k]]) else: ans = 0 return ans if __name__ == "__main__": n, k = [int(i) for i in input().split()] a_list = [int(i) for i in input().split()] print((solve(n, k, a_list)))
import collections def solve(n, k, a_list): counter = collections.Counter() for i in a_list: counter[i] += 1 tmp = sorted(list(counter.values()), reverse=True) ans = n - sum(tmp[:k]) return ans if __name__ == "__main__": n, k = [int(i) for i in input().split()] a_list = [int(i) for i in input().split()] print((solve(n, k, a_list)))
p03495
n,k=list(map(int,input().split())) A=list(map(int,input().strip().split(" "))) ANS=[] for i in range(200000): ANS.append(A.count(i)) ANS.sort(reverse=True) B=[e for e in ANS if e>0] P=[] if len(B)<=k: print((0)) else: for i in B[k:]: P.append(i) print((sum(P)))
n,k=list(map(int,input().split())) A=list(map(int,input().strip().split(" "))) dict={} for i in A: if i in dict: dict[i] += 1 else: dict[i] = 1 X=[] sorted_A = sorted(list(dict.items()), key=lambda x: x[1], reverse=True) for i,v in sorted_A: X.append(v) ans=0 if len(X)>k: for i in X[k:]: ans+=i print(ans)
p03495
import collections import sys n,k = list(map(int,input().split())) ls = list(map(int,input().split())) a = list(set(ls)) c = collections.Counter(ls) p = 0 if len(a) > k: for i in range(len(a)-1): if len(a) - k - i > 0: p += c.most_common()[-1-i][1] else: print(p) sys.exit() else: print((0))
import sys n,k = list(map(int,input().split())) ls = list(map(int,input().split())) p = len(list(set(ls))) if p <= k: print((0)) sys.exit() di=[float("inf")]*n for i in range(n): if di[ls[i]-1] == float("inf"): di[ls[i]-1] = 1 else: di[ls[i]-1] += 1 di.sort(reverse=True) q = 0 while True: s = di.pop() p -= 1 q += s if p <= k: print(q) sys.exit()
p03495
import collections n,k=list(map(int,input().split())) a=list(map(int,input().split())) now_k=len(set(a)) d=now_k-k arr=collections.Counter(a).most_common() #print(arr) b=sorted([arr[i][1] for i in range(now_k)]) #print(b) cnt=now_k cnt2=0 flg=0 for i in b: cnt-=1 cnt2+=i if cnt==k: print(cnt2) flg=1 break if flg==0: print((0))
import collections n,k=list(map(int,input().split())) a=list(map(int,input().split())) now_k=len(set(a)) d=now_k-k arr=collections.Counter(a).most_common() b=sorted([arr[i][1] for i in range(now_k)]) print((sum(b[:d])))
p03495
import collections n,k=list(map(int,input().split())) a=list(map(int,input().split())) now_k=len(set(a)) d=now_k-k arr=collections.Counter(a).most_common() b=sorted([arr[i][1] for i in range(now_k)]) print((sum(b[:d])))
from collections import Counter n,k=list(map(int,input().split())) a=list(map(int,input().split())) now_k=len(set(a)) d=now_k-k arr=Counter(a).most_common() b=sorted([arr[i][1] for i in range(now_k)]) print((sum(b[:d])))
p03495
import sys from collections import Counter n, k, *a = list(map(int, sys.stdin.read().split())) def main(): c = Counter(a) l = len(c) if l <= k: return 0 c = sorted(list(c.items()), key=lambda x: x[1]) res = 0 for i in range(l - k): res += c[i][1] return res if __name__ == '__main__': ans = main() print(ans)
import sys from collections import Counter n, k, *a = list(map(int, sys.stdin.read().split())) def main(): c = Counter(a) res = sum(sorted(c.values())[:-k]) print(res) if __name__ == '__main__': main()
p03495
import sys import collections sys.setrecursionlimit(10 ** 7) def main(): N, K = list(map(int, input().split())) c = collections.Counter(input().split()) print((sum(sorted(list(c.values()), reverse=True)[K:]))) if __name__ == '__main__': main()
import sys import collections sys.setrecursionlimit(10 ** 7) def main(): N, K = list(map(int, input().split())) c = collections.Counter(input().split()) c = sorted(c.values()) k = len(c) - K if k <= 0: print((0)) else: print((sum(c[:k]))) if __name__ == '__main__': main()
p03495
import collections n, k = list(map(int, input().split())) a = list(map(int, input().split())) a_cnt = collections.Counter(a).most_common()[::-1] ans = 0 n = len(list(set(a))) if n <= k: print((0)) exit() for v in range(n): ans += a_cnt[v][1] n -= 1 if n <= k: print(ans) exit()
import collections n, k = list(map(int, input().split())) values = list(map(int, input().split())) obj, cnt = list(zip(*collections.Counter(values).most_common()[::-1])) cnt = list(cnt) diff = max(0, len(cnt) - k) ans = sum(cnt[:diff]) print(ans)
p03495
from collections import Counter n,k = list(map(int,input().split())) A = list(map(int,input().split())) D = Counter(A) K = [] for key in list(D.keys()): K.append(key) if len(set(K)) <= k: print((0)) else: V = [] for v in list(D.values()): V.append(v) V.sort(reverse=True) print((n-sum(V[:k])))
from collections import Counter n,k = list(map(int,input().split())) A = list(map(int,input().split())) D = Counter(A) V = [] for v in list(D.values()): V.append(v) V.sort(reverse=True) print((max(n-sum(V[:k]),0)))
p03495
n,k=[int(i) for i in input().split()] a_list=[int(i) for i in input().split()] #print(a_list) dic={} for i in a_list: if i not in dic: dic[i]=1 else: dic[i]+=1 #print(dic) #print(len(dic)) #書き換えなくてよい if len(dic)<=k: print((0)) else: ans=sorted(list(dic.items()),key=lambda x:x[1],reverse=True) b_list=ans[k:] ans_sum=0 for i in b_list: ans_sum+=i[1] print(ans_sum)
n,k=[int(i) for i in input().split()] a_list=[int(i) for i in input().split()] a_dic={} for i in range(n): if a_list[i] not in a_dic: a_dic[a_list[i]]=1 else: a_dic[a_list[i]]+=1 if len(a_dic)<=k: print((0)) else: #値を取り出す a_value=list(a_dic.values()) a_value.sort(reverse=True) print((sum(a_value[k:])))
p03495
N, K = list(map(int, input().split())) A = list(map(int, input().split())) A1 = set(A) AN = {} for a in A1: AN[a] = A.count(a) AN = sorted(list(AN.items()), key=lambda x: x[1]) ans = 0 K1 = len(A1) - K if K1 > 0: for k in range(K1): ans += AN[k][1] print(ans) else: print('0')
N, K = list(map(int, input().split())) A = list(map(int, input().split())) A1 = set(A) AN = {} for a in A: if not a in AN: AN[a] = 0 AN[a] += 1 AN = sorted(list(AN.items()), key=lambda x: x[1]) ans = 0 K1 = len(A1) - K if K1 > 0: for k in range(K1): ans += AN[k][1] print(ans) else: print('0')
p03495
import collections n,k=list(map(int,input().split())) a=list(map(int,input().split())) count=0 b=len(collections.Counter(a)) #print(b) for i in range(min(k,b)): count+=collections.Counter(a).most_common()[i][1] # print(count) ans=len(a)-count print(ans)
import collections n,k=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() count=0 b=len(collections.Counter(a)) c=collections.Counter(a).most_common() #print(b) for i in range(min(k,b)): count+=c[i][1] # print(count) ans=len(a)-count print(ans)
p03495
from collections import defaultdict n, k = list(map(int, input().split())) li = list(map(int, input().split())) s = set(li) ns = [li.count(i) for i in s] ns.sort() if len(ns) <= k: print((0)) else: print((sum(ns[:-k])))
n, k = list(map(int, input().split())) li = list(map(int, input().split())) li.sort() ar = [] tmp = -1 for a in li: if a != tmp: tmp = a ar.append(1) else: ar[-1] += 1 ar.sort() if len(ar) <= k: print((0)) else: print((sum(ar[:-k])))
p03495
from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) count = [] c = Counter(a) # dict {'a': 3, 'b': 4, ...} for i in c: count.append(c[i]) count.sort(reverse = True) print((n - sum(count[:k])))
from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) c = Counter(a) # Counter({1: 2, 2: 2, 5: 1}) count = list(c.values()) # [2, 2, 1] (type: 'dict_values') l_count = list(count) # to list l_count.sort(reverse = True) # to descending order print((n - sum(l_count[:k]))) # n - (sum of first k values from count[])
p03495
N, K = list(map( int, input().split() )) A = list( map( int, input().split() ) ) numAppeared = [0] * (N+1) for i in A: numAppeared[i] += 1 numAppeared.sort( reverse=True ) print(( sum( numAppeared[i] for i in range(K,N) ) ))
N, K = list(map( int, input().split() )) A = list( map( int, input().split() ) ) numAppeared = [0] * (N+1) for i in A: numAppeared[i] += 1 numAppeared.sort( reverse=True ) # print( sum( numAppeared[i] for i in range(K,N) ) ) print(( sum( numAppeared[K:N] ) ))
p03495
N, K = list(map(int, input().split())) A = list(map(int, input().split())) T = [0] * (N + 1) for a in A: T[a] += 1 ns = [] for t in T: if t > 0: ns.append(t) ns.sort() ans = 0 while len(ns) > K: ans += ns[0] ns = ns[1:] print(ans)
import heapq N, K = list(map(int, input().split())) A = list(map(int, input().split())) T = [0] * (N + 1) for a in A: T[a] += 1 ns = [] for t in T: if t > 0: heapq.heappush(ns, t) ans = 0 while len(ns) > K: ans += heapq.heappop(ns) print(ans)
p03495
n, k = input().split() n, k = int(n), int(k) balls = [int(x) for x in input().split()] dic = {} for x in balls: if x not in dic: dic[x] = 1 else: dic[x] += 1 change = 0 qnt = list(dic.values()) qnt.sort() while len(qnt) > k: change += qnt[0] qnt.pop(0) print(change)
n, k = input().split() n, k = int(n), int(k) balls = input().split() dic = {} for x in balls: if x not in dic: dic[x] = 1 else: dic[x] += 1 change = 0 qnt = list(dic.values()) qnt.sort() dif = len(qnt) - k for x in range(0, dif): change += qnt[x] print(change)
p03495
n,k = list(map(int,input().split())) A = list(map(int,input().split())) D = dict.fromkeys(list(range(1,n+1)),0) ans = 0 for a in A: D[a] += 1 D = sorted(list(D.items()), key=lambda x:x[1]) for i in range(n-k): ans += D[i][1] print(ans)
n,k = list(map(int,input().split())) A = list(map(int,input().split())) L = [0] * n ans = 0 for a in A: L[a-1] += 1 L = sorted(L) for i in range(n-k): ans += L[i] print(ans)
p03495
import collections n, k = list(map(int, input().split())) a = list(map(int, input().split())) ans = 0 dic = collections.Counter(a) #for i in a: # if i in dic: # dic[i] += 1 # else: # dic[i] = 1 dic = sorted(list(dic.items()), key=lambda x: x[1]) while len(dic) > k: ans += dic[0][1] del dic[0] print(ans)
n, k = list(map(int, input().split())) a = list(map(int, input().split())) ans = 0 dic = {} for i in a: if i in dic: dic[i] += 1 else: dic[i] = 1 dic = sorted(list(dic.items()), key=lambda x: x[1]) #while len(dic) > k: # ans += dic[0][1] # del dic[0] for i in range(len(dic)-k): ans += dic[i][1] print(ans)
p03495
n,k=list(map(int,input().split())) a=list(map(int,input().split())) d={} for i in a: d[i]=d.get(i,0)+1 c=0 while len(d)>k: x=min(d, key=d.get) c+=d[x] del d[x] print(c)
n,k=list(map(int,input().split())) a=list(map(int,input().split())) s=set(a) l=[0]*(n+1) for i in range(n): l[a[i]]+=1 l=[i for i in l if i>0] l.sort() le=len(s) c=0 for i in range(len(l)): if le<=k: break else: c+=l[i] le-=1 print(c)
p03495
import copy import collections def calc(k, balls): balls_count = set(copy.copy(balls)) change_count = 0 flg = True while flg == True: if len(balls_count) <= int(k): flg = False return change_count else: c = collections.Counter(balls) most_common = c.most_common()[-1] balls = [i for i in balls if i != most_common[0]] balls_count = sorted(set(copy.copy(balls))) change_count += int(most_common[1]) _ = input().split() k = _[1] balls = sorted(input().split()) print((calc(k, balls)))
import copy import collections def calc(k, balls): dif = len(set(copy.copy(balls))) - int(k) change_count = 0 if dif <= 0: return change_count else: c = collections.Counter(balls) most_common = c.most_common()[::-1] for x in most_common: change_count = change_count + x[1] dif = dif - 1 if dif <= 0 : break return change_count _ = input().split() k = _[1] balls = sorted(input().split()) print((calc(k, balls)))
p03495
import collections n, k = list(map(int,input().split())) a = list(map(int, input().split())) c = collections.Counter(a) ans = 0 if len(set(a)) <= k: print(ans) exit() for i in range(0,k): ans += c.most_common()[i][1] print((n-ans))
import collections n, k = list(map(int,input().split())) a = list(map(int, input().split())) c = collections.Counter(a) ans = 0 cnt = 0 if len(set(a)) <= k: print(ans) exit() for tuple in c.most_common(): ans += tuple[1] cnt += 1 if cnt == k: print((n-ans)) exit()
p03495
from collections import Counter N, K = list(map(int, input().split())) a = Counter(list(map(int, input().split()))) if N == K: print((0)) else: num = list(a.values()) if len(num) <= K: print((0)) else: print((sum(sorted(num)[:-K])))
from collections import Counter N, K = list(map(int, input().split())) A = sorted(list(Counter(list(map(int, input().split()))).values())) if N == K: print((0)) elif len(A) <= K: print((0)) else: print((sum(A[:-K])))
p03495
from collections import Counter N,K = list(map(int,input().split())) A=list(map(int,input().split())) count = Counter(A) diff = len(count)-K ans=0 if diff<=0: print((0)) else: for i in range(diff): ans+=count.most_common()[len(count)-i-1][1] print(ans)
from collections import Counter N,K = list(map(int,input().split())) A=list(map(int,input().split())) count = Counter(A) count = count.most_common() diff = len(count)-K ans=0 if diff>0: for i in range(diff): ans+=count[len(count)-i-1][1] print(ans)
p03495
N, K = list(map(int, input().split())) A = list(map(int, input().split())) C = list(set(A)) B = len(C) x = B - K ans = 0 figure_list = [0] * B if x<=0: print('0') else: for i in range(B): stock = int(C[i]) counter = 0 for ii in range(N): if stock == A[ii]: counter += 1 figure_list[i] = counter figure_list = sorted(figure_list) for i in range(B-K): ans += figure_list[i] print(ans)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) C = list(set(A)) B = len(C) x = B - K d = {} for i in A: if i in d: d[i] += 1 else: d[i] = 1 d = sorted(list(d.items()), key=lambda x:x[1]) ans = 0 count = 0 if x<=0: print('0') else: for key, value in d: ans = ans + value count = count + 1 if count == x: print(ans) break
p03495
from collections import Counter N, K = list(map(int, input().split())) A = input().split() cnt = Counter(A) del_num = len(cnt) - K print((sum(sorted(cnt.values())[:del_num])))
from collections import Counter n,k = list(map(int, input().split())) a = input().split() cnt = Counter(a) del_num = len(cnt) - k print((sum(sorted(cnt.values())[:del_num])))
p03495
N, K = list(map(int,input().split())) A = list(map(int,input().split())) li = [] for i in range(N+1): cnt = A.count(i+1) if cnt>0: li.append(cnt) li.sort(reverse=True) print((sum(li[K:])))
N, K = list(map(int,input().split())) A = list(map(int,input().split())) li = {} for i in A: c = li.setdefault(i,0) li[i] = c + 1 # print(c) w = len(list(li.keys())) - K # print(w) # print(len(li.keys())) ans = sorted(li.values()) # print(ans) if w > 0: print((sum(ans[:w]))) else: print((0))
p03495
N, K = list(map(int, input().split())) A = list(map(int, input().split())) C = list(set(A)) B = [0 for i in range(len(C))] for a in A: B[C.index(a)] += 1 print((sum(sorted(B)[:-K])))
N, K = list(map(int, input().split())) A = list(map(int, input().split())) B = {i:0 for i in set(A)} for a in A: B[a] += 1 print((sum(sorted(B.values())[:-K])))
p03495
N, K = list(map(int, input().split())) A = list(map(int, input().split())) B = {i:0 for i in set(A)} for a in A: B[a] += 1 print((sum(sorted(B.values())[:-K])))
N, K = list(map(int, input().split())) B = {} for i in input().split(): if i in B: B[i] += 1 else: B[i] = 1 print((sum(sorted(B.values())[:-K])))
p03495
from collections import Counter N, K = list(map(int,input().split())) listA = Counter(input().split()) listA = list(listA.values()) listA.sort() times = len(listA) - K # print(times,len(listA),K) num = 0 if times <= 0: num = 0 else: for _ in range(times): num += listA.pop(0) print(num)
from collections import Counter N, K = list(map(int,input().split())) listA = Counter(input().split()) # print(listA) listA = list(listA.values()) listA.sort() times = len(listA) - K num = 0 if times <= 0: num = 0 else: for i in range(times): num += listA[i] print(num)
p03495
from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) syurui = len(set(a)) #print(syurui) c = Counter(a) ans = 0 for i in range(1, syurui-k + 1): ans += c.most_common()[-i][1] print(ans)
from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) syurui = len(set(a)) #print(syurui) c = Counter(a) ans = 0 c_sort = c.most_common() #print(c_sort) for i in range(1, syurui-k + 1): ans += c_sort[-i][1] print(ans)
p03495
import sys input = sys.stdin.readline n,k = list(map(int,input().split())) A = list(map(int,input().split())) sum = 0 import collections c = collections.Counter(A) c = c.most_common() while len(c) > k: sum += c[-1][1] c = c[:-1] print(sum)
import sys import collections input = sys.stdin.readline n,k = list(map(int,input().split())) A = list(map(int,input().split())) sum = 0 c = collections.Counter(A) c = c.most_common() if len(c) > k: a = len(c)-k c = c[-a:] for i in range(a): sum += c[i][1] print(sum) else: print((0))
p03495
N , K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() cnt = [] while len(A) > 0: temp = A[0] i_cnt = 0 while A[0] == temp: i_cnt += 1 del A[0] if len(A) == 0: break cnt.append(i_cnt) cnt.sort() result = 0 for i in range(len(cnt) - K): result += cnt[i] print(result)
N , K = list(map(int, input().split())) A = list(map(int, input().split())) A.sort() A.append(0) cnt = [] i_cnt = 1 for i in range(N): if A[i] == A[i + 1]: i_cnt += 1 else: cnt.append(i_cnt) i_cnt = 1 cnt.sort() result = 0 for i in range(len(cnt) - K): result += cnt[i] print(result)
p03495
import collections import sys input = sys.stdin.readline n, k = list(map(int, input().split())) a = list(map(int, input().split())) d = collections.Counter(a) v = list(d.values()) v = sorted(v) ans = 0 while len(v) > k: ans += v.pop(0) print(ans)
import collections import sys input = sys.stdin.readline n, k = list(map(int, input().split())) a = list(map(int, input().split())) d = collections.Counter(a) v = list(d.values()) v = sorted(v) ans = 0 i = 0 while len(v) - i > k: ans += v[i] i += 1 print(ans)
p03495
list_ = [0] n, min_count = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() kind = 1 tmp = a[0] for i in range(n): if(tmp != a[i]): kind += 1 tmp = a[i] list_.append(0) list_[kind - 1] += 1 ans = 0 for i in range(kind - min_count): min_idx = list_.index(min(list_)) ans += list_[min_idx] list_[min_idx] = 200001 print(ans)
list_ = [0] n, min_count = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() kind = 1 tmp = a[0] for i in range(n): if(tmp != a[i]): kind += 1 tmp = a[i] list_.append(0) list_[kind - 1] += 1 ans = 0 list_.sort() idx = 0 for i in range(kind - min_count): ans += list_[idx] idx += 1 print(ans)
p03495
N , K = list(map(int,input().split())) li = list(map(int,input().split())) typ = [] for i in range(N): if li[i] == -1: pass else: count = 0 num = li[i] for i2 in range(N - i): if li[i + i2] == num: count += 1 li[i + i2] = -1 typ.append(count) typ.sort() count = 0 if len(typ) > K: for i in range(len(typ) - K): count += typ[i] print(count)
N , K = list(map(int,input().split())) li = list(map(int,input().split())) typ = [] li.sort() count = 0 for i in range(N - 1): count += 1 if li[i] != li[i + 1]: typ.append(count) count = 0 if li[N - 1] != li[N - 2]: typ.append(1) else: typ.append(count + 1) typ.sort() count = 0 if len(typ) > K: for i in range(len(typ) - K): count += typ[i] print(count)
p03495
n,k = list(map(int,input().split())) freq = {} a = [int(i) for i in input().split()] for i in a: if i not in freq: freq[i] = 1 else: freq[i] += 1 total = 0 while len(list(freq.keys())) > k: mn = (0,2000001) for i in list(freq.keys()): if freq[i] < mn[1]: mn = (i,freq[i]) total += mn[1] del freq[mn[0]] print(total)
n,k = list(map(int,input().split())) freq = {} a = [int(i) for i in input().split()] for i in a: if i not in freq: freq[i] = 1 else: freq[i] += 1 l = sorted(freq.values()) total = 0 index = 0 while len(l) - index > k: total += l[index] index += 1 print(total)
p03495
N, K = list(map(int, input().split())) A = list(map(int, input().split())) A_dict = {} rewrite = 0 for a in A: if a in A_dict: A_dict[a] += 1 else: A_dict[a] = 1 while len(A_dict) > K: rewrite_key = min(A_dict, key=A_dict.get) rewrite += A_dict[rewrite_key] del A_dict[rewrite_key] print(rewrite)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) A_dict = {} for a in A: if a in A_dict: A_dict[a] += 1 else: A_dict[a] = 1 A_sorted = sorted(list(A_dict.items()), key=lambda x:x[1], reverse=True) rewrite = 0 while len(A_sorted) > K: tmp = A_sorted.pop() rewrite += tmp[1] print(rewrite)
p03495
N, K = list(map(int, input().split())) A = list(map(int, input().split())) ## 種類数の求め方 # 1. A内の要素を取り出して、それがA内に存在するとき:種類+1 # 2. その要素を重複数だけAから削除してループ kinds = 0 A.sort() duplicatedList = [] while len(A) > 0: if A[0] in A: kinds += 1 duplicatedList.append(A.count(A[0])) for j in range(A.count(A[0])): A.remove(A[0]) if kinds <= K: print('0') else: duplicatedList.sort() tmp = 0 for i in range(kinds-K): tmp += duplicatedList[i] print(tmp)
n,k=list(map(int,input().split())) a=list(map(int,input().split())) d={} l=[] for i in range(n): try: l[d[a[i]]]+=1 except: d[a[i]]=len(l) l.append(1) ans=0 l.sort() for i in range(len(l)-k): ans+=l[i] print(ans)
p03495
import collections N, K = list(map(int, input().split())) A = [int(i) for i in input().split()] hint = collections.Counter(A) ans = 0 bb = hint.most_common() if K >= len(bb): print(ans) else: for i in range(-1, -(len(bb)-K)-1, -1): ans += bb[i][1] print(ans)
import collections N, K = list(map(int, input().split())) A = [int(i) for i in input().split()] ans = 0 con = collections.Counter(A).most_common() if len(con) <= K: print(ans) else: for a, b in con[K:]: ans += b print(ans)
p03495
import collections N, K = list(map(int, input().split())) A = [int(i) for i in input().split()] ans = 0 con = collections.Counter(A).most_common() if len(con) <= K: print(ans) else: for a, b in con[K:]: ans += b print(ans)
import collections N, K = list(map(int, input().split())) A = [int(i) for i in input().split()] num = collections.Counter(A).most_common()[::-1] ans = 0 if len(num) > K: for i in range(len(num) - K): ans += num[i][1] print(ans)
p03495
n, k = list(map(int, input().split())) a = list(map(int, input().split())) Alist = [] setA = [x for x in set(a)] for i in setA: Alist.append(a.count(i)) Alist.sort() ans = 0 for i in range(len(Alist) - k): ans += Alist[i] print(ans)
n, k = list(map(int, input().split())) a = list(map(int, input().split())) p = [0] * (n + 1) for i in a: p[i] += 1 p.sort() print((sum(p[:n-k+1])))
p03495
# -*- coding: utf-8 -*- N, K = list(map(int, input().split())) A = list(map(int, input().split())) count = [0] * len(set(A)) labels = set(A) for val in A: for i, label in enumerate(labels): if label==val: count[i] += 1 ans = 0 diff = len(set(A)) - K if diff > 0: count_sorted = sorted(count) for i in range(diff): ans += count_sorted[i] print(ans)
# -*- coding: utf-8 -*- N, K = list(map(int, input().split())) A = list(map(int, input().split())) count = {} for val in A: if val in count: count[val] += 1 else: count[val] = 1 ans = 0 diff = len(set(A)) - K if diff > 0: count_sorted = sorted(list(count.items()), key=lambda x:x[1]) for k,v in count_sorted: ans += v diff -= 1 if diff == 0: break print(ans)
p03495
N, K = [int(x) for x in input().split()] A_lst = [int(x) for x in input().split()] dict = {} for i in A_lst: if not i in list(dict.keys()): dict[i] = 1 else: dict[i] += 1 lst = [] for i in list(dict.keys()): lst.append(dict[i]) lst.sort() k = len(lst) cnt = 0 for i in lst: if k <= K: break else: k -= 1 cnt += i print(cnt)
N, K = [int(x) for x in input().split()] A_lst = [int(x) for x in input().split()] dict = {} for i in A_lst: if not i in list(dict.keys()): dict[i] = 1 else: dict[i] += 1 val_lst = list(dict.values()) val_lst.sort() k = len(val_lst) cnt = 0 for i in val_lst: if k <= K: break else: k -= 1 cnt += i print(cnt)
p03495
N, K = list(map(int, input().split())) A = list(map(int, input().split())) buckets = {} for i in A: if i in buckets: buckets[i] += 1 else: buckets[i] = 1 kinds = sorted(buckets.values()) count = len(kinds) if K < count: mini = 0 for i in kinds: mini += i count -= 1 if count <= K: break print(mini) else: print((0))
N, K = list(map(int, input().split())) A = list(map(int, input().split())) buckets = {} for i in A: if i in buckets: buckets[i] += 1 else: buckets[i] = 1 kinds = sorted(list(buckets.values()), reverse=True) if K < len(kinds): mini = N-sum([kinds[i] for i in range(K)]) print(mini) else: print((0))
p03495
n,k = list(map(int,input().split())) from collections import defaultdict d = defaultdict(int) num_list = list(map(int,input().split())) for tmp in num_list: d[tmp] += 1 v_list = sorted(list(d.values())) while len(v_list) > k: v_list.pop(0) print((n - sum(v_list)))
n,k = list(map(int,input().split())) from collections import defaultdict d = defaultdict(int) num_list = list(map(int,input().split())) for tmp in num_list: d[tmp] += 1 v_list = sorted(list(d.values()) ,reverse=True) print((n - sum(v_list[:k])))
p03495
N,K = list(map(int, input().split())) a_list = list(map(int, input().split())) counter_list = [] for i in range(1,N+1): if a_list.count(i) > 0: counter_list.append(a_list.count(i)) counter_list.sort() count = 0 for i in range(len(counter_list) - K): count += counter_list[i] print(count)
N,K = list(map(int, input().split())) a_list = list(map(int, input().split())) counter_list = [0]*N for i in a_list: counter_list[i-1] += 1 counter_list.sort(reverse=True) ans = N - sum(counter_list[:K]) print(ans)
p03495
n, k = list(map(int, input().split())) a = input().split() d = dict() for i in a: d[i] = d.get(i, 0) + 1 d_sorted = sorted(d.values()) knd = len(set(a))##種類数 print((sum(d_sorted[:knd - k])))
n, k = list(map(int, input().split())) a = input().split() b = dict() for i in a: b[i] = b.get(i, 0) + 1 print((sum(sorted(b.values())[:-k])))
p03495
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = LS() return l sys.setrecursionlimit(1000000) mod = 1000000007 #A def A(): n,a,b = LI() print((min(n*a,b))) return #B def B(): s = S() print((s.count("1"))) return #C def C(): n = list(map(int, S())) k = 0 s = sum(n) for i in range(len(n)): k *= 10 k += n[i] if k%s == 0: print("Yes") else: print("No") return #D def D(): n = I() a = LI() ans = float("inf") for i in range(n): m = 0 while a[i]%2 == 0: m += 1 a[i] //= 2 ans = min(m,ans) print(ans) return #E def E(): n = I() f = LIR(n) p = LIR(n) return #F def F(): n,k = LI() a = LI() d = defaultdict(int) for i in a: d[i] += 1 d = list(d.values()) d.sort() ans = 0 for i in range(len(d)-k): ans += d[i] print(ans) return #G def G(): return #H def H(): return #I def I_(): return #J def J(): return #Solve if __name__ == "__main__": F()
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from itertools import permutations import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): n,k = LI() a = LI() d = defaultdict(lambda : 0) for i in a: d[i] += 1 d = list(d.values()) d.sort() res = len(d)-k print((sum(d[:res]))) return #Solve if __name__ == "__main__": solve()
p03495
import collections n, k = list(map(int, input().split())) a = list(map(int, input().split())) cnt = collections.Counter(a) ans = 0 if len(cnt.most_common()) <= k: print((0)) exit() for i in range(k): ans += cnt.most_common()[i][1] print((n - ans))
import collections n, k = list(map(int, input().split())) a = list(map(int, input().split())) cnt = collections.Counter(a) ans = 0 t=cnt.most_common() if len(t) <= k: print((0)) exit() for i in range(k): ans += t[i][1] print((n - ans))
p03495
# -*- coding: utf-8 -*- from collections import Counter N, K = list(map(int, input().split())) num_list = list(map(int, input().split())) # 各数値ごとに数を集計 num_dict = Counter(num_list) ans = 0 while True: # 種類数がK以下なら終了 if len(num_dict) <= K: print(ans) exit() # 一番数が少ない要素の個数分、答えに追加 ans += num_dict.most_common()[-1][1] # 一番数が少ない要素を削除 del num_dict[num_dict.most_common()[-1][0]]
# -*- coding: utf-8 -*- from collections import Counter N, K = list(map(int, input().split())) num_list = list(map(int, input().split())) # 各数値ごとに数を集計 num_dict = Counter(num_list) # 数の少ない順でソート num_tpl = num_dict.most_common()[::-1] ans = 0 for i in range(len(num_tpl)): # 種類数がK以下なら終了 if len(num_tpl) - i <= K: print(ans) exit() # 数が少ない要素から、答えに追加していく ans += num_tpl[i][1]
p03495
from collections import Counter from collections import OrderedDict N, K = list(map(int, input().split())) cnt = Counter(list(map(int, input().split()))) tot = 0 if len(cnt) <= K: print((0)) else: k = [] for i in list(cnt.values()): k.append(i) k.sort() for i in range(len(cnt)-K): tot += k[i] print(tot)
from collections import Counter N, K = list(map(int, input().split())) cnt = Counter(list(map(int, input().split()))) tot = 0 k = [] for i in list(cnt.values()): k.append(i) k.sort() for i in range(len(cnt)-K): tot += k[i] print(tot)
p03495
import collections as col N,K = list(map(int,input().split())) A = list(map(int,input().split())) L= len(set(A)) A = col.Counter(A) ans = 0 if L <= K: print((0)) else: for i in range(1,L-K+1): ans += A.most_common()[-i][1] print(ans)
import collections as col N,K = list(map(int,input().split())) A = list(map(int,input().split())) L= len(set(A)) A = col.Counter(A) Aval = list(A.values()) Aval = sorted(Aval) ans = 0 if L <= K: print((0)) else: for i in range(L-K): ans += Aval[i] print(ans)
p03495
import collections import sys N,K=list(map(int,input().split())) a=[] a=collections.Counter( list(map(int,input().split())) ) b=sorted(list(a.items()), key=lambda x:x[1]) if len(b)=="K": print(0) sys.exit() else: sum=0 for i in range(len(b)-K): sum+=b[i][1] else: print(sum)
import sys from collections import Counter N,K=list(map(int, sys.stdin.readline().split())) A=list(map(int, sys.stdin.readline().split())) C=Counter(A) C=list(C.values()) C.sort() print(sum(C[:-1*K]))
p03495
import collections N,K = list(map(int, input().split())) A = list(map(int, input().split())) c = collections.Counter(A) cnt = 0 if K < len(list(c.keys())): for i in range(1,abs(len(list(c.keys())) - K)+1): cnt += c.most_common()[-i][1] print(cnt)
import collections N,K = list(map(int, input().split())) A = list(map(int, input().split())) c = collections.Counter(A) cnt = 0 most_common = c.most_common() if K < len(list(c.keys())): for i in range(1,abs(len(list(c.keys())) - K)+1): cnt += most_common[-i][1] print(cnt)
p03495
import collections N,K = list(map(int,input().split())) a = list(map(int,input().split())) c = collections.Counter(a) if len(c) <= K: print((0)) else: print((sum([c.most_common()[-i][1] for i in range(1,len(c)-K+1)])))
import collections N,K = list(map(int,input().split())) a = list(map(int,input().split())) c = collections.Counter(a) c_most = c.most_common() if len(c) <= K: print((0)) else: print((sum([c_most[-i][1] for i in range(1,len(c)-K+1)])))
p03495
import sys n, k = list(map(int, input().split())) a = list(map(int, input().split())) num_flag = [0 for i in range(n)] for item in a: num_flag[item - 1] += 1 while 0 in num_flag: num_flag.remove(0) num_flag.sort() cnt = 0 while len(num_flag) > k: cnt += num_flag[0] num_flag.pop(0) print(("{}".format(cnt)))
import sys n, k = list(map(int, input().split())) a = list(map(int, input().split())) num_flag = [0 for i in range(n)] for item in a: num_flag[item - 1] += 1 # while 0 in num_flag: # num_flag.remove(0) # num_flag.sort() # cnt = 0 # while len(num_flag) > k: # print(len(num_flag)) # cnt += num_flag[0] # num_flag.pop(0) num_flag.sort(reverse=True) cnt = 0 for i in range(k): cnt += num_flag[i] print(("{}".format(n - cnt)))
p03495
N, K = list(map(int,input().split())) ball = input().split() ball_list = sorted(list(set(ball))) nums = len(ball_list) if K >= nums: print("0") exit() balls = [] for i in range(nums): balls.append(ball.count(ball_list[i])) balls = sorted(balls, reverse=True) print((N - sum(balls[:K])))
N, K = list(map(int,input().split())) ball = input().split() d = {} if K >= len(set(ball)): print("0") exit() for i in ball: if not i in d: d[i] = 1 else: d[i] += 1 d_val = sorted(list(d.values()),reverse=True) print((N - sum(d_val[:K])))
p03495
nk = list(map(int,input().split())) ls = list(map(int,input().split())) d = dict() for i in ls: if i in d: d[i] += 1 else: d[i] = 1 adj = 0 key_num = len(list(d.keys())) while(1): if key_num <= nk[1]: print(adj) break min_idx = min(list(d.items()), key=lambda x:x[1])[0] min_num = min(list(d.items()), key=lambda x:x[1])[1] del d[min_idx] adj += min_num key_num -= 1
nk = list(map(int,input().split())) ls = list(map(int,input().split())) d = dict() for i in ls: if i in d: d[i] += 1 else: d[i] = 1 l = list(d.values()) l.sort(reverse = True) num = sum(l[nk[1]:]) print(num)
p03495
n,k = list(map(int,input().split())) a = list(map(int,input().split())) b = set(a) syurui = [] ans = 0 for i in b: syurui.append(a.count(i)) syurui.sort() if len(b) <= k: print((0)) else: for i in range(len(b)-k): ans += syurui[i] print(ans)
n,k = list(map(int,input().split())) a = list(map(int,input().split())) a.sort() ans = 0 key = a[0] a_syurui = [] count = 1 for i in a[1:]: if key == i: count += 1 else: a_syurui.append(count) count = 1 key = i a_syurui.append(count) a_syurui.sort() if len(a_syurui) <= k: print((0)) else: for i in range(len(a_syurui)-k): ans += a_syurui[i] print(ans)
p03495
n, k = list(map(int, input().split())) a = list(map(int, input().split())) cnt_list = [] b = set(a) for s in b: cnt_list.append(a.count(s)) cnt_list = sorted(cnt_list) print((sum(cnt_list[:len(cnt_list) - k])))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) cnt_list = [0]*(n+1) for i in range(n): cnt_list[a[i]] += 1 cnt_list.sort() print((sum(cnt_list[:len(cnt_list) - k])))
p03495
import collections n, k = list(map(int, input().split())) a = list(map(int, input().split())) a_val = collections.Counter(a) count = 0 if len(a_val) > k: for i in range(len(a_val) - k): count += a_val.most_common()[-1-i][1] print(count)
from collections import Counter n, k = list(map(int, input().split())) a = list(map(int, input().split())) a = sorted(list(Counter(a).values()), reverse=True) print((sum(a[k:])))
p03495
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import collections N, K = list(map(int, input().split())) A = list(map(int, input().split())) count_rmv = 0 count_int = sorted(collections.Counter(A).values()) num_int_type = len(count_int) while num_int_type > K: count_rmv += count_int[0] del count_int[0] num_int_type -= 1 print(count_rmv)
#!/usr/bin/env python # -*- coding: utf-8 -*- import collections N, K = list(map(int, input().split())) A = list(map(int, input().split())) count_rmv = 0 count_int = collections.Counter(A).most_common() num_int_type = len(count_int) while num_int_type > K: num_int_type -= 1 count_rmv += count_int[num_int_type][1] print(count_rmv)
p03495
N,K = [int(i) for i in input().split()] AAA = [int(i) for i in input().split()] count = [0 for i in range(200010)] for A in AAA: count[A]+=1 ans=0 while sum([1 if i!=0 else 0 for i in count])>K: #print(count[:10]) buff = min([i for i in count if i!=0]) ans += buff count.remove(buff) print(ans)
N,K = [int(i) for i in input().split()] AAA = [int(i) for i in input().split()] count = [0 for i in range(200010)] for A in AAA: count[A]+=1 ans=0 count=sorted([i for i in count if i!=0]) if len(count)<=K: print("0") exit() else: print((sum(count[:-K])))
p03495
import collections N, K = list(map(int, input().split())) A = list(map(int, input().split())) number = len(set(A)) c = collections.Counter(A) values,counts=list(zip(*c.most_common())) count = 0 for i in range(number): if number <= K: print(count) break count += counts[-(i+1)] number -= 1
from collections import Counter N, K = list(map(int, input().split())) A = list(map(int, input().split())) c = Counter(A) d = c.most_common()[::-1] ans = 0 for i in range(len(set(A))-K): ans += d[i][1] print(ans)
p03495
N, K = list(map(int, input().split())) A = list(map(int, input().split())) A_set = set(A) A_dict = {} for i in A_set: A_dict[i] = A.count(i) A_dict = sorted(list(A_dict.items()), key=lambda x:x[1]) ans = 0 if len(A_set) > K: for i in range(len(A_set) - K): ans += A_dict[i][1] print(ans)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) A_set = set(A) A_dict = {x:0 for x in A_set} for i in A: A_dict[i] += 1 A_dict = sorted(list(A_dict.items()), key=lambda x:x[1]) ans = 0 if len(A_set) > K: for i in range(len(A_set) - K): ans += A_dict[i][1] print(ans)
p03495
import collections from collections import OrderedDict count=0 N,K=list(map(int,input().split())) ball=list(map(str,input().split())) c=sorted(collections.Counter(ball).values()) n=len(c)-K if n==0: print(count) else: for i in range(n): count+=c[i] print(count)
import collections N,K=list(map(int,input().split())) c=sorted(collections.Counter(list(map(str,input().split()))).values()) print((sum(c[:-K])))
p03495
N, K = list(map(int, input().split())) list_A = [int(x) for x in input().split()] set_A = set(list_A) if len(set_A) <= K : print((0)) exit() dict_A = dict.fromkeys(set_A, 0) for i in range(N) : dict_A[list_A[i]] += 1 ans = 0 for i in range(len(set_A)-K) : ans += min(dict_A.values()) del dict_A[min(dict_A, key=dict_A.get)] print(ans)
N, K = list(map(int, input().split())) list_A = [int(x) for x in input().split()] list_num = [0 for i in range(N+1)] for i in range(N) : list_num[list_A[i]] += 1 list_num.sort(reverse = True) ans = N for i in range(K) : ans -= list_num[i] if ans > 0 : print(ans) else : print((0))
p03495
import collections N, K = list(map(int, input().split())) A = list(map(int, input().split())) c = collections.Counter(A) n = len(c) cnt = 0 if n - K > 0: for i in range(n - K): cnt += c.most_common()[::-1][i][1] print(cnt)
import collections N, K = list(map(int, input().split())) A = list(map(int, input().split())) c = collections.Counter(A) n = len(c) c_sorted = sorted(c.values()) cnt = 0 for i in range(max(0, n - K)): cnt += c_sorted[i] print(cnt)
p03495
N,K = list(map(int,input().split())) A = list(map(int,input().split())) Ad = {x:0 for x in set(A)} if len(set(A)) <= K: print((0)) else: count = 0 for a in A: Ad[a] += 1 Ad = sorted(list(Ad.items()), key=lambda x:x[1]) for i in range(len(set(A))-K): count += Ad[i][1] print(count)
n,k = list(map(int,input().split())) A = list(map(int,input().split())) if len(set(A))<=k: print((0)) else: d = {i:0 for i in set(A)} for a in A: d[a] += 1 ans = list(d.values()) ans.sort(reverse = True) print((sum(ans[k:])))
p03495
n,k = list(map(int,input().split())) A = list(map(int,input().split())) if len(set(A))<=k: print((0)) else: d = {i:0 for i in set(A)} for a in A: d[a] += 1 ans = list(d.values()) ans.sort(reverse = True) print((sum(ans[k:])))
n,k = list(map(int,input().split())) A = list(map(int,input().split())) d = {i:0 for i in set(A)} for a in A: d[a] += 1 ans = list(d.values()) ans.sort(reverse = True) print((sum(ans[k:])))
p03495
import collections N,K=list(map(int,input().split())) li=list(map(int,input().split())) li_count=collections.Counter(li) change=0 S=max(len(li_count)-K,0) for s in range(S): change+=li_count.most_common()[-1-s][1] print(change)
import collections N,K=list(map(int,input().split())) li=list(map(int,input().split())) li_count=collections.Counter(li) li_count_most=li_count.most_common()[::-1] change=0 S=max(len(li_count)-K,0) for s in range(S): change+=li_count_most[s][1] print(change)
p03495
#-*-coding:utf-8-*- from collections import Counter def main(): n, k = list(map(int, input().split())) a_list = list(input().split()) a_set = set(a_list) c = Counter(a_list) cnt = 0 for i in range(len(a_set) - k): cnt += c.most_common()[::-1][i][1] print(cnt) if __name__ == '__main__': main()
#-*-coding:utf-8-*- #from collections import Counter def main(): n, k = list(map(int, input().split())) a_list = list(input().split()) a_set = set(a_list) #c = Counter(a_list) dic = {} for i in a_list: dic.setdefault(i, 0) dic[i] += 1 freq = sorted(dic.values()) cnt = 0 for i in range(len(a_set) - k): cnt += freq[i] #cnt += c.most_common()[::-1][i][1] print(cnt) if __name__ == '__main__': main()
p03495
from collections import Counter N,K = list(map(int,input().split())) src = list(map(int,input().split())) ctr = Counter(src) ans = 0 kind = len(ctr) for k,v in reversed(ctr.most_common()): if kind <= K: break ans += v kind -= 1 print(ans)
from collections import Counter N,K = list(map(int,input().split())) src = list(map(int,input().split())) ctr = Counter(src) ans = N for k,v in ctr.most_common(K): ans -= v print(ans)
p03495
from collections import Counter N,K = list(map(int,input().split())) src = list(map(int,input().split())) ctr = Counter(src) ans = N for k,v in ctr.most_common(K): ans -= v print(ans)
from collections import Counter N,K = list(map(int,input().split())) A = list(map(int,input().split())) ctr = Counter(A) stay = 0 for k,v in ctr.most_common(K): stay += v print((N - stay))
p03495
import collections def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) c = collections.Counter(A) i = 0 ans = 0 for num, cnt in c.most_common()[::-1]: if i >= len(set(A)) - K: break ans += cnt i += 1 print(ans) main()
import collections def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) TMP = [0] * N for i in A: TMP[i-1] += 1 sort_TMP = sorted(TMP, reverse=True) max_ball = 0 cnt = 1 for a in sort_TMP: if cnt <= K: cnt += 1 max_ball += a else: break print((N-max_ball)) main()
p03495
n, k = list(map(int, input().split())) aList = list(map(int, input().split())) num = [0 for _ in range(n + 1)] for i in range(n + 1): if i in aList: num[i] += aList.count(i) num.sort() num = num[:-k] print((sum(num)))
n, k = list(map(int, input().split())) aList = list(map(int, input().split())) num = [0 for _ in range(n + 1)] for i in aList: num[i] += 1 num.sort() num = num[:-k] print((sum(num)))
p03495
from collections import Counter N, K = list(map(int, input().split())) A = Counter(list(map(int, input().split()))).most_common() l = len(A) ans = 0 while l > K: ans += A[-1][1] del A[-1] l = len(A) print(ans)
from collections import Counter N, K = list(map(int, input().split())) A = Counter(list(map(int, input().split()))).most_common() ans = 0 while len(A) > K: ans += A[-1][1] del A[-1] print(ans)
p03495
# -*- coding: utf-8 -*- import io import sys import math def solve(n, k, a_lst): # implement process a_set = set(a_lst) ak = len(a_set) diff = ak - k if diff < 1: return 0 min_change = float("inf") cnt_lst = [] for a in a_set: cnt_lst.append(a_lst.count(a)) cnt_lst.sort() return sum(cnt_lst[0:diff]) def main(): # input n, k = list(map(int,input().split())) a_lst = list(map(int,input().split())) # process ans = str( solve(n, k, a_lst) ) # output print(ans) return ans ### DEBUG I/O ### _DEB = 0 # 1:ON / 0:OFF _INPUT = """\ 10 3 5 1 3 2 4 1 1 2 3 4 """ _EXPECTED = """\ 0 """ def logd(str): """usage: if _DEB: logd(f"{str}") """ if _DEB: print(f"[deb] {str}") ### MAIN ### if __name__ == "__main__": if _DEB: sys.stdin = io.StringIO(_INPUT) print("!! Debug Mode !!") ans = main() if _DEB: print() if _EXPECTED.strip() == ans.strip(): print("!! Success !!") else: print(f"!! Failed... !!\nANSWER: {ans}\nExpected: {_EXPECTED}")
# -*- coding: utf-8 -*- import io import sys import math def solve(n, k, a_lst): # implement process a_set = set(a_lst) ak = len(a_set) diff = ak - k if diff < 1: return 0 #ソート済み配列を検査することで、count処理を線形にする a_lst.sort() tmp = a_lst[0] cnt = 0 cnt_lst = [] for i in range(len(a_lst)): if tmp != a_lst[i]: tmp = a_lst[i] cnt_lst.append(cnt) cnt = 0 cnt += 1 cnt_lst.append(cnt) cnt_lst.sort() return sum(cnt_lst[0:diff]) def main(): # input n, k = list(map(int,input().split())) a_lst = list(map(int,input().split())) # process ans = str( solve(n, k, a_lst) ) # output print(ans) return ans ### DEBUG I/O ### _DEB = 0 # 1:ON / 0:OFF _INPUT = """\ 5 2 1 1 2 2 5 """ _EXPECTED = """\ 0 """ def logd(str): """usage: if _DEB: logd(f"{str}") """ if _DEB: print(f"[deb] {str}") ### MAIN ### if __name__ == "__main__": if _DEB: sys.stdin = io.StringIO(_INPUT) print("!! Debug Mode !!") ans = main() if _DEB: print() if _EXPECTED.strip() == ans.strip(): print("!! Success !!") else: print(f"!! Failed... !!\nANSWER: {ans}\nExpected: {_EXPECTED}")
p03495
import collections n, k = list(map(int, input().split())) a = list(map(int, input().split())) c = collections.Counter(a) count = 0 for i in range(k, len(c)): count += c.most_common()[i][1] print(count)
n, k = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() count = 1 b = [] for i in range(n-1): if a[i] != a[i+1]: b.append(count) count = 1 else: count += 1 b.append(count) b.sort(reverse=True) count = 0 if k < len(b): for i in range(k, len(b)): count += b[i] print(count)
p03495
n,k = list(map(int,input().split())) a = {} s = 0 for i in input().split(): a[int(i)] = a.get(int(i),0)+1 b = list(a.values()) while(k<len(b)): c = min(b) s+=c b.remove(c) print(s)
n,k = list(map(int,input().split())) a = {} for i in input().split(): a[int(i)] = a.get(int(i),0)+1 b = list(a.values()) b.sort() print((sum(b[:len(b)-k])))
p03495
# -*- coding: utf-8 -*- n, k = list(map(int, input().split())) A = list(map(int, input().split())) dict_A = {} for a in A: if a not in dict_A: dict_A[a] = 1 else: dict_A[a] += 1 if len(list(dict_A.keys())) <= k: print((0)) exit() sorted_A = sorted(list(dict_A.items()), key=lambda x: x[1]) ans = 0 for i in range(len(list(dict_A.keys()))-k): ans += sorted_A[i][1] print(ans)
# -*- coding: utf-8 -*- n, k = list(map(int, input().split())) A = list(map(int, input().split())) B = {} for a in A: if a not in B: B[a] = 1 else: B[a] += 1 C = sorted(list(B.items()), key=lambda x: x[1]) if len(C) <= k: print((0)) else: ans = 0 for i in range(len(C)-k): ans += C[i][1] print(ans)
p03495
import collections n,k = list(map(int,input().split())) a = list(map(int,input().split())) a = collections.Counter(a) a = a.most_common() if k<len(a): x = 0 for i in range(k,len(a)): x += a[i][1] print(x) else: print((0))
import collections n,k = list(map(int,input().split())) a = list(input().split()) a = collections.Counter(a) a = a.most_common() if k<len(a): x = 0 for i in range(k,len(a)): x += a[i][1] print(x) else: print((0))
p03495
N, K = [int(x) for x in input().split(" ")] lst = [int(x) for x in input().split(" ")] dic= {} cnt = 0 swap = 0 for i in range(1,N+1): dic["{}".format(i)] = 0 for i in range(0,N): dic["{}".format(lst[i])] += 1 sorted_dic = sorted(list(dic.items()), key = lambda x : x[1]) for i in range(0,N): swap += sorted_dic[i][1] if sorted_dic[i][1] != 0: cnt +=1 if cnt >= len(set(lst))-K: break print(swap)
N, K = [int(x) for x in input().split(" ")] lst = [int(x) for x in input().split(" ")] dic= {} cnt = 0 swap = 0 prep = len(set(lst))-K for i in range(1,N+1): dic["{}".format(i)] = 0 for i in range(0,N): dic["{}".format(lst[i])] += 1 sorted_dic = sorted(list(dic.items()), key = lambda x : x[1]) for i in range(0,N): swap += sorted_dic[i][1] if sorted_dic[i][1] != 0: cnt +=1 if cnt >= prep: break print(swap)
p03495
from collections import Counter from sys import stdin input = stdin.readline N, K = list(map(int, input().split())) An = Counter([int(i) for i in input().split()]) def main(): # 要素数(v) 多い順 インデックス K 含んでそれよりも後ろ # 先頭 K + 1 個目から 末尾 まで # 要素数(v) 合計 print((sum([v for k, v in An.most_common()[K:]]))) return main()
from collections import Counter from sys import stdin input = stdin.readline N, K = list(map(int, input().split())) An = Counter(input().split()) def main(): # 要素数(v) 昇順 # 先頭 から インデックス len(An) - K - 1 まで # 要素数(v) 合計 print((sum(sorted(An.values())[:len(An) - K]))) return main()
p03495
from collections import Counter from sys import stdin input = stdin.readline N, K = list(map(int, input().split())) An = Counter(input().split()) def main(): # 要素数(v) 昇順 # 先頭 から インデックス len(An) - K - 1 まで # 要素数(v) 合計 print((sum(sorted(An.values())[:len(An) - K]))) return main()
from collections import Counter N, K = list(map(int, input().split())) An = Counter(input().split()) def main(): # 要素数(v) 昇順 # 先頭 から インデックス len(An) - K - 1 まで # 要素数(v) 合計 print((sum(sorted(An.values())[:len(An) - K]))) return main()
p03495
n, k = list(map(int, input().split())) a = list(map(int, input().split())) count = [0] * n for x in range(n): count[a[x]-1] += 1 count.sort() length = len(count) for x in range(length): if len(count[x:]) == k: break print((sum(count[:x])))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) count = [0] * n for x in range(n): count[a[x]-1] += 1 count.sort() length = len(count) print((sum(count[:length - k])))
p03495