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

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

n,u,v=map(int,input().split())

row,col,w=[],[],[]
for i in range(n-1):
 a,b=map(int,input().split())
 row.append(a-1)
 col.append(b-1)
 w.append(1)

g=csr_matrix((w,(row,col)),shape=(n,n))

d_u=dijkstra(g,directed=False,indices=u-1)
d_v=dijkstra(g,directed=False,indices=v-1)

l=0
for t_u,t_v in zip(d_u,d_v):
 if t_u<t_v:
  l=max(l,t_v)
print(int(l)-1)

### FIXED CODE ###

from collections import deque

def BFS(t):
    tree=[[] for i in range(n)]
    for i in list:
      tree[i[0]-1].append(i[1]-1)
      tree[i[1]-1].append(i[0]-1)

    dist=[-1 for i in range(n)]
    dist[t-1]=0

    que=deque()
    que.append(t-1)
    while que:
        x=que.popleft()
        for p in tree[x]:
            if dist[p]==-1:
                que.append(p)
                dist[p]=dist[x]+1
    return dist

n,u,v=map(int,input().split())
list=[list(map(int,input().split())) for i in range(n-1)]

u_dist=BFS(u)
v_dist=BFS(v)

l=0
for u_d,v_d in zip(u_dist,v_dist):
 if u_d<v_d:
  l=max(l,v_d)

print(l-1)
### BUGGY CODE ###

from bisect import*
n,*t=map(int,open(0).read().split())
c=0
for k in range(30):
    b=sorted(i%2**-~k for i in t[n:])
    m=0
    for a in[i%2**-~k for i in t[:n]]:
        l,r=bisect_left(b,2**k-a),bisect_left(b,2**-~k-a)
        if 2**k-a<0:
            l=bisect_left(b,(2**k-a)%2**-~k)-n
        m+=r-l
    c+=m%2*2**k
print(c)

### FIXED CODE ###

def main():
    from numpy import array,searchsorted,sum,hstack
    n,*t=map(int,open(0).read().split())
    a,b=array(t[:n],'i4'),array(t[n:],'i4')
    c=0
    for k in range(28,-1,-1):
        l,h=pow(2,k),pow(2,k+1)
        a%=h
        b%=h
        b.sort()
        y=hstack((b-h,b))
        i=searchsorted(y,l-a)
        j=searchsorted(y,h-a)
        m=sum(j-i)
        c+=m%2*l
    print(c)
if __name__=='__main__':
    main()
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split())) 
q = int(input())

arr = [0] * (10**5+1)
# arr = [i for i in range(1, 10**5+1)]

for i in A:
    arr[i] += i

