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

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

num = []
count = []
for a in range(len(A)):
    tmp = A[a]
    if not tmp in num:
        num.append(tmp)
        count.append(1)
    else:
        index = num.index(tmp)
        count[index] += 1

count = sorted(count)
ans = 0
if len(count)<=K:
    pass
else:
    tmp = len(count)-K
    count = count[:tmp]
    ans = sum(count)

print(ans)

### FIXED CODE ###

#辞書型でリトライ
N,K = map(int, input().split(' '))
A = input().split(' ')

dic = {}
for a in range(len(A)):
    tmp = A[a]
    if not tmp in dic:
        dic[tmp] = 1
    else:
        dic[tmp] += 1

values = sorted(dic.values())
ans = 0
if len(values)<=K:
    pass
else:
    tmp = len(values)-K
    values = values[:tmp]
    ans = sum(values)

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

def main():
    n,m = map(int,input().split())

    edges = [[] for _ in range(n)]

    for _ in range(m):
        a,b = map(int,input().split())
        edges[a-1].append(b-1)
        edges[b-1].append(a-1)

    q = [0]

    ans = [-1]*n
    ans[0] = 0
    count = 1

    while q:
        l = q.pop(0)
        for i in edges[l]:
            if ans[i] == -1:
                ans[i] = l
                count += 1
                q.append(i)
        if count == n:
            break

    if count == n:
        print('Yes')
        for i in ans[1:]:
            print(i+1)
    else:
        print('No')

if __name__ == '__main__':
    main()


### FIXED CODE ###

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

edges = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

q = [0]

ans = [-1]*n
ans[0] = 0
count = 1

while q:
    l = q.pop(0)
    for i in edges[l]:
        if ans[i] == -1:
            ans[i] = l
            count += 1
            q.append(i)
    if count == n:
        break

if count == n:
    print('Yes')
    for i in ans[1:]:
        print(i+1)
else:
    print('No')
### BUGGY CODE ###

def main():
    s = input()
    n = len(s)
    mod = 10 ** 9 + 7

    dp = [[0] * 13 for _ in range(n + 2)]
    dp[n + 1][0] = 1
    for i, t in zip(range(n, 0, -1), s):
        x = dp[i]
        y = dp[i + 1]
        for j in range(13):
            z = y[j]
            if not z:
                continue
            if t == '?':
                for d in range(10):
                    k = (10 * j + d) % 13
                    x[k] += z
            else:
                k = (10 * j + int(t)) % 13
                x[k] += z

    print(dp[1][5] % mod)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    s = input()
    mod = 10 ** 9 + 7
    table1 = [0] * 13
    table2 = [0] * 13
    table1[0] = 1
    pre = [[((10 * i + j) % 13) for j in range(10)] for i in range(13)]

    for l in s:
        for i in range(13):
            q = table1[i] % mod
            if q == 0:
                continue
            if l == '?':
                for k in pre[i]:
                    table2[k] += q
            else:
                k = (10 * i + int(l)) % 13
                table2[k] += q

        table1 = table2
        table2 = [0] * 13

    print(table1[5] % mod)


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

r, g, b, n = (int(i) for i in input().split())  
 
rmax = int(n/r)
gmax = int(n/g)
count = 0
 
for i in range(0, rmax + 1):
  for j in range(0, gmax + 1):
    tmp = (n - r * i - g * j)
    if (tmp % b == 0 and tmp >=0):
      count += 1
  
print(count)

### FIXED CODE ###

r, g, b, n = (int(i) for i in input().split())  
 
rmax = int(n/r)
count = 0
 
for i in range(0, rmax + 1):
  gmax = (n - r * i) // g
  for j in range(0, gmax + 1):
    tmp = n - r * i - g * j
    if (tmp % b == 0 and tmp >=0):
      count += 1
  
print(count)
### BUGGY CODE ###

