Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import collections

def solve(N: int, s: "List[str]"):
    answer = 0
    ss = [collections.Counter(s[i]) for i in range(N)]
    for i in range(N):
        for j in range(i+1,N):
            if ss[i] == ss[j]:
                answer += 1
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import collections
from itertools import groupby

def solve(N: int, s: "List[str]"):
    s = [sorted(s[i]) for i in range(N)]
    s.sort()
    group = groupby(s)
    answer = 0
    for key, group in group:
        a = len(list(group))
        answer += int(a*(a-1)/2) if a > 1 else 0
    print(answer)
   


    # for i in range(N):
    #     a = 1
    #     pop_index = []
    #     for j in range(i+1,len(ss)):
    #         if ss[i] == ss[j]:
    #             a += 1
    #             pop_index.append(j)
        
    #     ss = [ss[i] for i in range(len(ss)) if i not in pop_index]
    #     answer += int(a*(a-1)/2) if a > 1 else 0
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

a,b,k=map(int,input().split())

for i in range(a,b+1):
    if i <= a+k-1 or i >= b-k+1:
        print(i)

### FIXED CODE ###

a,b,k=map(int,input().split())

for i in range(a,min(b,a+k-1)+1):
    print(i)

for j in range(max(b-k+1,a+k),b+1):
    print(j)
### BUGGY CODE ###

#n, m = [int(x) for x in input().split()]

s = list(input())
q = int(input())

for _ in range(q):
  Q = [x for x in input().split()]
  if Q[0] == '1':
    s.reverse()
  else:
    if Q[1] == '1':
      s.insert(0, Q[2])
    else:
      s.append(Q[2])

print('' . join(s))

### FIXED CODE ###

from collections import deque

s = deque(input())
q = int(input())
flg = 0

for _ in range(q):
  Q = [x for x in input().split()]
  if Q[0] == '1':
    flg += 1
  else:
    if (Q[1] == '1' and flg%2==0) or (Q[1] == '2' and flg%2==1):
      s.appendleft(Q[2])
    else:
      s.append(Q[2])
if flg%2==1:
  s.reverse()

print('' . join(s))
### BUGGY CODE ###

x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

li  = []

for i in a:
    for j in b:
        li.append(i+j)

li.sort(reverse=True)
li = li[:k]

lin = []

for i in li:
    for j in c:
        lin.append(i+j)

lin.sort(reverse=True)

for i in range(k):
    print(lin[i])

### FIXED CODE ###

x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

li  = []

for i in a:
    for j in b:
        li.append(i+j)

li.sort(reverse=True)
li = li[:k]

lin = []

for i in li:
    for j in c:
        lin.append(i+j)

lin.sort(reverse=True)

for i in range(k):
    print(lin[i])
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, K: int, x: "List[int]", y: "List[int]"):
    sx = sorted(x)
    sy = sorted(y)
    acc = [[0]*N for _ in range(N)]

    for i, x1 in enumerate(sx):
        for j, y1 in enumerate(sy):
            acc[i][j] = sum([True for xx, yy in zip(x, y)
                             if xx <= x1 and yy <= y1])

    m = INF

    for i, x1 in enumerate(sx[:-K+1]):
        for j, y1 in enumerate(sy[:-K+1]):
            # 始点を固定
            for x2 in sx[i+1:]:
                for y2 in sy[j+1:]:
                    # 終点を固定
                    counter = 0
                    for xx, yy in zip(x, y):
                        if (x1 <= xx <= x2) and (y1 <= yy <= y2):
                            counter += 1
                    if counter >= K:
                        flag = True
                        area = abs((y2-y1)*(x2-x1))
                        if area < m:
                            m = area
                        break   # これ以上yをあげたところで面積は増える一方なので抜ける
    print(m)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, K, x, y)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, K: int, x: "List[int]", y: "List[int]"):
    sx = sorted(x)
    sy = sorted(y)
    acc = [[0]*N for _ in range(N)]

    for i, x1 in enumerate(sx):
        for j, y1 in enumerate(sy):
            acc[i][j] = sum([True for xx, yy in zip(x, y)
                             if xx <= x1 and yy <= y1])

    m = INF

    for i, x1 in enumerate(sx[:-K+1]):
        for j, y1 in enumerate(sy[:-K+1]):
            # 始点を固定
            for x2 in sx[i+1:]:
                for y2 in sy[j+1:]:
                    # 終点を固定
                    counter = 0
                    for xx, yy in zip(x, y):
                        if (x1 <= xx <= x2) and (y1 <= yy <= y2):
                            counter += 1
                    if counter >= K:
                        flag = True
                        area = abs((y2-y1)*(x2-x1))
                        if area < m:
                            m = area
                        break   # これ以上yをあげたところで面積は増える一方なので抜ける
    print(m)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, K, x, y)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import collections