for _ in range(q):
    b, c = map(int, input().split())
    arr[c] += (arr[b]//b*c)
    arr[b] = 0

    print(sum(arr))


### FIXED CODE ###

n = int(input())
A = list(map(int, input().split())) 
q = int(input())

from collections import Counter
arr = Counter(A)
ans = sum([i*arr[i] for i in arr])
 
for i in range(q):
    b,c = list(map(int,input().split()))
    ans += (c-b)*arr[b]
    arr[c],arr[b] = arr[c]+arr[b],0
    print(ans)
### BUGGY CODE ###

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

ways = 0

for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i + j + k == S:
                ways += 1


print(ways)

### FIXED CODE ###

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

ways = 0
for i in range(K+1):
    for j in range(K+1):
        k = S - i - j
        if k >= 0 and k <= K:
            ways += 1

print(ways)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

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

seg = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

B = {}
for a in A:
    ind = seg[a]
    if not ind in B.keys():
        B[ind] = a
    else:
        if B[ind] < a:
            B[ind] = a

I = sorted(list(B.keys()))
#print(I)
Ap = []
def search(ind, remain, ret, l, maxl):
    if ind >= len(I):
        return False, ret, l
    #print(I[ind], remain, ret)
    a = I[ind]
    p = remain // a
    r = remain % a 
    if p == 0:
        return False, ret, l
    if r == 0:
        ret.append((a, p))
        l += p
        return True, ret, l
    for q in range(p-1, -1, -1):
        nowl = l
        r += a
        oldr = ret[:]
        ok, newr, newl = search(ind+1, r, oldr, nowl, maxl)
        if ok:
            newl += q
            newr.append((a, q))
            if ind == 0:
                if newl >= maxl:
                    maxl = newl
                    Ap.append(newr)
                continue
            return True, newr, newl
    if ind == 0:
        return False, Ap, l
    return False, ret, l

def main():

    only, Ls, l = search(0, N, [], 0, 0)
    #print(Ls)
    if only:
        Q = []
        for k, v in Ls:
            Q.extend([B[k]]*v)
        Q.sort(reverse=True)
        print(''.join([str(q) for q in Q]))
    else:
        anss = []
        for i, L in enumerate(Ls):
            P = []
            for k, v in L:
                P.append((B[k], v))
            P.sort(reverse=True)
            if i == 0:
                maxp = P[0][1]
            elif P[0][1] >= maxp:
                maxp = P[0][1]
            else:
                continue
            Q = ''
            for p, v in P:
                Q = Q + str(p)*v
            num = int(Q)
            anss.append(num)

        print(max(anss))

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

NUM = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
INF = 10**14

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

dp = [-INF]*(N+1)
dp[0] = 0
for i in range(N):
    for a in A:
        c = NUM[a]
        if i + c <= N:
            dp[i+c] = max(dp[i+c], dp[i]+1)

D = dp[N]
ind = N
ans = ''
for _ in range(D):
    for a in A:
        c = NUM[a]
        if ind - c < 0: continue
        if dp[ind] == dp[ind-c] + 1:
            ind -= c
            ans += str(a)
            break
print(ans)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(3000)

H, W = map(int, input().split())
lst = [['#'] * (W+2)]
lst += [['#'] + list(input()) + ['#'] for i in range(H)]
lst += [['#'] * (W+2)]


lst_ue = [[-1] * (W+2) for i in range(H+2)]
lst_shita = [[-1] * (W+2) for i in range(H+2)]
lst_migi = [[-1] * (W+2) for i in range(H+2)]
lst_hidari = [[-1] * (W+2) for i in range(H+2)]

# print (lst_ue)
def ue(i, j):
    if lst_ue[i][j] != -1:
        return lst_ue[i][j]
    if lst[i][j] == '#':
        lst_ue[i][j] = 0
        return 0
    else:
        lst_ue[i][j] = ue(i-1, j) + 1
        return lst_ue[i][j]


def shita(i, j):
    if lst_shita[i][j] != -1:
        return lst_shita[i][j]
    if lst[i][j] == '#':
        lst_shita[i][j] = 0
        return 0
    else:
        lst_shita[i][j] = shita(i+1, j) + 1
        return lst_shita[i][j]        


def hidari(i, j):
    if lst_hidari[i][j] != -1:
        return lst_hidari[i][j]
    if lst[i][j] == '#':
        lst_hidari[i][j] = 0
        return 0
    else:
        lst_hidari[i][j] = hidari(i, j-1) + 1
        return lst_hidari[i][j]        

def migi(i, j):
    if lst_migi[i][j] != -1:
        return lst_migi[i][j]
    if lst[i][j] == '#':
        lst_migi[i][j] = 0
        return 0
    else:
        lst_migi[i][j] = migi(i, j+1) + 1
        return lst_migi[i][j]        

ans = 0
for i in range(1,H+1):
    for j in range(1, W+1):
        if lst[i][j] != '#':
            ans = max(ans, ue(i,j)+shita(i,j)+hidari(i,j)+migi(i,j)-3)

print (ans)


### FIXED CODE ###

#上下方向の探索と左右方向の探索をまとめる
#まず表を完成させる-->全マスの探索
H, W = map(int, input().split())
lst = [['#'] * (W+2)]
lst += [['#'] + list(input()) + ['#'] for i in range(H)]
lst += [['#'] * (W+2)]


lst_ue = [[0] * (W+2) for i in range(H+2)]
lst_shita = [[0] * (W+2) for i in range(H+2)]
lst_migi = [[0] * (W+2) for i in range(H+2)]
lst_hidari = [[0] * (W+2) for i in range(H+2)]

for i in range(1, H+1):
    for j in range(1, W+1):
        lst_hidari[i][j] = 0 if lst[i][j] == '#' else 1 + lst_hidari[i][j-1]
    for j in range(W, 0, -1):
        lst_migi[i][j] = 0 if lst[i][j] == '#' else 1 + lst_migi[i][j+1]

for j in range(1, W+1):
    for i in range(1, H+1):
        lst_ue[i][j] = 0 if lst[i][j] == '#' else 1 + lst_ue[i-1][j]
    for i in range(H+1, 0, -1):
        lst_shita[i][j] = 0 if lst[i][j] == '#' else 1 + lst_shita[i+1][j]

ans = 0
for i in range(1,H+1):
    for j in range(1, W+1):
        ans = max(ans, lst_ue[i][j]+lst_shita[i][j]+lst_migi[i][j]+lst_hidari[i][j]-3)

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

N=int(input())

a=[[0 for j in range(N-1)] for i in range(N)]
for i in range(N):
  line=list(map(int,input().split()))
  for j in range(N-1):
    a[i][j]=line[j]-1

id=[[0 for j in range(N)] for i in range(N)]
v=0
for i in range(N-1):
  for j in range(i+1,N):
    id[i][j]=v
    v+=1

def toId(i,j):
  if i>j:
    i,j=j,i
  return id[i][j]

to=[[] for i in range(v)]
inner=[0 for i in range(v)]
for i in range(N):
  for j in range(N-1):
    a[i][j]=toId(i,a[i][j])
  for j in range(N-2):
    to[a[i][j]].append(a[i][j+1])
    inner[a[i][j+1]]+=1

stack=[]
isstarted=[False for i in range(v)]
dist=[0 for i in range(v)]
for i in range(v):
  if inner[i]==0:
    stack.append([i,1])

while stack:
  node=stack.pop()
  e=node[0]
  d=node[1]
  if d>dist[e]:
    dist[e]=d
  inner[e]-=1
  if inner[e]<=0 and not isstarted[e]:
    isstarted[e]=True
    children=to[e]
    for child in children:
      stack.append([child,dist[e]+1])
for i in range(len(isstarted)):
  if not isstarted[i]:
    print(-1)
    break
else:
  ans=0
  for i in range(len(dist)):
    if dist[i]>ans:
      ans=dist[i]
  print(ans)

### FIXED CODE ###

N=int(input())
a=[[0 for j in range(N-1)] for i in range(N)]
for i in range(N):
  line=list(map(int,input().split()))
  for j in range(N-1):
    a[i][j]=line[j]-1
  a[i]=a[i][::-1]
    
q=[]

#seen=[[False for j in range(N)] for i in range(N)]

# 選手nが試合できるならqueに入れる
def check(i):
  if len(a[i])==0:
    return False
  j=a[i][-1]
  if a[j][-1]==i:
    q.append([i,j])
  
for i in range(N):
  check(i)
  
from collections import defaultdict

day=0
while q:
  day+=1
 # q=sorted(q)
  prevQ=q.copy()
  q=[]
  matched=defaultdict(list)
  for p in prevQ:
    i=p[0]
    j=p[1]
    if i>j:
      i,j=j,i
    if matched[i]:
      continue
    a[i].pop()
    a[j].pop()
    check(i)
    check(j)
    matched[i].append(j)
    
for i in range(N):
  if len(a[i])!=0:
    print(-1)
    break
else:
  print(day)
### BUGGY CODE ###

import sys
S=input()
Q=int(sys.stdin.readline())
for i in range(Q):
	qu=input()
	if qu[0]=='1':
		S=S[::-1]
	else:
		if qu[2]=='1':
			S=qu[4]+S
		else:
			S+=qu[4]
print(S)

### FIXED CODE ###

import sys
from collections import deque
S=[input()]
S=deque(S)
Q=int(sys.stdin.readline())
flag=0
for i in range(Q):
	qu=tuple(input().split())
	if qu[0]=='1':
		if flag==0:
			flag+=1
		else:
			flag=0
	else:
		if qu[1]=='1' and flag==0:
			S.appendleft(qu[2])
		elif qu[1]=='1' and flag==1:
			S.append(qu[2])
		elif qu[1]=='2' and flag==0:
			S.append(qu[2])
		elif qu[1]=='2' and flag==1:
			S.appendleft(qu[2])
if flag==1:
	S=''.join(S)
	S=S[::-1]
	print(S)
	exit()
print(''.join(S))
### BUGGY CODE ###

import bisect


def solve(mid):
    cnt = 0
    r = n
    for i in range(n):
        l = bisect.bisect_left(a, mid - a[i])
        cnt += (r - l)
    return cnt >= m
    

n, m = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)

