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

from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    S = list(_ for _ in input())
    S = S[::-1]    
    S_num = 0
    temp_ans_0 = ''
    temp_ans_1 = ''
    num_temp_ans_0 = 0
    num_temp_ans_1 = 0
    for i in range(len(S)):
        if(i%2 ==0):
            temp_ans_0 += '0'
            temp_ans_1 += '1'
        else:
            temp_ans_0 += '1'
            temp_ans_1 += '0'
    for i in range(len(S)):
        S_num += int(S[i]) * 2**i
        num_temp_ans_0 += int(temp_ans_0[i]) * 2**i
        num_temp_ans_1 += int(temp_ans_1[i]) * 2**i
    c0 = bin(S_num ^ num_temp_ans_0).count('1')
    c1 = bin(S_num ^ num_temp_ans_1).count('1')
    
    print(min(c0,c1))
    
if __name__ == '__main__':
    main()


### FIXED CODE ###

from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    S = list(_ for _ in input())
    S = S[::-1]    
    S_num = 0
    temp_ans_0 = '0b'
    temp_ans_1 = '0b'
    num_temp_ans_0 = 0
    num_temp_ans_1 = 0
    for i in range(len(S)):
        if(i%2 ==0):
            temp_ans_0 += '0'
            temp_ans_1 += '1'
        else:
            temp_ans_0 += '1'
            temp_ans_1 += '0'
    # i = 0
    # for s in S:
    #     S_num += int(s) * 2**i
    #     if(i%2 ==0):
    #         num_temp_ans_0 += 0 * 2**i
    #         num_temp_ans_1 += 1 * 2**i
    #     else:
    #         num_temp_ans_0 += 1 * 2**i
    #         num_temp_ans_1 += 0 * 2**i
    #     i +=1
    S_str ='0b'+''.join(S)
    S_num = int(S_str,0)
    num_temp_ans_0 = int(temp_ans_0,0)
    num_temp_ans_1 = int(temp_ans_1,0) 
    c0 = bin(S_num ^ num_temp_ans_0).count('1')
    c1 = bin(S_num ^ num_temp_ans_1).count('1')
    
    print(min(c0,c1))
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

import bisect

n = int(input())
l = sorted(map(int, input().split()))
ll = [l[:i] for i in range(n)]

ans = 0
for i in range(2,n)[::-1]:
    for j in range(1,i)[::-1]:
        a = bisect.bisect(ll[j], l[i] + l[j])
        b = bisect.bisect(ll[j], l[i] - l[j])
#         print(l[i] + l[j], l[i] , l[j], a, ll[j], l[i] - l[j], l[i] - l[j] < ll[i][a])
        if l[i] - l[j] < ll[i][a]:
            ans += a -b
print(ans)


### FIXED CODE ###

import bisect

n = int(input())
l = sorted(map(int, input().split()))

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        ans += bisect.bisect_left(l,l[j]+l[i])-j-1
print(ans)
### BUGGY CODE ###

# C - Prison
import numpy as np

n, m = map(int, input().split())
a = np.ones(n, dtype=np.int64)

for i in range(m):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    b = np.zeros(n, dtype=np.int64)
    b[l:r+1] = 1
    a = a&b

print(sum(a))

### FIXED CODE ###

# C - Prison

n, m = map(int, input().split())

ansl = 1
ansr = n

for i in range(m):
    l, r = map(int, input().split())
    if l>ansl:
        ansl = l
    if r<ansr:
        ansr = r

print(max(ansr-ansl+1,0))
### BUGGY CODE ###

import math
K,S = map(int, input().split())
n = 0
up = math.floor(K)
for i in range(up+1):
    for j in range(i,up+1):
        for k in range(j,up+1):
            if i==j and j==k:
                same=1
            elif (i==j and j!=k)or(j==k and i!=j) or(k ==i and i!=j):
                same =3
            else:
                same =6
            if i+j+k ==S:
                n=n+same
            else:
                n =n

print(n)


### FIXED CODE ###

import math
import sys
input = sys.stdin.readline


K,S = map(int, input().split())
n = 0
up = math.floor(K)
for i in range(0,K+1):
    for j in range(0, K+1):
        if(0<= S-i-j <=K):
            n +=1
        else:
                n =n