n = int(input())
*a, = map(int, input().split())
counter = collections.Counter(a)
#print(counter)
d = {}
for key, value in counter.items():
    d[key] = (value * (value - 1)) // 2
#print(counter)

#print('d:', d, end='\n\n')

for k in range(n):
    d2 = d.copy()
    '''
    print('d2:', d2)
    print(f'a[{k}]:', a[k], end=', ')
    print(f'd[{a[k]}]:', d[a[k]])
    print('計算')
    print(f'(counter[a[k]] - 1):{(counter[a[k]] - 1)}')
    print(f'(counter[a[k]] - 2): {(counter[a[k]] - 2)}')
    '''
    
    if d[a[k]] > 0: d2[a[k]] = ((counter[a[k]] - 1) * (counter[a[k]] - 2)) // 2
    #print(f'd2({a[k]}除く):', d2)
    print(sum(d2.values()))

### FIXED CODE ###

import collections
n = int(input())
*a, = map(int, input().split())
counter = collections.Counter(a)
d = {key: (value * (value - 1)) // 2 for key, value in counter.items()}
#print(d)
all_sum = sum(d.values())
#print(all_sum)

sum_d = {}
for k in range(n):
    if a[k] not in sum_d:
        if d[a[k]] > 0:
            tmp = ((counter[a[k]] - 1) * (counter[a[k]] - 2)) // 2
            sum_d[a[k]] = all_sum  - d[a[k]] + tmp
            print(sum_d[a[k]])
        else:
            print(all_sum)
    else:
        print(sum_d[a[k]])
### BUGGY CODE ###

while True:
	ans = 0
	try:
		limit = input()
		for n in range(2, limit + 1):
			for x in range(2, n):
				if n % x == 0:
					break
			else:
					ans = ans + 1
		print ans
	except EOFError:
		pass

### FIXED CODE ###

def prime_count(n):
	j = 0
	ans = [1] * (n + 1)
	ans[0] = ans[1] = 0
	for i in xrange(3, n + 1, 2):
		if i * 2 > n:
			break
		if ans[i] != 0:
			for j in xrange(2 * i, n + 1, i):
				ans[j] = 0
	for k in xrange(2 * 2, n + 1, 2):
		ans[k] = 0
	print sum(ans)

try:
	while True:
		n = input()
		prime_count(n)
except EOFError:
	pass
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
L = []
for i in range(M):
	b, c = map(int, input().split())
	_ = [c, b]
	L.append(_)
	L.sort()
	L.reverse()
c = 0
D = []
while c < N and len(L) > 0:
	for i in range(L[0][1]):
		D.append(L[0][0])
		c += 1
	del L[0]
i = 0
while D[i] >= A[i] and i < N and i < len(D):
	i += 1
	if i == len(D) or i == N:
		break
x = sum(D[:i]) + sum(A[i:])
print(x)

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
L = []
for i in range(M):
	b, c = map(int, input().split())
	L.append((c, b))
L = sorted(L, reverse = True)
L.append((0, N))
temp = 0
sum = 0
for i in range(M + 1):
	for j in range(L[i][1]):
		if A[temp] < L[i][0]:
			sum += L[i][0]
			temp += 1
		else:
			sum += A[temp]
			temp += 1
		if temp == N:
			break
	if temp == N:
		break
print(sum)
### BUGGY CODE ###

import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


# 解説

N, T = list(map(int, sys.stdin.buffer.readline().split()))
A, B = list(zip(*[map(int, sys.stdin.buffer.readline().split()) for _ in range(N)]))

A = np.array(A, dtype=int)
B = np.array(B, dtype=int)

# 移動時間を考えなくて良いようにする
A += 1
B += 1
T += 1

# 使う店を決めたとき、(a - 1) / b の大きい順に使うのが最適
I = np.argsort((A - 1) / B)[::-1]
A = A[I]
B = B[I]

idx_zero = np.searchsorted((A == 1).astype(int), 1, side='left')
MAX_COUNT = (10 ** 9).bit_length() + 2
# dp[i][x]: i まで見て、x こ使うときの t の最小値
dp = np.full((idx_zero + 1, MAX_COUNT), IINF, dtype=int)
dp[:, 0] = 1
for x in range(MAX_COUNT - 1):
    dp[1:, x + 1] = dp[:-1, x] * A[:idx_zero] + B[:idx_zero]
    dp[:, x + 1] = np.minimum.accumulate(dp[:, x + 1])
    dp[:, x + 1] = np.minimum(dp[:, x + 1], T + 1)

#: :type: list of int
B_A0 = np.msort(B[idx_zero:]).tolist()
ans = 0
# idx_zero 以降で、B を小さい順に使えるだけ使う
for cnt, t in enumerate(dp[idx_zero].tolist()):
    if t > T:
        break
    i = 0
    while i < len(B_A0) and t + B_A0[i] <= T:
        t += B_A0[i]
        i += 1
        cnt += 1
    ans = max(ans, cnt)
print(ans)


### FIXED CODE ###

import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


# 解説

N, T = list(map(int, sys.stdin.buffer.readline().split()))
A, B = list(zip(*[map(int, sys.stdin.buffer.readline().split()) for _ in range(N)]))

A = np.array(A, dtype=int)
B = np.array(B, dtype=int)

# 移動時間を考えなくて良いようにする
A += 1
B += 1
T += 1

# 使う店を決めたとき、(a - 1) / b の大きい順に使うのが最適
I = np.argsort((A - 1) / B)[::-1]
A = A[I]
B = B[I]

idx_zero = np.searchsorted((A == 1).astype(int), 1, side='left')
A1 = A[:idx_zero]
B1 = B[:idx_zero]
B2 = np.msort(B[idx_zero:])

MAX_COUNT = (10 ** 9).bit_length() + 2
# dp[i][x]: i まで見て、x こ使うときの t の最小値
dp = np.full((idx_zero + 1, MAX_COUNT), T + 1, dtype=int)
dp[:, 0] = 1
for x in range(MAX_COUNT - 1):
    next_col = dp[:-1, x] * A1 + B1
    np.minimum(next_col, T + 1, out=next_col)
    np.minimum.accumulate(next_col, out=next_col)
    dp[1:, x + 1] = next_col

# idx_zero 以降で、B を小さい順に使えるだけ使う
cum = B2.cumsum()
counts = np.searchsorted(cum, T - dp[idx_zero], side='right')
ans = counts + np.arange(dp.shape[1])
print(ans[dp[idx_zero] <= T].max())
### BUGGY CODE ###

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

tmp1 = abs(N - K)

while True:
    if K == 1:
        print(0)
        break
    tmp2 = abs(tmp1 - K)
    if tmp1 < tmp2:
        print(tmp1)
        break
    else:
        tmp1 = tmp2


### FIXED CODE ###

N, K = map(int, input().split())
print(min(N % K, K - (N % K)))
### BUGGY CODE ###

# 解説放送
# 写経

def main():
    inf = 18 * (10 ** 6 + 1)

    s = input()
    s = '0' + s
    *s, = map(int, s)  # 先に一括でintにした

    n = len(s)

    dp = [[inf] * 2 for _ in range(n + 1)]
    dp[0][0] = 0

    for i, c in enumerate(s[::-1]):
        for j in range(2):
            x = c + j
            if x < 10:
                dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + x)  # a=x,b=0
            if x > 0:
                dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + (10 - x))  # a=0,bに繰り下がり

    print(dp[n][0])