ok = 0
ng = 10 ** 18
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid

ru = [0] * (n + 1)
for i in range(n):
    ru[i + 1] = ru[i] + a[i]

ans = 0
r = n
ok = ok + 1
cnt = 0
for i in range(n):
    l = bisect.bisect_left(a, ok - a[i])
    cnt += (r - l)
    ans += (r - l) * a[i] + (ru[r] - ru[l])
ans += (ok - 1) * (m - cnt)
print(ans)


### FIXED CODE ###

import bisect


n, m = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)

ruiseki = [0]*(n+1)
for i in range(n):
    ruiseki[i+1] = ruiseki[i] + a[i]

def solve(min_power):
    ans = 0
    for pos in range(n):
        tmp = min_power - a[pos]
        next_pos = max(bisect.bisect_left(a, tmp), pos)
        times = n - pos - (next_pos - pos)
        if times == n - pos:
            ans += 2 * (times - 1) + 1 
        else:
            ans += 2 * times
    if ans >= m:
        return True
    else:
        return False

ok = 0
ng = 2*10**5 + 1
while abs(ok - ng) > 1:
    mid =  (ok + ng) // 2 
    if solve(mid):
        ok = mid
    else:
        ng = mid

cnt = 0
ans = 0

for pos in range(n):
    tmp = ok - a[pos]
    next_pos = max(bisect.bisect_left(a, tmp), pos)
    times = n - pos - (next_pos - pos)
    if times == n - pos:
        cnt += 2 * (times - 1) + 1 
        ans += 2 * (ruiseki[n] - ruiseki[n-times+1] + (times-1)*a[pos]) + 2*a[pos]
    else:
        cnt += 2 * times
        ans += 2 * (ruiseki[n] - ruiseki[n-times] + times*a[pos])