import sys
import bisect
input = sys.stdin.readline
def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    f = list(map(int,input().split()))
    if sum(a)<=k:
        print(0)
    else:
        a.sort()
        f.sort(reverse=True)
        mul=[]
        for i in range(n):
            mul.append([a[i]*f[i],a[i]])
        mul.sort(reverse=True)
        for _ in range(k):
            mul[0][0]-=(mul[0][0]//mul[0][1])
            mul[0][1]-=1
            mul.sort(reverse=True)
        print(mul[0][0])



main()

### FIXED CODE ###

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト atcoder
    # ord(c) chr(2) alphabet <=> number
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    f = list(map(int,input().split()))
    a.sort()
    f.sort(reverse=True)
    ok = 10**12
    ng=-1

    while ok-ng>1:
        mid=(ok+ng)//2
        cnt=0
        for x,y in enumerate(a):
            cnt+=max(0,y-mid//f[x])
        if cnt>k:
            ng=mid
        else:
            ok=mid
    print(ok)
main()
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7

for i in range(60):
    x, y = 0, 0    
    for Ai in A:
        if Ai >> i & 1:
            x += 1
    y = N - x
    ans += (x * y) * (2 ** i)
    
print(ans % mod)

### FIXED CODE ###

import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
ans = 0
mod = 10 ** 9 + 7

for i in range(60):
    x, y = 0, 0    
    B = A >> i & 1
    x = np.count_nonzero(B)
#     for Ai in A:
#         if Ai >> i & 1:
#             x += 1
    y = N - x
    ans += (x * y) * (2 ** i)
    
print(ans%mod)
### BUGGY CODE ###

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

for i in range(A,B+1):
    if (i < A+K)or (i>B-K):
        print(i)

### FIXED CODE ###

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

if abs(A-B)<K:
    for i in range(A, B+1):
        print(i)
else:
    x = {i for i in range(A, A+K)}
    y = {j for j in range(B-K+1, B+1)}
    z = x | y
    z = sorted(list(z))
    for a in z:
        print(a)
### BUGGY CODE ###

N = int(input())
P = list(map(int, input().split(' ')))
count = 0
for i, value in enumerate(P):
    if min(P[:i+1]) == value:
        count += 1
print(count)

### FIXED CODE ###

N = int(input())
P = list(map(int, input().split(' ')))
count = 1
min_value = P[0]
for i in range(1, N):
    if P[i] <= min_value:
        min_value = P[i]
        count += 1
print(count)
### BUGGY CODE ###

import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

N,M,K = mips()
A = [i for i in mips()]
B = [i for i in mips()]
# N,M <= 200000
ans = 0
clock = K
A2 = [0]
B2 = [0]
for i in range(1,N+1):
    ai = A2[i-1] + A[i-1]
    A2.append(ai)
for i in range(1,M+1):
    bi = B2[i-1] + B[i-1]
    B2.append(bi)
for i in range(N+1):
    j = M
    if A2[i] > K:
        break
    while (B2[j] + A2[i] > K):
        j -= 1
    ans = max(ans,i+j)
print(ans)

### FIXED CODE ###

import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

N,M,K = mips()
A = [i for i in mips()]
B = [i for i in mips()]
# N,M <= 200000
ans = 0
clock = K
A2 = [0]
B2 = [0]
for i in range(1,N+1):
    ai = A2[i-1] + A[i-1]
    A2.append(ai)
for i in range(1,M+1):
    bi = B2[i-1] + B[i-1]
    B2.append(bi)
j = M
for i in range(N+1):
    if A2[i] > K:
        break
    while (B2[j] + A2[i] > K):
        j -= 1
    ans = max(ans,i+j)
print(ans)
### BUGGY CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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

uf = UnionFind(N)
AB=[tuple(map(int,input().split())) for _ in range(M)]
x=[uf.union(ab[0]-1,ab[1]-1) for ab in AB]

dic=uf.all_group_members()
print(max([len(d) for d in dic.values()]))

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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

uf = UnionFind(N)

for i in range(M):
    A,B=map(int,input().split())
    uf.union(A-1,B-1)

print(max([uf.size(i) for i in range(N)]))
### BUGGY CODE ###

N = int(input())
v = list(map(int, input().split()))
answer = 1
for i in v:
    answer = answer * i
answer = answer if answer <= 1000000000000000000 else -1
print(answer)

### FIXED CODE ###

N = int(input())
v = list(map(int, input().split()))
limit = 10 ** 18

answer = 1
if 0 in v:
  answer = 0
else:
  for i in v:
    answer = answer * i
    if answer <= limit:
      continue
    else:
      answer = -1
      break
print(answer)
### BUGGY CODE ###

import collections

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

ans=0
B=collections.Counter(A)

keys=list(B.keys())
values=list(B.values())

for i in values:
    ans+=(i*(i-1))//2


for j in A:
    ANS=ans
    num=values[keys.index(j)]
    ANS=ANS-(num-1)
    print(ANS)

### FIXED CODE ###

import collections

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

ans=0
dic=collections.Counter(A)
keys=list(dic.keys())
values=list(dic.values())


for i in values:
    
    ans+=(i*(i-1))//2

for j in A:
    ANS=ans
    num=dic[j]
    ANS=ANS-(num-1)
    print(ANS)
### BUGGY CODE ###

import numpy as np
n=int(input())
s=input()
dp=np.zeros((n+1,n+1),dtype=int)
for i in range(n):
    for j in range(i+1,n):
        if s[i]==s[j]:
            if dp[i][j]<j-i:
                dp[i+1][j+1]=dp[i][j]+1
print(np.amax(dp))

### FIXED CODE ###

n=int(input())
s=input()
dp=[[0]*n for i in range(n)]
for i in range(n-2,-1,-1):
    for j in range(n-1,i,-1):
        if j==n-1:
            if s[j]==s[i]:
                dp[i][j]=1
        else:
            if s[j]==s[i] and dp[i+1][j+1]+1<=j-i:
                dp[i][j]=dp[i+1][j+1]+1
            else:
                dp[i][j]=0
ans=0
for i in range(n):
    for j in range(n):
        ans=max(ans,dp[i][j])
print(ans)
### BUGGY CODE ###

n, m = tuple(map(int, input().split()))
a = list(map(int, [input() for _ in range(m)]))

dp = []
# 0段目と1段目は1通り（但し、１段目が壊れていない場合）（0 段目は「なにもしない」という から1 通り）
dp[:2] = 1, 1 if 1 not in a else 0 

for i in range(2, n + 1):
    if i in a:
        dp.append(0)
    else:
        dp.append(dp[i - 1] + dp[i - 2])

print(dp[-1] % (10 **9+7))

### FIXED CODE ###

n, m = map(int, input().split())
a = set(map(int, [input() for _ in range(m)]))

dp = [0] * (n+1)
# 0段目と1段目は1通り（但し、１段目が壊れていない場合）（0 段目は「なにもしない」という から1 通り）
dp[:2] = 1, 1 if 1 not in a else 0 

for i in range(2, n+1):
    if i in a:
        continue
    else:
        dp[i] = (dp[i-1] + dp[i-2])

print(dp[-1] % (10**9+7))
### BUGGY CODE ###

import math
import time

t = time.time()
def iip():
    return [int(i) for i in input().split()]

H, N = iip()
mp_for_damage = [10**9 for i in range(H+1)]
mp_for_damage[0] = 0
ab = []

for i in range(N):
    ab.append(iip())

ab= sorted(ab, key=lambda x:x[0]/x[1], reverse=True)

for i in range(N):
    a, b = ab[i]
    for j in range(H+1):
        if a < H and mp_for_damage[a] < b:
            continue

        for k in range(1, a):
            if k > H:
                break
            mp_for_damage[k] = min(mp_for_damage[k], b)

        if j + a > H:
            break
        mp_for_damage[j+a] = min(mp_for_damage[j+a], mp_for_damage[j] + b)

#print(mp_for_damage)
print(mp_for_damage[H])

#print(time.time() - t)

### FIXED CODE ###

import math
import time


t = time.time()
def iip():
    return [int(i) for i in input().split()]

def main():
    H, N = iip()
    mp_for_damage = [10**9 for i in range(H+1)]
    mp_for_damage[0] = 0
    ab = []

    for i in range(N):
        ab.append(iip())

    ab= sorted(ab, key=lambda x:x[0]/x[1], reverse=True)

    for i in range(N):
        a, b = ab[i]

        for k in range(1, min(a, H) + 1):
            mp_for_damage[k] = min(mp_for_damage[k], b)
            # print(k, b)

        if a >= H:
            mp_for_damage[H] = min(mp_for_damage[H], b)
            continue

        if a < H and mp_for_damage[a] < b:
            continue

        for j in range(H-a+1):
            mp_for_damage[j+a] = min(mp_for_damage[j+a], mp_for_damage[j] + b)

    #print(mp_for_damage)
    #print(mp_for_damage)
    print(mp_for_damage[H])

    #print(time.time() - t)

main()
### BUGGY CODE ###

N = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
for i in set(a):
	if i <= a.count(i):
		ans += a.count(i) - i
	else:
		ans += a.count(i)
print(ans)


### FIXED CODE ###

import collections

N = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0

for ai in set(a):
    if c[ai] < ai:
        ans += c[ai]
    else:
        ans += c[ai] - ai

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

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

### FIXED CODE ###

n,k = 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]))
### BUGGY CODE ###