if __name__ == '__main__':
    main()


### FIXED CODE ###

# 解説放送
# 写経

def main():
    inf = 18 * (10 ** 6 + 1)

    s = input()
    s = '0' + s

    n = len(s)

    dp = [[inf] * 2 for _ in range(n + 1)]
    dp[0][0] = 0

    for i, c in enumerate(s[::-1]):
        for j in range(2):
            x = int(c) + j
            if x < 10:
                dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + x)  # a=x,b=0
            if x > 0:
                dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + (10 - x))  # a=0,bに繰り下がり

    print(dp[n][0])


if __name__ == '__main__':
    main()
### BUGGY CODE ###

# ABC169 B Multiplication 2

from collections import deque

n = int(input())

a_list = deque([int(x) for x in input().split()])

ans = 1
for i in range(n):
    ans *= a_list.popleft()

if ans > 10**18:
    print("-1")
else:
    print(ans)

### FIXED CODE ###

# ABC169 B Multiplication 2

from collections import deque

n = int(input())

a_list = [int(x) for x in input().split()]

if min(a_list) == 0:
    print("0")
else:
    a_dq = deque(a_list)
    ans = 1
    for i in range(n):
        ans *= a_dq.popleft()
        if ans > 10**18:
            break

    if ans > 10**18:
        print("-1")
    else:
        print(ans)