print(n)
### BUGGY CODE ###

from sys import stdin
N,M=[int(x) for x in stdin.readline().rstrip().split()]
A=[int(x) for x in stdin.readline().rstrip().split()]
data=[]
for i in range(M):
    data.append([int(x) for x in stdin.readline().rstrip().split()])
for k in data:
    for j in range(k[0]):
        A.append(k[1])


ans = sum(sorted(A)[::-1][:N])
print(ans)

### FIXED CODE ###

from sys import stdin
N,M=[int(x) for x in stdin.readline().rstrip().split()]
A=[(int(x),1) for x in stdin.readline().rstrip().split()]
data=[]
for i in range(M):
    r,q=[int(x) for x in stdin.readline().rstrip().split()]
    A.append((q,r))
ans=0
cnt=0
for j in reversed(sorted(A)):
    cnt+=j[1]
    ans+=(j[0]*j[1])
    if cnt > N:
        ans = ans-(j[0]*(cnt-N))
        break
print(ans)
### BUGGY CODE ###

# def check(place, List):
#     flag = 0
#     for i in range(len(List)):
#         distance = abs(i - place)
#         if distance > len(List):
#             distance = len(List) - distance
#         if distance < List[i]:
#             flag = 1
#     return flag
# def getDistance(Now,Next,C):
#     dst = abs(Next - Now)
#     if(dst > C/2):
#         dst = C - dst
#     return dst
#
#
#
# N, C = map(int, input().split())
# # Counter = [0 for i in range(C)]
# X_V = []
# #V = []
# for i in range(N):
#      #x,v = map(int, input().split()))
#      X_V.append(tuple(map(int, input().split())))
# nowPlace = 0
# while(1):
#     getCal = list(map(lambda x:x[1] - getDistance(nowPlace, x[0], C), X_V))
#     nextPlace = X_V[getCal.index(max(getCal))][0]

N, C = map(int, input().split())
X = [0]
V = [0]
for i in range(N):
    x,v = map(int, input().split())
    X.append(x)
    V.append(v)
#print(-X[1])
inv_X = [C-X[i] for i in range(N+1)][::-1]
inv_X.pop()
inv_X.insert(0,0)
#累積和の計算
right = [0]
left = [0]
#print(V)
for i in range(1,N+1):
    right.append(right[i-1]+V[i])
    left.append(left[i-1]+V[N+1-i])
#print('right:', right, 'left:', left)
Rtemp_max = 0
#right -> left pattern
for i in range(N+1):
    for j in range(N+1-i):
        OA = X[i]
        OB = inv_X[j]
        RightMovingDistance = 2 * OA + OB
        getCal = right[i] + left[j] - RightMovingDistance
        #print(i, j,right[i], left[j], RightMovingDistance)
        #print('Right_i:',i,'Right_getCal:',getCal)
        Rtemp_max = max(Rtemp_max, getCal)
#left -> right pattern
Ltemp_max = 0
for i in range(N+1):
    for j in range(N+1-i):
        OA = X[i]
        OB = inv_X[j]
        LeftMovingDistance = OA + 2 * OB
        getCal = right[i] + left[j] - LeftMovingDistance
        #print(i, j,right[i], left[j], LeftMovingDistance)
        #print('Right_i:',i,'Right_getCal:',getCal)
        Ltemp_max = max(Ltemp_max, getCal)
ans = max(Rtemp_max, Ltemp_max)
print(ans)


### FIXED CODE ###

import numpy as np
N, C = map(int, input().split())
X,V = [],[]
for _ in range(N):
    x,v = map(int, input().split())
    X.append(x)
    V.append(v)

r1,r2,l1,l2 = [0],[0],[0],[0]
sum = 0
#原点から時計回りに行ってくる、行って戻ってくるパターン。前の奴と比較して、それより小さかったら無視
for i in range(N):
    sum += V[i]
    #print(r1, r2)
    r1.append(max(r1[i], sum-X[i]))
    r2.append(max(r2[i], sum-2*X[i]))
sum = 0
for i in range(N,0,-1):
    #print('hogehoge',i,V[i-1],X[i-1])
    sum += V[i-1]
    #print(l1, l2)
    l1.append(max(l1[-1], sum-(C-X[i-1])))
    l2.append(max(l2[-1], sum-2*(C-X[i-1])))