#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    S=input()
    n=len(S)
    A="dream dreamer erase eraser".split()
    F=A[:]
    for a in A:
        for b in A:
            F.append(a+b)
    
    #print(F)
    #print(A)
    global cond
    cond=[]
    def dfslike_dreameraser(varS):#string->bool,resursion
        #print(varS)
        if len(varS)==0:
            cond.append(1)
            return 
        for word in reversed(F):
            if varS[:len(word)]==word:
                dfslike_dreameraser(varS[len(word):])
        return 
        
    dfslike_dreameraser(S)
    #print(cond)
    print(["NO","YES"][cond!=[]])
#%%submit!
resolve()

### FIXED CODE ###

#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
import random
def resolve():
    
    S=input()
    A="dream dreamer erase eraser".split()
    #print(A)
    que=[S]
    while(que!=[]):
        t=len(que)
        #print(t)
        vS=que.pop(random.randint(0,t-1))
        if vS=="":
            print("YES")
            return
        for w in A:
            r=len(w)
            if vS[:r]==w:
                que.append(vS[r:])
        #print(que,"k")    

    print("NO")
#%%submit!
resolve()
### BUGGY CODE ###

N=int(input())
S=list(input())
flag=1
count=0
for i in range(1000):
  numS=''
  flag=1
  if i<10:
    numS='00'+str(i)
  elif i<100:
    numS='0'+str(i)
  else:
    numS=str(i)
  for j in range(N):
    if numS[0]==S[j]:
      for k in range(j+1,N):
        if numS[1]==S[k]:
          if numS[2] in S[k+1:N]:
            count+=1
            flag=0
            break
    if flag==0:
      break