### BUGGY CODE ###

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

sum_A = sum(A)
sum_B = sum(B)
if sum_A > K: # 時間を超過する場合
    tmp_cnt = 0
    for i,a in enumerate(A):
        tmp_cnt += a
        if tmp_cnt > K:
            break
    A_n_max = i
else: #時間を超過しない場合
    A_n_max = len(A)
    
cnt = 0
best_cnt = 0
for a_sub_i in range(A_n_max):
    cnt = A_n_max - a_sub_i
    time_left = K - sum(A[:(A_n_max - a_sub_i)])
   # print(a_sub_i)
   # print(time_left)
    for b_j in range(len(B)):
      #  print(b_j)
        if (time_left - sum(B[:(b_j+1)])) < 0:
            cnt = cnt + b_j
    #        print(f"b done {b_j}")
            break
        if b_j == (len(B)-1):
            cnt = cnt + b_j +1
     #       print(f"b done__ {b_j}")
            break
            
    if cnt > best_cnt:
        best_cnt = cnt
        
print(best_cnt)

### FIXED CODE ###

N, M, K = list(map(int, input().split()))
A = [0] + [int(i) for i in input().split() ]
B = [0] + [int(i) for i in input().split() ]

best = 0
a_time = 0
b_time = sum(B)
b_i = len(B)-1
end_flag = False
for a_i in range(N+1):
    a_time += A[a_i]
    while a_time + b_time > K:
        if b_i == 0:
            end_flag = True
            break
        b_time -= B[b_i]
        b_i -= 1

    if end_flag == True:
        break
    if a_i + b_i > best:
        best = a_i + b_i

print(best)
### BUGGY CODE ###

n,m = map(int,input().split())
price = []
honsu = []
for i in range(n):
  a,b = map(int,input().split())
  price.append(a)
  honsu.append(b)
for j in range(n):
  k = j + 1
  while(k<n):
    if price[j] > price[k]:
      temp1,temp2 = price[j],honsu[j]
      price[j] = price[k]
      honsu[j] = honsu[k]
      price[k] = temp1
      honsu[k] = temp2
    k+=1
money = 0
l = 0
while m > 0:
  if(m-honsu[l]>0):
    m -= honsu[l]
    money += honsu[l] * price[l]
  else:
    c = abs(m-honsu[l])
    m -= honsu[l]-c
    money += (honsu[l]-c) * price[l]
  l += 1
print(money)

### FIXED CODE ###

n,m = map(int,input().split())
price = []
honsu = []
c = []
for i in range(n):
  a,b = map(int,input().split())
  c.append([a,b])
c = sorted(c)
price,honsu=zip(*c)
money = 0
l = 0
while m > 0:
  if(m-honsu[l]>0):
    m -= honsu[l]
    money += honsu[l] * price[l]
  else:
    c = abs(m-honsu[l])
    m -= honsu[l]-c
    money += (honsu[l]-c) * price[l]
  l += 1
print(money)
### BUGGY CODE ###

import collections
mod = 10**9+7
n=int(input())
kaijou = []
kaijou.append(1)
for i in range(1,n+3):
    kaijou.append(kaijou[i-1]*i)

lcom = [[0 for _ in range(n+3)] for _ in range(n+3)]

def conb(p,r):
    if lcom[p][r] == 0:
        lcom[p][r] = kaijou[p]//(kaijou[r]*kaijou[p-r])
    return lcom[p][r]

def tyoufuku(i,a,b):
    global n
    ret = 0
    if i == 1:
        return 1
    else:
        for j in range(i):
            if a < j or n-b <i-j-1:
                continue
            else:
                ret += conb(a,j)*conb(n-b,i-j-1)
        return ret