#print(l1, l2)
a = max(np.array(r1) + np.array(l2)[::-1])
b = max(np.array(r2) + np.array(l1)[::-1])
print(max(a,b))
### BUGGY CODE ###

X, Y, Z, K = [int(x) for x in input().split()]
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)
ABC = []
for a in range(len(A)):
    if a+1 > K:
        continue
    for b in range(len(B)):
        if (a+1)*(b+1) > K:
            continue
        for c in range(len(C)):
            if (a+1)*(b+1)*(c+1) > K:
                continue
            ABC.append(A[a] + B[b] + C[c])
ABC = sorted(ABC, reverse=True)
for i in range(K):
    print(ABC[i])

### FIXED CODE ###

X, Y, Z, K = [int(x) for x in input().split()]
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)
ABC = []
for a in range(len(A)):
    if a+1 > K:
        break
    for b in range(len(B)):
        if b+1 > K:
            break
        elif (a+1)*(b+1) > K:
            break
        for c in range(len(C)):
            if c+1 > K:
                break
            elif (a+1)*(c+1) > K:
                break
            elif (b+1)*(c+1) > K:
                break
            elif (a+1)*(b+1)*(c+1) > K:
                break
            ABC.append(A[a] + B[b] + C[c])
ABC = sorted(ABC, reverse=True)
for i in range(K):
    print(ABC[i])
### BUGGY CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k=int(input())

cnt=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            cnt += gcd(i,j,l)
print(cnt)

### FIXED CODE ###

import math
from functools import reduce
import itertools

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k=int(input())

l=[]
for i in range(1,k+1):
    l.append(i)

c_list = list(itertools.combinations_with_replacement(l,3))

cnt=0
for l in c_list:
    a = l[0]
    b = l[1]
    c = l[2]
    if a == b == c:
        d = 1
    elif a == b or b == c or c == a:
        d = 3
    else:
        d = 6
    cnt += gcd(a,b,c)*d
print(cnt)
### BUGGY CODE ###

def main():
	import sys
	sys.setrecursionlimit(10**7)
	mod=998244353
	n,s=map(int,input().split())
	a=list(map(int,input().split()))
	from functools import lru_cache
	@lru_cache(maxsize=None)
	def dfs(x,y):
		if x==0:
			if y==0:
				return 1
			else:
				return 0
		r=dfs(x-1,y)*2%mod
		if x>0:
			if y-a[x-1]>=0:
				r+=dfs(x-1,y-a[x-1])
		r%=mod
		return r
	print(dfs(n,s))
main()

### FIXED CODE ###

mod=998244353
n,s=map(int,input().split())
a=list(map(int,input().split()))
dp=[[0]*(s+1) for _ in range(n+1)]
dp[0][0]=1
for i in range(n):
	for j in range(s+1):
		dp[i+1][j]+=2*dp[i][j]
		dp[i+1][j]%=mod
		if j+a[i]<=s:
			dp[i+1][j+a[i]]+=dp[i][j]
			dp[i+1][j+a[i]]%=mod
print(dp[n][s])
### BUGGY CODE ###


import itertools
import math
import copy

N, A, B, C = map(int, input().rstrip().split())

pattern = [list(itertools.combinations(range(x), 3)) for x in range(3, N+1)]

def stretch_shortening(sticks, A, B, C):
    #sticks = sorted(sticks)
    min_cost = 1e10
    
    for i1, i2, i3 in pattern[len(sticks) - 3]:
        cost = abs(sticks[i1] - A) + abs(sticks[i2] - B) + abs(sticks[i3] - C)
        if min_cost > cost:
            min_cost = cost
    return min_cost

def connect(sticks, A, B, C):
    
    min_cost = stretch_shortening(sticks, A, B, C) + (N - len(sticks)) * 10
    
    if len(sticks) <= 3:
        return min_cost
    
    for i1, i2 in itertools.combinations(range(len(sticks)), 2):
        if sticks[i1] + sticks[i2] > sticks[-1] and sticks[-1] > C:
            continue
        copied_sticks = copy.copy(sticks)
        copied_sticks[i1] += copied_sticks[i2]
        copied_sticks.pop(i2)
        copied_sticks = sorted(copied_sticks)
        min_cost_connect = connect(copied_sticks, A, B, C)
        if min_cost_connect < min_cost:
            min_cost = min_cost_connect
    
    return min_cost

