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

# -*- coding: utf-8 -*-
n = int(input())
vv = list(map(int, input().split()))
d1 = {}
d2 = {}

for i in range(n):
    v = vv[i]
    if i%2==0:
        if v not in d2:
            d2[v] = 0
        d2[v] += 1
    else:
        if v not in d1:
            d1[v] = 0
        d1[v] += 1

res = 10**7
for v1 in d1.keys():
    for v2 in d2.keys():
        if v1==v2:
            continue
        tmp = 0
        for k in d1.keys():
            if k!=v1:
                tmp += d1[k]
        for k in d2.keys():
            if k!=v2:
                tmp += d2[k]
        res = min(res, tmp)
if res==10**7:
    print(n//2)
else:
    print(res)


### FIXED CODE ###

# -*- coding: utf-8 -*-
n = int(input())
vv = list(map(int, input().split()))
d1 = {}
d2 = {}

for i in range(n):
    v = vv[i]
    if i%2==0:
        if v not in d2:
            d2[v] = 0
        d2[v] += 1
    else:
        if v not in d1:
            d1[v] = 0
        d1[v] += 1

dl1 = sorted(list(d1.keys()), reverse=True, key=lambda k:d1[k])
dl2 = sorted(list(d2.keys()), reverse=True, key=lambda k:d2[k])
i1 = 0
i2 = 0

if len(dl1)==1 and len(dl2)==1:
    if dl1[0]==dl2[0]:
        print(n//2)
    else:
        print(0)
    exit()
elif len(dl1)==1:
    print(sum(sorted(d2.values(), reverse=True)[1:]))
    exit()
elif len(dl2)==1:
    print(sum(sorted(d1.values(), reverse=True)[1:]))
    exit()


if dl1[0]!=dl2[0]:
    res = 0
    res += sum(sorted(d1.values(), reverse=True)[1:])
    res += sum(sorted(d2.values(), reverse=True)[1:])
    print(res)
else:
    res1 = 0
    l = sorted(d1.values(), reverse=True)
    res1 += l[0]
    if len(l)>2:
        res1 += sum(l[2:])
    res1 += sum(sorted(d2.values(), reverse=True)[1:])

    res2 = 0
    l = sorted(d2.values(), reverse=True)
    res2 += l[0]
    if len(l)>2:
        res2 += sum(l[2:])
    res2 += sum(sorted(d1.values(), reverse=True)[1:])
    print(min(res1,res2))
### BUGGY CODE ###

from collections import defaultdict,deque
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
G=defaultdict(set)
Comps=[[] for i in range(N)]
for i in range(M):
  a,b,c=map(int,input().split())
  G[(a-1,c-1)].add((b-1,c-1,0))
  G[(b-1,c-1)].add((a-1,c-1,0))
  Comps[a-1].append(c-1)
  Comps[b-1].append(c-1)
for i in range(N):
  for c in Comps[i]:
    G[(i,-1)].add((i,c,1))
    G[(i,c)].add((i,-1,0))
def BFS(x):
  visited=defaultdict(bool)
  stack=deque([(x,-1,0)])
  ans=0
  while stack:
    a,c,m=stack.popleft()
    if visited[(a,c)]:
      continue
    if a==N-1 and c==-1:
      return m
    for i in G[(a,c)]:
      if not visited[(i[0],i[1])]:
        if i[2]==0:
          stack.appendleft((i[0],i[1],m))
        else:
          stack.append((i[0],i[1],m+1))
    visited[(a,c)]=True
  return -1

print(BFS(0))



      
    

### FIXED CODE ###

from collections import defaultdict,deque
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
N,M=map(int,input().split())
if M==0:
  print(-1)
  exit()
G=defaultdict(set)
for i in range(M):
  a,b,c=map(int,input().split())
  G[a+(c<<30)].add(b+(c<<30))
  G[b+(c<<30)].add(a+(c<<30))
  G[a].add(a+(c<<30))
  G[b].add(b+(c<<30))
  G[a+(c<<30)].add(a)
  G[b+(c<<30)].add(b)
def BFS(x):
  d={}
  for k in G.keys():
    d[k]=float("inf")
  stack=deque([(x,0)])
  if x not in d:
    return -1
  while stack:
    s,m=stack.popleft()
    if s==N:
      return m
    if d[s]>m:
      d[s]=m
      if s>=(1<<30):
        for i in G[s]:
          if d[i]>10**30:
            stack.appendleft((i,m))
      else: 
        for i in G[s]:
          if d[i]>10**30:
            stack.append((i,m+1))
  return -1

print(BFS(1))
### BUGGY CODE ###

l,r = map(int,input().split())
minimum = 2019
for i in range(l,r+1):
  for j in range(i+1,r+1):
    if (i*j)%2019 == 0:
      minimum = 0
      break
    else:
      if (i*j)%2019 < minimum:
        minimum = (i*j)%2019
print(minimum)

### FIXED CODE ###

l,r = map(int,input().split())
minimum = 2019
for i in range(l,r+1):
  if minimum == 0:
    break
  for j in range(i+1,r+1):
    if (i*j)%2019 == 0:
      minimum = 0
      break
    else:
      if (i*j)%2019 < minimum:
        minimum = (i*j)%2019
print(minimum)
### BUGGY CODE ###

n=int(input())
s=[int(input()) for i in range(5)]
p=[n, 0, 0, 0, 0, 0]
t=0
if min(s) >= n:
  print(5)
else:
  while p[5] != n:
    for i in range(5):
      if p[4-i] >= s[4-i]:
        p[4-i] -= s[4-i]
        to = s[4-i]
      else:
        to = p[4-i]
        p[4-i] = 0
      p[5-i] += to

    t+=1
  print(t)

### FIXED CODE ###

import math
N = int(input())
t = min([int(input()) for _ in range(5)])
print(math.ceil(N/t)+4)
### BUGGY CODE ###

N, M = list(map(int, input().split(' ')))
result_list = [input().split(' ') for i in range(M)]
AC_total = 0
WA_total = 0
ac_list = []
wa_dict = {}
for p, s in result_list:
    if p not in ac_list:
        if s == 'WA':
            if p in wa_dict:
                wa_dict[p] += 1
            else:
                wa_dict[p] = 1
        else:
            AC_total += 1
            if p in wa_dict:
                WA_total += wa_dict[p]
            ac_list.append(p)
print('{} {}'.format(AC_total, WA_total))

### FIXED CODE ###

N, M = list(map(int, input().split(' ')))
AC_total = 0
WA_total = 0
ac_list = [False] * N
wa_list = [0] * N
for i in range(M):
    p, s = input().split(' ')
    p = int(p) - 1
    if not ac_list[p]:
        if s == 'WA':
            wa_list[p] += 1
        else:
            AC_total += 1
            WA_total += wa_list[p]
            ac_list[p] = True
print('{} {}'.format(AC_total, WA_total))
### BUGGY CODE ###

def expected_value(x):
    x = int(x)
    return (x + 1) / 2


def main():
    N, K = map(int, input().split(' '))
    p_list = list(map(expected_value, input().split(' ')))
    hash_max = 0
    for i in range(0, N - K + 1):
        if sum(p_list[i:i + K]) > hash_max:
            hash_max = sum(p_list[i:i + K])
    print(hash_max)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def expected_value(x):
    x = int(x)
    return (x + 1) / 2


def main():
    N, K = map(int, input().split(' '))
    p_list = list(map(expected_value, input().split(' ')))
    cumulative_list = [0]
    for p in p_list:
        cumulative_list.append(cumulative_list[-1] + p)
    max_len = 0
    for i in range(0, N - K + 1):
        if max_len < cumulative_list[i + K] - cumulative_list[i]: max_len = cumulative_list[i + K] - cumulative_list[i]
    print(max_len)


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

def resolve():
    n = int(input())
    a = tuple(map(int,input().split()))
    cnt_0 = 0
    for i in set(a):
        b = a.count(i)
        cnt_0 += int(b*(b-1)/2)
    for i in a:
        b = a.count(i)
        cnt_1 = b-1
        print(cnt_0-cnt_1)

resolve()

### FIXED CODE ###

import collections
def resolve():
    n = int(input())
    a = tuple(map(int,input().split()))
    A = collections.Counter(a)
    cnt_0 = 0
    for i in A.values():
        cnt_0 += int(i*(i-1)/2)
    for i in a:
        cnt_1 = A[i]-1
        print(cnt_0-cnt_1)
resolve()
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
E =[]
for i in range(1,N+1):
  E.append(int(int(A.index(i))+1))
for i in range(0,N):
  a = int(E[i])
  print(str(a)+' ',end = '')


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
D = [0]*N
for i in range(N):
  a = A[i]
  D[a-1] = i+1
d = str(D[0])
for i in range(1,N):
  d += ' '+str(D[i])
print(d)
### BUGGY CODE ###

N, M = map(int, input().split())
Pref = [[] for i in range(N)]
City = [N+1 for i in range(M)]
for i in range(M):
    p, y = map(int, input().split())
    Pref[p-1].append(y)
    City[i] = (p, y)
for i in range(N):
    Pref[i].sort()
for i in range(M):
    first = City[i][0]
    second = Pref[first-1].index(City[i][1])
    ans = "{0:06d}".format(first) + "{0:06d}".format(second+1)
    print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
Pref = [1 for i in range(N)]
City = []
Ans = ["" for i in range(M)]
for i in range(M):
    p, y = map(int, input().split())
    City.append((y, p-1, i))
City.sort()
for i in range(M):
    Ans[City[i][2]] =  "{0:06d}".format(City[i][1]+1) + "{0:06d}".format(Pref[City[i][1]])
    Pref[City[i][1]] += 1

for i in range(M):
    print(Ans[i])
### BUGGY CODE ###

s=list(input())
n=len(s)
mod=10**9 + 7
dp=[[0]*(13) for i in range(n)]

saki=[[0]*10 for i in range(n)]
for i in range(10):
    saki[0][i]=i
    for j in range(n-1):
        saki[j+1][i]=saki[j][i]*10%13

if s[n-1]=='?':
    for i in range(10):
        dp[0][i]=1
else:
    dp[0][int(s[n-1])]=1

for i in range(n-1):
    if s[n-2-i]=='?':
        for j in range(13):
            if dp[i][j]>0:
                for k in range(10):
                    dp[i+1][(j+saki[i+1][k])%13]+=dp[i][j]%mod
    else:
        for j in range(13):
            if dp[i][j]>0:
                dp[i+1][(j+saki[i+1][int(s[n-2-i])])%13]+=dp[i][j]%mod
print(dp[n-1][5]%mod)

### FIXED CODE ###

mod=10**9+7
r=[[(j-k)*9%13 for j in range(10)] for k in range(13)]
dp=[1]+[0]*12
for c in input():
  dp = [sum(dp[j] for j in k)%mod for k in r] if c>'9' else [dp[(int(c)-k)*9%13] for k in range(13)]
print(dp[5])
### BUGGY CODE ###

import numpy as np 
import sys 

readline = sys.stdin.readline

N, K = map(int, readline().split())
A = list(map(int, readline().split()))

# 愚直にやると計算量O(K)でTLEになる
# 同じ街にいったら操作打ち切りで配列を完結させる

# Teleport順の配列を作る
teleport = [1]
next_town = 1
for i in range(K):
    next_town = A[next_town - 1]
    if next_town in teleport:
        dupulicate_town = next_town
        dupulicate_index = teleport.index(dupulicate_town)
        dupulicate_list = teleport[dupulicate_index:]
        break
    else:
        teleport.append(next_town)


if len(teleport) - 1 == K:
    print(teleport[-1])
else: # ループに入る場合
    consumption = len(teleport) - 1
    roop_num = K - consumption
    roop_index = roop_num % len(dupulicate_list)
    if roop_index == 0:
        print(dupulicate_list[-1])
    else:
        print(dupulicate_list[roop_index - 1])



### FIXED CODE ###

import numpy as np 
import sys 

readline = sys.stdin.readline

N, K = map(int, readline().split())
A = list(map(int, readline().split()))

# 愚直にやると計算量O(K)でTLEになる
# 同じ街にいったら操作打ち切りで配列を完結させる

# Teleport順の配列を作る
teleport = {1: True}
next_town = 1
roop_exist = False
for i in range(K):
    next_town = A[next_town - 1] # next_townがintで与えられる
    try: # 辞書を使用してO[1]で判定する
        teleport[next_town]
        dupulicate_town = next_town
        # 辞書をリストに変換
        teleport = list(teleport.keys())
        dupulicate_index = teleport.index(dupulicate_town)
        dupulicate_list = teleport[dupulicate_index:]
        roop_exist = True
        break
    except KeyError:
        teleport[next_town] = True


# 最後の処理の前にリストに変換してしまう
if not roop_exist:
    teleport = list(teleport.keys())

if len(teleport) - 1 == K:
    print(teleport[-1])
else: # ループに入る場合
    consumption = len(teleport) - 1
    roop_num = K - consumption
    roop_index = roop_num % len(dupulicate_list)
    if roop_index == 0:
        print(dupulicate_list[-1])
    else:
        print(dupulicate_list[roop_index - 1])
### BUGGY CODE ###

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

vals = {}
for A in As:
    if A in vals:
        vals[A] += 1
    else:
        vals[A] = 1

for k in range(len(As)):
    Ak = As[k]
    total = 0
    for val in vals:
        if val == Ak:
            total += (vals[val] - 1)*(vals[val] - 2) // 2
        else:
            total += vals[val]*(vals[val]-1) // 2
    print(total)


### FIXED CODE ###

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

vals = {}
for A in As:
    if A in vals:
        vals[A] += 1
    else:
        vals[A] = 1

#print(vals)

choose2 = {}
for val in vals:
    num = vals[val]
    choose2[val] = num*(num - 1) // 2

#print(choose2)

total = 0
for k in choose2:
    total += choose2[k]
#print("total: " + str(total))

for Ak in As:
    print(total - (vals[Ak] - 1))
### BUGGY CODE ###

n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
print(max(a[1:]))
for j in range(1,n-1):
  b=a[:j]+a[j+1:]
  print(max(b))
print(max(a[:n]))

### FIXED CODE ###

n=int(input())
a=[]
for i in range(n):
  a.append(int(input()))
m=max(a)
x=[i for i, x in enumerate(a) if x == m]
if(len(x)>=2):
  for i in range(n):
    print(m)
else:
  a.remove(m)
  M=max(a)
  for i in range(n):
    if(i==x[0]):
      print(M)
    else:
      print(m)
### BUGGY CODE ###

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

from itertools import accumulate

ans=[0]*(N+1)
for _ in range(K):
    for i,a in enumerate(A):
        ans[max(0,i-a)]+=1
        ans[min(i+a+1,N)]-=1
    A = list(accumulate(ans))[:-1]
    ans=[0]*(N+1)
    if all(i == N-1 for i in A):
        break
print(*A)

### FIXED CODE ###

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

from itertools import accumulate

if N-min(A) <= K:
    print(*[N]*N)
    exit()
    
ans=[0]*(N+1)
for _ in range(K):
    for i,a in enumerate(A):
        ans[max(0,i-a)]+=1
        ans[min(i+a+1,N)]-=1
    A = list(accumulate(ans))[:-1]
    ans=[0]*(N+1)
    if all(i == N for i in A):
        break
print(*A)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from itertools import product
from heapq import heappop, heappush
import numpy as np


def small_dp(N,k,X):
    if k == 0:
        return N
    if k == 1:
        return X[0][1]*(N//X[0][0]) + N%X[0][0]
    if k == 2:
        c = 0
        for i in range(N//X[0][0]+1):
            j = (N-i*X[0][0])//X[1][0]
            c = max(X[0][1]*i + X[1][1]*j + (N-i*X[0][0])%X[1][0], c)
        return c
    if k == 3:
        dp = np.zeros((3, N+1), dtype=int)
        dp[0] = np.max((X[0][1]*np.repeat(np.arange(N//X[0][0]+1), X[0][0])[:N+1]+np.tile(np.arange(X[0][0]),N//X[0][0]+1)[:N+1], np.arange(N+1)), axis=0)
        for i,w in product(range(1,3), range(1,N+1)):
            dp[i,w] = np.max((dp[i-1,w::-1] + X[i][1]*np.repeat(np.arange(w//X[i][0]+1), X[i][0])[:w+1]))
        N = dp[-1][N]
        return N

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    for C in ((A,B), (B,A)):
        *X, = filter(lambda c: int.__sub__(*c)<0, zip(*C))
        N = small_dp(N, len(X), X)
    res = N

    return str(res)

if __name__ == '__main__':
    print(solve())

### FIXED CODE ###

# -*- coding: utf-8 -*-
from itertools import product
from heapq import heappop, heappush

def small_dp(N,A,B):
    *X, = filter(lambda c: int.__sub__(*c)<0, zip(A,B))
    k = len(X)
    if k == 0:
        return N
    if k == 1:
        return X[0][1]*(N//X[0][0]) + N%X[0][0]
    if k == 2:
        c = 0
        for i in range(N//X[0][0]+1):
            j = (N-i*X[0][0])//X[1][0]
            c = max(X[0][1]*i + X[1][1]*j + (N-i*X[0][0])%X[1][0], c)
        return c
    if k == 3:
        if (N//X[1][0]+1)*(N//X[0][0]+1) <= 10**6 :
            return max(X[0][1]*i + max(X[1][1]*j + X[2][1]*((N-i*X[0][0]-j*X[1][0])//X[2][0]) + ((N-i*X[0][0]-j*X[1][0])%X[2][0]) for j in range((N-i*X[0][0])//X[1][0]+1)) for i in range(N//X[0][0]+1))
        else:
            import numpy as np
            dp = np.zeros(N+1, dtype=int)
            for w in range(1,N+1):
                dp[w] = max(dp[w-X[i][0]]+X[i][1] if w>=X[i][0] else w for i in range(k))
            N = dp[-1]
            return N

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    res = small_dp(small_dp(N, A, B), B, A)

    return str(res)

if __name__ == '__main__':
    print(solve())
### BUGGY CODE ###

from itertools import permutations
n, m, r = map(int, input().split())
R = list(map(lambda x: int(x)-1, input().split()))
INF = 10**18
dist = [[INF]*n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][k]+dist[k][j], dist[i][j])

ans = INF
for subset in permutations(R):
    d = 0
    for v, v2 in zip(subset, subset[1:]):
        d += dist[v][v2]
    if d < ans:
        ans = d
print(ans)


### FIXED CODE ###

import heapq
from itertools import permutations
n, m, r = map(int, input().split())
R = list(map(lambda x: int(x)-1, input().split()))
edges = [[]for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append((c, b))
    edges[b].append((c, a))


def dijkstra(init_v):
    next_v = [(0, init_v)]
    INF = 10**18
    dist = [INF]*n
    dist[init_v] = 0
    while next_v:
        d, v = heapq.heappop(next_v)
        if dist[v] < d:
            continue
        for d, v2 in edges[v]:
            if dist[v2] <= dist[v]+d:
                continue
            dist[v2] = dist[v]+d
            heapq.heappush(next_v, (dist[v2], v2))
    return dist


dists = []
for x in R:
    dist = dijkstra(x)
    dists.append(dist)

INF = 10**18
ans = INF
for subset in permutations(range(r)):
    d = 0
    for v, v2 in zip(subset, subset[1:]):
        d += dists[v][R[v2]]
    if d < ans:
        ans = d

print(ans)
### BUGGY CODE ###

V,E,r = map(int, input().split())

#edges = [[float('inf') for _ in range(V)] for _ in range(V)]
edges = []

for _ in range(E):
    tmp = [int(x) for x in input().split()]
    #edges[s][t] = d
    edges.append(tmp)

d = [float('inf') for _ in range(V)]
d[r] = 0

for _ in range(V-1):
    for x in edges:
        d[x[1]] = min(d[x[1]], d[x[0]] + x[2])

for x in d:
    if x == float('inf'):
        print('INF')
    else:
        print(x)


### FIXED CODE ###


#Bellman-FordだとTLEになる(はず)
V,E,r = map(int, input().split())
edges = []
for _ in range(E):
    tmp = [int(x) for x in input().split()]
    edges.append(tmp)

d = [float('inf') for _ in range(V)]
d[r] = 0

for _ in range(V-1):
    count = 0
    for x in edges:
        s,t,w = x
        if d[t] > d[s] + w:
            count += 1
            d[t] = d[s] + w
    if count == 0:
        break

for x in d:
    if x == float('inf'):
        print('INF')
    else:
        print(x)
### BUGGY CODE ###

n = int(input())
for m in range(n):
    count = 0
    for i in range(n):
        x = i + 1
        if x * x >= n:
            break
        for j in range(n):
            y = j + 1
            if x * x + y * y >= n:
                break
            for k in range(n):
                z = k + 1
                if x * x + y * y + z * z + x * y + y * z + z * x > m+1:
                    break
                elif x * x + y * y + z * z + x * y + y * z + z * x == m+1:
                    count += 1
                    break
    print(count)



### FIXED CODE ###

n = int(input())
ans = [0] * n
count = 0
for i in range(n):
    x = i + 1
    xx = x * x
    if  x * x >= n:
        break
    for j in range(n):
        y = j + 1
        yy = y * y
        if xx + yy + x * y>= n:
            break
        for k in range(n):
            z = k + 1
            zz = z * z
            kotae = xx + yy + zz + x * y + y * z + z * x
            if kotae > n:
                break
            ans[kotae-1] += 1
for i in range(n):
    print(ans[i])
### BUGGY CODE ###

from collections import defaultdict
n = int(input())

d = defaultdict(int)
for _ in range(n):
    s = input()
    d[s] += 1

max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]
#print(max_k_list)
# ['a', 'd']

max_k_list.sort()
for v in max_k_list:
    print(v)

### FIXED CODE ###

n = int(input())
d = dict()

maxi = 0
for _ in range(n):
    s = input()
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
    maxi = max(maxi, d[s])
    
max_k_list = [kv[0] for kv in d.items() if kv[1] == maxi]
#print(max_k_list)
# ['a', 'd']

max_k_list.sort()
for v in max_k_list:
    print(v)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(N-1):
    for j in range(i+1,N):
        if j-i==A[i]+A[j]:
            ans+=1
print(ans)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
ans=0
t=dict()
for i in range(N):
    if A[i]-i in t:
        ans+=t[A[i]-i]
    t.setdefault(-A[i]-i,0)
    t[-A[i]-i]+=1
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10**10 for _ in range(n)]
dp[0] = 0

for i in range(1, n):
    mincost = 10 ** 10
    for j in range(1, min(i, k)+1):
        cost = dp[i-j] + abs(h[i] - h[i-j])
        if cost < mincost:
            mincost = cost
    
    dp[i] = mincost

print(dp[-1])


### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10**10 for _ in range(n)]
dp[0] = 0

for i in range(1, n):
    mincost = 10 ** 10
    for j in range(1, min(i, k)+1):
        cost = dp[i-j] + abs(h[i] - h[i-j])
        if cost < mincost:
            mincost = cost
    
    dp[i] = mincost

print(dp[-1])
### BUGGY CODE ###

import sys
n = int(sys.stdin.readline().strip())
list = []
ans = 0
for x in range(n):
  list.append(sorted(''.join(sys.stdin.readline().strip())))
for i in range(len(list)-1):
  for j in range(i+1, n):
    if list[i] == list[j]:
      ans +=1
print(ans)

### FIXED CODE ###

import sys
n = int(sys.stdin.readline().strip())
list = [''.join(sorted(sys.stdin.readline().strip())) for i in range(n)]
d = {}
ans = 0
for x in list:
  if x in d:
    ans += d[x]
    d[x] += 1
  else:
    d[x] = 1
print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
connections = [[] for _ in range(N)]
for a, b in AB:
    connections[a - 1].append(b - 1)
    connections[b - 1].append(a - 1)
    
markers = [-1] * N
    
queue = [0]
steps = [-1] * N
steps[0] = 0
while len(queue) >= 1:
    room = queue.pop(0)
    for r in connections[room]:
        if steps[r] >= 0:
            continue
        queue.append(r)
        steps[r] = steps[room] + 1
        markers[r] = str(room + 1)
    
print("Yes")
print("\n".join(markers[1:]))

### FIXED CODE ###

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
connections = [[] for _ in range(N)]
for a, b in AB:
    connections[a - 1].append(b - 1)
    connections[b - 1].append(a - 1)

markers = [-1] * N

queue = [0]
steps = [-1] * N
steps[0] = 0
while len(queue) >= 1:
    room = queue.pop(0)
    for r in connections[room]:
        if steps[r] >= 0:
            continue
        queue.append(r)
        steps[r] = steps[room] + 1
        markers[r] = str(room + 1)

print("Yes")
print("\n".join(markers[1:]))
### BUGGY CODE ###

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

## 種類数の求め方
# 1. A内の要素を取り出して、それがA内に存在するとき：種類＋１
# 2. その要素を重複数だけAから削除してループ

kinds = 0
A = sorted(A)
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')
elif kinds > K:
    duplicatedList = sorted(duplicatedList)
    tmp = 0
    for i in range(kinds-K):
        tmp += duplicatedList[i]
    print(tmp)

### FIXED CODE ###

n,k=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)