print(ans - (cnt-m)*ok)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

INF = 10 ** 18

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

dp = [INF] * (H + 1)
dp[0] = 0

for i in range(N):
    A, B = map(int, input().split())
    for j in range(H + 1):
        if j < A:
            dp[j] = min(dp[j], dp[0] + B)
        else:
            dp[j] = min(dp[j], dp[j - A] + B)
    
print (dp[H])

# for d in dp:
#     print (d)

### FIXED CODE ###

INF = 10 ** 18


H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

dp = [[INF] * (H + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
    for j in range(H + 1):
        if j < AB[i][0]:
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][0] + AB[i][1])
        else:
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - AB[i][0]] + AB[i][1])
    
print (dp[N][H])

# for d in dp:
#     print (d)
### BUGGY CODE ###

import math
import numpy as np
n = int(input())
li = np.zeros(n, dtype=np.int)
def solve(n):
    s = math.sqrt(n)
    i = 2
    f = {}
    n_ = n
    while i <= s:
        while n_ % i == 0:
            f[i] = f.get(i,0)+1
            n_ = n_ // i
        i += 1

    c = 1
    if n_ > 1:
        f[n_] = 1
    for x in f.values():
        c *= (x+1)
    
    return c

ans = 0
while n > 0:
    n -= 1
    if n==0:
        break
    ans += solve(n)
print(ans)

### FIXED CODE ###

import math
import numpy as np
n = int(input())
li = np.zeros(n, dtype=np.int)
ans = 0
i = 1
while i < n:
    ans += (n-1)//i
    i += 1
print(ans)
### BUGGY CODE ###

from collections import deque

h,w = map(int,input().split())#行,列
C = list(map(int,input().split()))
D = list(map(int,input().split()))
S = [list(input()) for _ in range(h)]

seen = [[0]*w for _ in range(h)]
cost = [[-1]*w for _ in range(h)]
cost[C[0]-1][C[1]-1]=0
cost_base = 0
for i in range(h):
    for j in range(w):
        if S[i][j]=='#':
            cost[i][j]=-2

ok = True

q=deque()
q.append(C)
                