sticks = []
for _ in range(N):
    sticks.append(int(input()))
sticks = sorted(sticks)

min_cost = connect(sticks, C, B, A)
#min_cost = stretch_shortening(sticks, A, B, C)
#print(pattern)

print(min_cost)



### FIXED CODE ###


import itertools
import math
import copy

N, A, B, C = map(int, input().rstrip().split())

pattern = [list(itertools.combinations(range(x), 3)) for x in range(3, N+1)]

def stretch_shortening(sticks, A, B, C):
    min_cost = 1e10
    
    for i1, i2, i3 in pattern[len(sticks) - 3]:
        cost = abs(sticks[i1] - A) + abs(sticks[i2] - B) + abs(sticks[i3] - C)
        if min_cost > cost:
            min_cost = cost
    return min_cost

temp_set = set()
def connect(sticks, A, B, C):
    
    min_cost = stretch_shortening(sticks, A, B, C) + (N - len(sticks)) * 10
    
    if len(sticks) <= 3:
        return min_cost
    
    for i1, i2 in itertools.combinations(range(len(sticks)), 2):
        if sticks[i1] + sticks[i2] > sticks[-1] and sticks[-1] >= C:
            continue
        if sticks[i1] <= 10 or sticks[i2] <= 10:
            continue
        
        copied_sticks = copy.copy(sticks)
        copied_sticks[i1] += copied_sticks[i2]
        copied_sticks.pop(i2)
        copied_sticks = sorted(copied_sticks)
        
        len_set = len(temp_set)
        temp_set.add(''.join(["{:05d}".format(x) for x in copied_sticks]))
        if len_set == len(temp_set):
            continue
        
        min_cost_connect = connect(copied_sticks, A, B, C)

        if min_cost_connect < min_cost:
            min_cost = min_cost_connect
    
    return min_cost

sticks = []
for _ in range(N):
    sticks.append(int(input()))
sticks = sorted(sticks)

min_cost = connect(sticks, C, B, A) #, 1e10)
#min_cost = stretch_shortening(sticks, A, B, C)
#print(pattern)

print(min_cost)
### BUGGY CODE ###

num=raw_input()
tmp=map(int, raw_input().split(" "))
tmp_count=[]
for i in set(tmp):
    tmp_count.append(tmp.count(i))

#print set(tmp),tmp_count
out=tmp[:]
for i,j in zip(set(tmp),tmp_count):
    for k in range(j):
        out.append(i-1)
        out.append(i+1)

#print set(out)

sub=[]
for i in set(out):
    sub.append(out.count(i))
#print sub
print max(sub)


### FIXED CODE ###

import numpy as np
from collections import Counter
#from statistics import mode
num=raw_input()
tmp=map(int, raw_input().split(" "))
#tmp_count=[]
#for i in set(tmp):
#    tmp_count.append(tmp.count(i))

#print set(tmp),tmp_count
#out=tmp[:]
#for i,j in zip(set(tmp),tmp_count):

#out=tmp[:]
#for i in tmp:
#    out.append(i-1)
#    out.append(i+1)

arr1=np.array(tmp)
arr2=np.array(tmp)+1
arr3=np.array(tmp)-1
arr=np.r_[arr1, arr2,arr3]
#print arr
data = Counter(list(arr))
print data.most_common(1)[0][1]
#print mode(list(arr))
#print np.median(arr)
"""
sub=[]
for i in set(arr):
    sub.append(list(arr).count(i))
#print sub
print max(sub)
"""
### BUGGY CODE ###

a,b,m=map(int, input().split())
rei=list(map(int, input().split())) 
den=list(map(int, input().split())) 
cou = [0] * m
ans = []
for i in range(m):
	cou[i]=list(map(int, input().split()))
	ans.append(rei[cou[i][0]-1]+den[cou[i][1]-1]-cou[i][2])
[[ans.append(rei[j]+den[i]) for i in range(b)] for j in range(a)]
print(min(ans))

### FIXED CODE ###