print(count)

### FIXED CODE ###

N = int(input())
S = input()
s1 = set()
s2 = set()
s3 = set()

for i in S:
  for j in s2:
    s3.add(j+i)
  for k in s1:
    s2.add(k+i)
  s1.add(i)
print(len(s3))
### BUGGY CODE ###

import sys
input=sys.stdin.readline
import heapq

H,W = map(int,input().split())
C_pos=list(map(lambda x:int(x)-1,input().split()))

C_pos=(C_pos[0],C_pos[1])

D_pos=list(map(lambda x:int(x)-1,input().split()))

Grid=[[c for c in input()] for _ in range(H)]

Dist=[[float("inf")]*W for _ in range(H)]

Dist[C_pos[0]][C_pos[1]]=0


Q=[]
heapq.heappush(Q,(0,C_pos[0],C_pos[1]))

DX=[-1,1,0,0]
while Q:
    #上下左右の道
    dist,cx,cy=heapq.heappop(Q)

    if cx==D_pos[0] and cy==D_pos[1]:
        break

    for dx,dy in zip(DX,reversed(DX)):
        nx = cx+dx
        ny=cy+dy
        if 0<=nx<H and 0<=ny<W and Grid[nx][ny]==".":
            if Dist[nx][ny]>dist:
                Dist[nx][ny]=dist
                Q.append((dist,nx,ny))
    #ワープ
    for dx in range(-2,3):
        for dy in range(-2,3):
            if dx==0 and dy==0:
                continue
            nx = cx+dx
            ny=cy+dy
            if 0<=nx<H and 0<=ny<W and Grid[nx][ny]==".":
                if Dist[nx][ny]>dist+1:
                    Dist[nx][ny]=dist+1
                    Q.append((dist+1,nx,ny))