def main():
    global n
    a=list(map(int,input().split()))

    ca= collections.Counter(a)
    tyo= ca.most_common()[0][0]

    kaburi=[i for i, x in enumerate(a) if x == tyo]

    for i in range(1,n+2):
        print((conb(n+1,i)-tyoufuku(i,kaburi[0],kaburi[1]))%mod)

main()

### FIXED CODE ###

import collections
mod = 10**9+7
fac = [1]
caf = [1]
n=int(input())

def pow(n,p):
    res=1
    while p >0:
        if p%2==0:
            n = n**2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod

for i in range(1,n+2):
    fac.append((fac[i-1]*i)%mod)
    caf.append(pow(fac[i],mod-2)%mod)

def ncr(n,r):
    if n < r: return 0
    return fac[n]*caf[r]*caf[n-r]

def main():
    global n
    a=list(map(int,input().split()))

    ca= collections.Counter(a)
    tyo= ca.most_common()[0][0]
    kaburi=[i for i, x in enumerate(a) if x == tyo]

    for i in range(1,n+2):
        print((ncr(n+1,i)-ncr(n+1-(kaburi[1]-kaburi[0]+1),i-1))%mod)

main()
### BUGGY CODE ###

import itertools
import fractions

K = int(input())
K = [i for i in range(1, K+1)]
p = itertools.product(K, repeat=3)
p = list(p)

g = []

for i in p:
    a = fractions.gcd(i[0], i[1])
    b = fractions.gcd(a, i[2])
    g.append(b)

print(sum(g))


### FIXED CODE ###

import math

K = int(input())
g = 0
for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            a = math.gcd(i, j)
            b = math.gcd(a, k)
            if i != j != k:
                g += b*6
            elif i == j == k:
                g += b
            else:
                g += b*3

print(g)
### BUGGY CODE ###

def main():
  import sys
  input = lambda: sys.stdin.readline().rstrip()
  from heapq import heappop,heappush
  h,w=map(int,input().split())
  n=h*w
  hw=lambda hh,ww:hh*w+ww
  ch,cw=map(int,input().split())
  s=hw(ch-1,cw-1)
  dh,dw=map(int,input().split())
  g=hw(dh-1,dw-1)
  b=[list(input())for _ in range(h)]
  edge=[[]for _ in range(h*w)]
  for i in range(h):
    for j in range(w):
      if b[i][j]=="#":continue
      if i!=h-1:
        if b[i+1][j]==".":
          edge[hw(i,j)].append((hw(i+1,j),0))
          edge[hw(i+1,j)].append((hw(i,j),0))
      if j!=w-1:
        if b[i][j+1]==".":
          edge[hw(i,j)].append((hw(i,j+1),0))
          edge[hw(i,j+1)].append((hw(i,j),0))
      for ii in range(max(0,i-2),min(h,i+3)):
        for jj in range(max(0,j-2),min(w,j+3)):
          if i==ii and j==jj:continue
          if b[ii][jj]==".":
            edge[hw(i,j)].append((hw(ii,jj),1))
  inf = 10**20
  ans = [inf]*n
  ans[s] = 0
  hh = [(0, s)]
  while hh:
    c, v = heappop(hh)
    if ans[v] < c:
      continue
    for u, t in edge[v]:
      if c+t < ans[u]:
        ans[u] = c+t
        heappush(hh, (c+t, u))
  if ans[g]==10**20:ans[g]=-1
  print(ans[g])
if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()
h,w=map(int,input().split())
ch,cw=map(int,input().split())
ch-=1
cw-=1
stack=[(ch,cw)]
dh,dw=map(int,input().split())
dh-=1
dw-=1
b=[w*[-1]for _ in range(h)]
for i in range(h):
  for j,t in enumerate(input()):
    if t=="#":b[i][j]=10**10
b[ch][cw]=0
dxy=((-1,0),(1,0),(0,-1),(0,1))
for ans in range(10**6):
  for x,y in stack:
    b[x][y]=1
    if x==dh and y==dw:
      print(ans)
      exit()
    for dx,dy in dxy:
      if 0<=x+dx<h and 0<=y+dy<w:
        if b[x+dx][y+dy]==10**10:continue
        if b[x+dx][y+dy]==-1:
          stack.append((x+dx,y+dy))
          b[x+dx][y+dy]=1
  stackk=[]
  for x,y in stack:
    for xx in range(max(0,x-2),min(h,x+3)):
      for yy in range(max(0,y-2),min(w,y+3)):
        if b[xx][yy]==-1:stackk.append((xx,yy))
  stack=stackk