m=list(map(int, input().split()))
rei=list(map(int, input().split())) 
den=list(map(int, input().split())) 
cou = [0] * m[2]
ans = []
for i in range(m[2]):
	cou[i]=list(map(int, input().split()))
	ans.append(rei[cou[i][0]-1]+den[cou[i][1]-1]-cou[i][2])

ans.append(min(rei)+min(den))
print(min(ans))
### BUGGY CODE ###

import sys, re
import math
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
 
# 整数リストを連結表示    print(''.join(map(str, list)))
 
# -*- coding: utf-8 -*-
 
k = INT()
sum = 0

for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sum += math.gcd(math.gcd(a, b), c)

print(sum)

### FIXED CODE ###

import sys, re
import math
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
 
# 整数リストを連結表示    print(''.join(map(str, list)))
 
# -*- coding: utf-8 -*-
 
k = INT()
sum = 0


def A(value, sum):
    if value == 0:
        print(sum)
    else:
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                sum += math.gcd(math.gcd(value, b), c)
        A(value - 1, sum)

A(k, 0)
### BUGGY CODE ###

S = input()
Q = int(input())

rev = False
for i in range(Q):
  query = list(input())
  if query[0] == '1':
    rev = not rev
  else:
    c = query[4]
    if query[2] == '1' and not rev or (rev and query[2] == '2'):
      S = c + S
    else:
      S = S + c

if rev:
  print(S[::-1])
else:
  print(S)

### FIXED CODE ###

from collections import deque
S = list(input())
Q = int(input())

S = deque(S)

rev = False
for i in range(Q):
  query = list(input())
  if query[0] == '1':
    rev = not rev
  else:
    c = query[4]
    if query[2] == '1' and not rev or (rev and query[2] == '2'):
      S.appendleft(c)
    else:
      S.append(c)
      
if rev:
  S.reverse()


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

from functools import lru_cache

n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

@lru_cache(maxsize=1000000)
def dp(i, a):
    if i == 0:
        return action[0][a]
    else:
        return max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]

import sys
sys.setrecursionlimit(1000000)
print(max([dp(n-1,a) for a in range(3)]))


### FIXED CODE ###

n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

memo = []
for i in range(n):
    memo.append([-1]*3)

def dp(i, a):
    if i == 0:
        return action[0][a]
    elif memo[i][a] != -1:
        return memo[i][a]
    else:
        memo[i][a] = max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]
        return memo[i][a]

import sys
sys.setrecursionlimit(1000000)
print(max([dp(n-1,a) for a in range(3)]))
### BUGGY CODE ###

n = int(input())
abc = [list(map(int, input().split())) for _ in range(n - 1)]
Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(Q)]

from heapq import heappop, heappush

def main():
    cost = dict()
    for a, b, c in abc:
        if a-1 in cost:
            cost[a-1] = cost[a-1] + [(b-1, c)]
        else:
            cost[a-1] = [(b-1, c)]
        if b-1 in cost:
            cost[b-1] = cost[b-1] + [(a-1, c)]
        else:
            cost[b-1] = [(a-1, c)]

    start = K - 1
    d = [float('inf') for i in range(n)] # 最短距離
    d[start] = 0

    q = [] # min-heap, (距離, 頂点)
    heappush(q, (d[start], start))
    while q:
        du, u = heappop(q) # 最短距離とその頂点
        if d[u] < du:
            continue
        if u in cost:
            for v, weight in cost[u]:
                alt = du + weight
                if d[v] > alt:
                    d[v] = alt
                    heappush(q, (alt, v))

    for goal1, goal2 in xy:
        print(d[goal1 - 1] + d[goal2 - 1])

if __name__ == '__main__':
    main()


### FIXED CODE ###

n = int(input())
abc = [list(map(int, input().split())) for _ in range(n - 1)]
Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(Q)]

from heapq import heappop, heappush