#print(Dist)
ans=Dist[D_pos[0]][D_pos[1]]
if ans==float("inf"):
    print(-1)
else:
    print(ans)


### FIXED CODE ###

from collections import deque
import sys
input=sys.stdin.readline
H,W = map(int,input().split())
C_pos=list(map(lambda x:int(x)-1,input().split()))
D_pos=list(map(lambda x:int(x)-1,input().split()))
Grid=[[c for c in input()] for _ in range(H)]
Dist=[[float("inf")]*W for _ in range(H)]

DX=[0,0,1,-1]
DY=[1,-1,0,0]

Q=deque()
Q.append((C_pos[0],C_pos[1]))
DX=[-1,1,0,0]
visited=set()
prev_visited=set()

dist=0
while True:
    prev_visited=set(v for v in Q)
    if len(Q)==0:
        print(-1)
        exit()

    #できる限りbfs
    while Q:
        cx,cy=Q.pop()
        if cx==D_pos[0] and cy==D_pos[1]:
            print(dist)
            exit()

        visited.add((cx,cy))
        for dx,dy in zip(DX,reversed(DX)):
            nx = cx+dx
            ny=cy+dy
            if 0<=nx<H and 0<=ny<W and Grid[nx][ny]=="." and (nx,ny) not in visited:
                visited.add((nx,ny))
                prev_visited.add((nx,ny))
                Dist[nx][ny]=dist
                Q.append((nx,ny))
                if nx==D_pos[0] and ny==D_pos[1]:
                    print(dist)
                    exit()

    Q=deque()
    for cx,cy in prev_visited:
        for dx in range(-2,3):
            for dy in range(-2,3):
                if dx==0 and dy==0:
                    continue
                nx = cx+dx
                ny=cy+dy
                if (nx,ny) in visited:
                    continue
                if 0<=nx<H and 0<=ny<W and Grid[nx][ny]==".":
                    Q.append((nx,ny))
    dist+=1
### BUGGY CODE ###

N = int(input())
Cx = [[] for i in range(N)]
Cy = [[] for i in range(N)]
for i in range(N):
  x, y = map(int, input().split())
  Cx[i] = [x, i]
  Cy[i] = [y, i]
Cx.sort()
Cy.sort()
Qx = [[Cx[i + 1][0] - Cx[i][0], Cx[i][1], Cx[i + 1][1]] for i in range(N - 1)]
Qx.sort()
Qy = [[Cy[i + 1][0] - Cy[i][0], Cy[i][1], Cy[i + 1][1]] for i in range(N - 1)]
Qy.sort()
R = [i for i in range(N)]
def root(n):
  if R[n] == n:
    return n
  else:
    R[n] = root(R[n])
    return R[n]