print(-1)
### BUGGY CODE ###

from math import *



class V:
    def __init__(self,si,parent):
        self.si = si
        self.parent = parent
    def isInnovator(self):
        return self.parent is None
    def findInnovator(self):
        re = self
        while True:
            if re.parent is None:
                return re
            re = re.parent


N,K = tuple(map(int,input().split()))
vs = [V(vi,None) for vi in range(N)]

for _ in range(K):
    ui,vi,w = tuple(map(int,input().split()))
    ui-=1
    vi-=1
    u = vs[ui]
    v = vs[vi]
    uInnov = u.findInnovator()
    vInnov = v.findInnovator()
    if uInnov == vInnov:
        continue
    vInnov.parent = uInnov

re = 0
for v in vs:
    if v.isInnovator():
        re += 1

print(re)


### FIXED CODE ###

from math import *



class V:
    def __init__(self,si):
        self.si = si
        self.parent = self
    def isInnovator(self):
        return self.parent == self
    def findInnovator(self):
        re = self
        while True:
            if re.parent == re:
                self.parent = re
                return re
            re = re.parent


N,K = tuple(map(int,input().split()))
vs = [V(vi) for vi in range(N)]

for _ in range(K):
    ui,vi,w = tuple(map(int,input().split()))
    ui-=1
    vi-=1
    u = vs[ui]
    v = vs[vi]
    uInnov = u.findInnovator()
    vInnov = v.findInnovator()
    if uInnov == vInnov:
        continue
    vInnov.parent = uInnov

re = 0
for v in vs:
    if v.isInnovator():
        re += 1

print(re)
### BUGGY CODE ###

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

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x, y))
    

dots = XY[:]

import sys
INT_MAX = sys.maxsize

x_dots = [(x, y) for x, y in dots]
x_dots = sorted(x_dots)
y_dots = [(x, y) for x, y in dots]
y_dots = sorted(y_dots, key=lambda x: x[1])

ans = INT_MAX

for left_i, (left_p_x, _) in enumerate(x_dots):
    for right_i, (right_p_x, _) in enumerate(x_dots[left_i:]):
        for under_i, (_, under_p_y) in enumerate(y_dots):
            for top_i, (_, top_p_y) in enumerate(y_dots[under_i:]):
                counter = 0
                for x, y in dots:
                    if left_p_x <= x and x <= right_p_x and under_p_y <= y and y <= top_p_y:
                        counter += 1
                
                if counter >= K:
                    area = (top_p_y-under_p_y) * (right_p_x-left_p_x)
                    ans = min(ans, area)


print(ans)



### FIXED CODE ###

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

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x, y))
    
dots = XY[:]

import sys
INT_MAX = sys.maxsize

ans = INT_MAX

import itertools
for ((left_x, _), (right_x, _)) in itertools.combinations(dots, 2):
    if left_x > right_x:
        left_x, right_x = right_x, left_x
    for ((_, under_y), (_, top_y)) in itertools.combinations(dots, 2):
        if under_y > top_y:
            under_y, top_y = top_y, under_y
        counter = 0
        for d_x, d_y in dots:
            if  (left_x <= d_x) and (d_x <= right_x) and (under_y <= d_y) and (d_y <= top_y):
                counter += 1
                
        if counter >= K:
            area = (top_y-under_y) * (right_x-left_x)
            if ans > area:
                ans = area
            
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
A = [int(c) for c in input().split()]

numbers = set(A)
numbers = {n: A.count(n) for n in numbers}
numbers = list(numbers.values())
numbers.sort()
if len(numbers) <= K:
    print(0)
else:
    print(sum(numbers[:len(numbers) - K]))


### FIXED CODE ###

from collections import defaultdict

N, K = map(int, input().split())
A = list(map(int, input().split()))
D = defaultdict(lambda: 0)
for a in A:
    D[a] += 1
V = list(D.values())
V.sort(reverse=True)
print(sum(V[K:]))