def main():
    cost = [[] for _ in range(n)]
    for i in range(n - 1):
        a = abc[i][0] - 1
        b = abc[i][1] - 1
        c = abc[i][2]
        cost[a].append((b, c))
        cost[b].append((a, c))
    # print(cost)

    start = K - 1
    d = [float('inf') for i in range(n)] # 最短距離
    d[start] = 0

    q = [] # min-heap, (距離, 頂点)
    heappush(q, (d[start], start))
    while q:
        du, u = heappop(q) # 最短距離とその頂点
        if d[u] < du:
            continue
        for v, weight in cost[u]:
            alt = du + weight
            if d[v] > alt:
                d[v] = alt
                heappush(q, (alt, v))

    for goal1, goal2 in xy:
        print(d[goal1 - 1] + d[goal2 - 1])

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

N=input()
A=[ input()  for _ in range(N) ]

L=[]
for i,a in enumerate(A):
	if i==0:
		L.append(a)
	else:
		L.append( max(L[-1], a) )

R=[]
for i,a in enumerate(A[::-1]):
	if i==0:
		R.append(a)
	else:
		R.append( max(R[-1], a) )

R=R[::-1]


for i in range(N):
	if i==0:
		print R[i+1]
	elif i==N-1:
		print L[i-1]
	else:
		print max( R[i+1], L[i-1])


### FIXED CODE ###

import sys
N=input()
A=[ int(sys.stdin.readline().strip())  for _ in range(N) ]

L=[]
for i,a in enumerate(A):
	if i==0:
		L.append(a)
	else:
		L.append( max(L[-1], a) )

R=[]
for i,a in enumerate(A[::-1]):
	if i==0:
		R.append(a)
	else:
		R.append( max(R[-1], a) )

R=R[::-1]


for i in range(N):
	if i==0:
		print R[i+1]
	elif i==N-1:
		print L[i-1]
	else:
		print max( R[i+1], L[i-1])
### BUGGY CODE ###

n,k = map(int, input().split())
p = [i for i in map(int, input().split())]

cnt=0
sum=0
for i in range(n-k+1):
    tmp=0
    for j in range(k):
        tmp += p[i+j]
    if sum < tmp:
        cnt = i
        sum = tmp

ans=0
for i in range(cnt, cnt+k):
    tmp=0
    ans += (1+p[i])*p[i]/2/p[i]

print(ans)

### FIXED CODE ###

n,k = map(int, input().split())
p = [i for i in map(int, input().split())]

ex = []
for i in range(n):
    ex += [(1+p[i])]

s = sum(ex[0:k])
t = s
for i in range(n-k):
    s = s-ex[i]+ex[i+k]
    t = max(t, s)

print(t/2)
### BUGGY CODE ###

n,m = map(int,input().split())
branch = dict()
for i in range(1,n+1):
	branch[i] = []
for i in range(m):
	a,b = map(int,input().split())
	branch[a].append(b)
	branch[b].append(a)
arrival = [0 for i in range(n+1)]
q = [1]
arrival[1] = 1
while len(q)>0:
	next = branch[q[0]]
	for i in range(len(next)):
		if arrival[next[i]] == 0:
			arrival[next[i]] = arrival[q[0]]+1
			q.append(next[i])
	q.pop(0)
if arrival[n] == 3:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')

### FIXED CODE ###

n,m = map(int,input().split())
branch = dict()
for i in range(n):
	branch[i+1] = []
for i in range(m):
	a,b = map(int,input().split())
	branch[a].append(b)
	branch[b].append(a)

q = []
for i in range(len(branch[1])):
	q.append(branch[1][i])

check = False
for i in range(len(q)):
	if n in branch[q[i]]:
		check = True
		break
if check:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')
### BUGGY CODE ###

n,k = map(int,input().split())
al = list(map(int,input().split()))

from collections import defaultdict
dic = defaultdict(int)
for a in al:
    dic[a] += 1

l = [i for i in dic.values()]
l = sorted(l)

loop = 0
ans = 0
while True:
    loop += 1
    if loop > 200000:
        print("yabe")
        import sys
        sys.exit()
    if len(l) > k:
        ans += l[0]
    else:
        break
    l.pop(0)

print(ans)
    

### FIXED CODE ###

n,k = map(int,input().split())
al = list(map(int,input().split()))

from collections import defaultdict
dic = defaultdict(int)
for a in al:
    dic[a] += 1

l = [i for i in dic.values()]
l = sorted(l)

a = len(l) - k

ans = 0
for i in range(max(a,0)):
    ans += l[i]

print(ans)