cnt = 0
cost = 0
x = 0
y = 0
while cnt < N - 1:
  if Qx[x][0] <= Qy[y][0]:
    q = Qx[x]
    x += 1
  else:
    q = Qy[y]
    y += 1
  if root(q[1]) != root(q[2]):
    R[R[q[2]]] = q[1]
    cost += q[0]
    cnt += 1
print(cost)

### FIXED CODE ###

N = int(input())
Cx = [[0, 0] for i in range(N)]
Cy = [[0, 0] for i in range(N)]
for i in range(N):
  x, y = map(int, input().split())
  Cx[i] = [x, i]
  Cy[i] = [y, i]
Cx.sort()
Cy.sort()
Qx = sorted([[Cx[i + 1][0] - Cx[i][0], Cx[i][1], Cx[i + 1][1]] for i in range(N - 1)])
Qy = sorted([[Cy[i + 1][0] - Cy[i][0], Cy[i][1], Cy[i + 1][1]] for i in range(N - 1)])
R = [i for i in range(N)]
def root(n):
  if R[n] == n:
    return n
  else:
    R[n] = root(R[n])
    return R[n]
cnt = 0
cost = 0
x = 0
y = 0
while cnt < N - 1:
  if Qx[x][0] <= Qy[y][0]:
    q = Qx[x]
    x += 1
  else:
    q = Qy[y]
    y += 1
  r1 = root(q[1])
  r2 = root(q[2])
  if r1 != r2:
    R[r2] = q[1]
    cost += q[0]
    cnt += 1
print(cost)
### BUGGY CODE ###

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

for i in range(a[0],a[N-1]+1):
    cnt = max(a.count(i-1)+a.count(i)+a.count(i+1),cnt)
print(cnt)

### FIXED CODE ###

import sys

def input():
    return sys.stdin.readline().strip()

def main():
    N = int(input())
    a = list(map(int,input().split()))
    cnt = [0] * (max(a) + 2)

    for i in a:
        if i != 0:
            cnt[i-1] += 1
        cnt[i] += 1
        cnt[i+1] += 1
    print(max(cnt))

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

import math

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

h2 = sorted(h, reverse=True)

if n <= k:
    print(0)
else:
    for _ in range(k):
        h2.pop(0)
    ans = sum(h2)
    print(ans)

### FIXED CODE ###

import math

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

h.sort(reverse=True)

if n <= k:
    print(0)
else:
    x = n - k
    del h[0:k]
    ans = sum(h)
    print(ans)
### BUGGY CODE ###

from functools import reduce

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

def cmb(n, r):
    INF = 10 ** 9 + 7
    r = min(n - r, r)
    if r == 0:  return 1
    numer = reduce(lambda x, y: (x * y) % INF, range(n, n - r, -1))
    denom = reduce(lambda x, y: (x * y) % INF, range(1, r + 1))
    return (numer * pow(denom, INF - 2, INF)) % INF

A = sorted(A)
B = A[::]
n = A[-1]
temp = n // 2
min_ = 10 ** 9 + 7
for i in range(N - 1):
    A[i] -= temp
    A[i] = abs(A[i])
min_ = min(A)
ind = []
for i in range(N - 1):
    if A[i] == min_:
        if B[i] not in ind:
            ind.append(B[i])
            
mi = 0
ans = 0
for i in range(len(ind)):
    c = cmb(n, ind[i])
    if c > mi:
        mi = c
        ans = ind[i]
print(n, ans)

### FIXED CODE ###

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

A = sorted(A)
B = A[::]
n = A[-1]
temp = n // 2
min_ = 10 ** 9 + 7
for i in range(N - 1):
    A[i] -= temp
    A[i] = abs(A[i])
min_ = min(A)
for i in range(N - 1):
    if A[i] == min_:
        ans = B[i]
print(n, ans)