while len(q)>0:
    #移動A
    now = q.popleft()
    if seen[now[0]-1][now[1]-1] == 1:
        continue
    costnow = cost[now[0]-1][now[1]-1]
    seen[now[0]-1][now[1]-1] = 1

    for i in range(-1,2,2):
        if now[0]+i<1 or now[0]+i>h:
            continue
        if cost[now[0]+i-1][now[1]-1]==-1 or cost[now[0]+i-1][now[1]-1]>costnow:
            cost[now[0]+i-1][now[1]-1]=costnow
            q.appendleft([now[0]+i,now[1]])
    for i in range(-1,2,2):
        if now[1]+i<1 or now[1]+i>w:
            continue
        if cost[now[0]-1][now[1]+i-1]==-1 or cost[now[0]-1][now[1]+i-1]>costnow:
            cost[now[0]-1][now[1]+i-1]=costnow
            q.appendleft([now[0],now[1]+i])

    #移動B
    for i in range(-2,3):
        for j in range(-2,3):
            if now[0]+i<1 or now[0]+i>h:
                continue
            if now[1]+j<1 or now[1]+j>w:
                continue

            if cost[now[0]+i-1][now[1]+j-1]==-1:
                cost[now[0]+i-1][now[1]+j-1]=costnow+1
                q.append([now[0]+i,now[1]+j])

print(cost[D[0]-1][D[1]-1])

### FIXED CODE ###

from collections import deque

h,w = map(int,input().split())#行,列
C = list(map(int,input().split()))
D = list(map(int,input().split()))
S = [list(input()) for _ in range(h)]

seen = [[0]*w for _ in range(h)]
cost = [[-1]*w for _ in range(h)]
cost[C[0]-1][C[1]-1]=0
cost_base = 0
for i in range(h):
    for j in range(w):
        if S[i][j]=='#':
            cost[i][j]=-2

ok = True

q=deque()
q.append(C)
                
while len(q)>0:
    #移動A
    now = q.popleft()
    if seen[now[0]-1][now[1]-1] == 1:
        continue
    costnow = cost[now[0]-1][now[1]-1]
    seen[now[0]-1][now[1]-1] = 1

    for i in range(-1,2,2):
        if now[0]+i<1 or now[0]+i>h:
            continue
        if cost[now[0]+i-1][now[1]-1]==-1 or cost[now[0]+i-1][now[1]-1]>costnow:
            cost[now[0]+i-1][now[1]-1]=costnow
            q.appendleft([now[0]+i,now[1]])
    for i in range(-1,2,2):
        if now[1]+i<1 or now[1]+i>w:
            continue
        if cost[now[0]-1][now[1]+i-1]==-1 or cost[now[0]-1][now[1]+i-1]>costnow:
            cost[now[0]-1][now[1]+i-1]=costnow
            q.appendleft([now[0],now[1]+i])

    #移動B
    for i in range(-2,3):
        for j in range(-2,3):
            if now[0]+i<1 or now[0]+i>h:
                continue
            if now[1]+j<1 or now[1]+j>w:
                continue

            if cost[now[0]+i-1][now[1]+j-1]==-1:
                cost[now[0]+i-1][now[1]+j-1]=costnow+1
                q.append([now[0]+i,now[1]+j])

print(cost[D[0]-1][D[1]-1])
### BUGGY CODE ###

n = input()

a = n[::-1] + "0"

ans = 0

prev = 0

INF = 10 ** 100

dp = [[-1, -1] for i in range(len(a)+3)]

dp[0][0] = int(a[0])
dp[0][1] = 10 - int(a[0])

# dp[下の桁から][繰り上げるかどうか]
for i in range(1, len(a)):
    x = int(a[i])
    y = x + 1
    dp[i][0] = min([x + dp[i - 1][0], y + dp[i - 1][1]])
    dp[i][1] = min([(10 - x) + dp[i - 1][0], (10 - y) + dp[i - 1][1]])

print(min(dp[len(a)-1][0], dp[len(a)-1][1]))

### FIXED CODE ###

n = input()

a = n[::-1] + "0"

prev_a = int(a[0])
prev_b = 10 - int(a[0])

# dp[下の桁から][繰り上げるかどうか]
for i in range(1, len(a)):
    x = int(a[i])
    y = x + 1
    aa = min([x + prev_a, y + prev_b])
    bb = min([(10 - x) + prev_a, (10 - y) + prev_b])
    prev_a = aa
    prev_b = bb

print(min(aa, bb))
### BUGGY CODE ###

N,K = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
num = list(set(A))
ans=[]
for n in num:
    ans.append(A.count(n))
print(sum(sorted(ans)[:len(ans)-K:]))


### FIXED CODE ###

N,K = list(map(int,input().split(" ")))
d={}
for i in input().split(" "):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
print(sum(sorted(d.values())[:len(d.keys())-K:]))
### BUGGY CODE ###

#!/usr/bin/env python

n=int(input())
a=[int(i) for i in input().split()]
b=[]

for k,v in enumerate(a):
    if(k%2==0):
        b.insert(0, v)
    else:
        b.append(v)

if(n%2==0):
    b.reverse()

for k,v in enumerate(b):
    print(v, end="")
    if(k!=len(b)-1):
        print(" ", end="")
    else:
        print()


### FIXED CODE ###

#!/usr/bin/env python

n=int(input())
a=[int(i) for i in input().split()]

def cal(p, rev):
    if(rev):
        lst=reversed(list(enumerate(a)))
    else:
        lst=list(enumerate(a))
    for k,v in lst:
        if(k%2==p):
            print(str(v)+" ", end="")

if(n%2==1):
    cal(0, True)
    cal(1, False)
    print()
else:
    cal(1, True)
    cal(0, False)
    print()
### BUGGY CODE ###

x = int(input())
ans = 0
for b in range(1, x//2):
    for p in range(2, x):
        if b**p <= x:
            ans = max(ans, b**p)
        else:
            continue
if x == 1:
    ans = 1
print(ans)

### FIXED CODE ###

x = int(input())
ans = 1
for b in range(1, x):
    for p in range(2, x):
        if b**p <= x:
            ans = max(ans, b**p)
        else:
            break
print(ans)
### BUGGY CODE ###

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

def input():
    return sys.stdin.readline()[:-1]
A = list(map(int, input().split()))

hyouten = [0] * (N)

# 評点計算
for i in range(K-1, N):
    if i == K - 1:
        tmp = A[i]
        for j in range(1,K):
            tmp *= A[i-j]
    else:
        tmp //= A[i-K]
        tmp *= A[i]
    hyouten[i] = tmp

for i in range(K, N):
    if hyouten[i] > hyouten[i-1]:
        print('Yes')
    else:
        print("No")


### FIXED CODE ###

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

def input():
    return sys.stdin.readline()[:-1]
A = list(map(int, input().split()))


for i in range(K, N):
    if A[i-K] < A[i]:
        print('Yes')
    else:
        print("No")
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
b = a[0::2]
b1 = sorted(b, key=lambda x: b.count(x))
c = a[1::2]
c1 = sorted(c, key=lambda x: c.count(x))

if b == c:
    print(n//2)
else:
    print(n - b1.count(b1[-1]) - c1.count(c1[-1]))

### FIXED CODE ###

n = int(input())
v = list(map(int,input().split()))
v1 = sorted(v[0::2])
v2 = sorted(v[1::2])
s1 = set(v1)
s2 = set(v2)

## 偶数項・奇数項ごとに最大数および次点の値を保持
eve = [[0,0]]
odd = [[0,0]]
cnt_eve = 1
cnt_odd = 1

for i in range(1,n//2):
    ## 偶数
    if v1[i] == v1[i-1]:
        cnt_eve += 1
    else:
        eve.append([cnt_eve, v1[i-1]])
        cnt_eve = 1
    if v2[i] == v2[i-1]:
        cnt_odd += 1
    else:
        odd.append([cnt_odd, v2[i-1]])
        cnt_odd = 1
    if i == n//2 - 1:
        eve.append([cnt_eve, v1[i]])
        odd.append([cnt_odd, v2[i]])


eve.sort(key=lambda x: x[0], reverse=True)
odd.sort(key=lambda x: x[0], reverse=True)

if eve[0][1] != odd[0][1]:
    ans = n - eve[0][0] - odd[0][0]
    print(ans)
else:
    ans = n - max(eve[0][0] + odd[1][0], eve[1][0] + odd[0][0])
    print(ans)
### BUGGY CODE ###

n = int(input())
s = input()
cnt = 0
for i in range(n-2):
    for d1 in range(1, n-1-i):
        for d2 in range(1-d1, n-i-2*d1):
            if d2 != 0:
                j = i + d1
                k = i + 2*d1 + d2
                if len(set([s[i],s[j],s[k]]))==3:
                    cnt += 1
print(cnt)

### FIXED CODE ###

n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r*g*b

for i in range(n-2):
  for j in range(i+1, n-1):
    k = j + (j - i)
    if k > n-1:
    	break
    if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
      ans -= 1
print(ans)