Problem:
 Score : 300 points    Problem Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:   For each i = 1,2,..., n-2 , a_i = a_{i+2} .  Exactly two different numbers appear in the sequence.   You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.      Constraints  2 \leq n \leq 10^5  n is even.  1 \leq v_i \leq 10^5  v_i is an integer.         Input Input is given from Standard Input in the following format:  n  v_1  v_2  ...  v_n       Output Print the minimum number of elements that needs to be replaced.        Sample Input 1 4
3 1 3 2      Sample Output 1 1  The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1 .       Sample Input 2 6
105 119 105 119 105 119      Sample Output 2 0  The sequence 105,119,105,119,105,119 is /\/\/\/.       Sample Input 3 4
1 1 1 1      Sample Output 3 2  The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.

Solution (Python):
import sys
from collections import Counter

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    n = in_n()
    v = in_nl()
    c1 = Counter(v[::2]).most_common()
    c2 = Counter(v[1::2]).most_common()
    if c1[0][0] == c2[0][0]:
        if len(c1) == 1 and len(c2) == 1:
            count = n // 2
        elif len(c1) == 1:
            count = n // 2 + c2[1][1]
        elif len(c2) == 1:
            count = n // 2 + c1[1][1]
        else:
            count = max(c1[0][1] + c2[1][1], c1[1][1] + c2[0][1])
    else:
        count = c1[0][1] + c2[0][1]
    print(n - count)


if __name__ == '__main__':
    main()

Solution (Python):
import collections
N =int(input())
V =list(map(int,input().split()))
ev_col = collections.Counter(V[::2]).most_common()
od_col = collections.Counter(V[1::2]).most_common()

if ev_col[0][0] != od_col[0][0]:
    ans = N - od_col[0][1] - ev_col[0][1]
else:
    if len(ev_col) >= 2 and len(od_col)  >= 2:
        if ev_col[1][1] >= od_col[1][1]:
            ans = N - ev_col[1][1] - od_col[0][1]
        else:
            ans = N - od_col[1][1] - ev_col[0][1]
    else:
        ans = N - ev_col[0][1]
print(ans)

Solution (Python):
'''
Accepted    　:No
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :分
WAの回数　     :回
合計時間　　  　:分
'''
import collections
def myAnswer(N:int,V:list) -> int:
   odd = []
   even = []
   if len(set(V)) == 1:
      return N//2

   for n,v in enumerate(V):
      even.append(v) if n % 2 == 0 else odd.append(v)
   
   oddCounter = collections.Counter(odd)
   evenCounter = collections.Counter(even)
   oddCounter = sorted(oddCounter.items(),key=lambda x:x[1])
   evenCounter = sorted(evenCounter.items(),key=lambda x:x[1])
   oddMAX = oddCounter[-1][0]
   evenMAX = evenCounter[-1][0]
   if oddMAX == evenMAX:
      evenLen = len(evenCounter)
      oddLen = len(oddCounter)
      if evenLen >= 2 and oddLen >= 2:
         if evenCounter[-2][1] > oddCounter[-2][1]:
            evenMAX = evenCounter[-2][0]
         else:
            oddMAX = oddCounter[-2][0]
      elif evenLen >= 2:
         evenMAX = evenCounter[-2][0]
      else:
         oddMAX = oddCounter[-2][0]

   
   total = 0
   for n,v in enumerate(V):
      if n % 2 == 1:
         if oddMAX != v:
            total += 1
      else:
         if evenMAX != v:
            total += 1
   return total
def modelAnswer():
   return
def main():
   N = int(input())
   V = list(map(int,input().split()))
   print(myAnswer(N,V))


if __name__ == '__main__':
   main()

Solution (Python):
n = int(input())
v = list(map(int, input().split()))

u = v[1::2] 
d = v[0::2] 

U = [0] * 100010
for i in range(len(u)): 
    U[u[i]] += 1
    
D = [0] * 100010
for i in range(len(d)): 
    D[d[i]] += 1
   
if U.index(max(U)) == D.index(max(D)): 
    u = sorted(U, reverse=True)
    d = sorted(D, reverse=True)
    s = n - u[1] - d[0] if u[1] > d[1] else n - u[0] - d[1]
    print(s)
    exit()
    
print(n - max(U) - max(D))

Solution (Python):
n = int(input())
v = list(map(int, input().split()))

u = v[1::2] 
d = v[0::2] 

U = [0] * 100010
for i in range(len(u)): 
    U[u[i]] += 1
    
D = [0] * 100010
for i in range(len(d)): 
    D[d[i]] += 1
   
if U.index(max(U)) == D.index(max(D)): 
    u = sorted(U, reverse=True)
    d = sorted(D, reverse=True)
    s = n - u[1] - d[0] if u[1] > d[1] else n - u[0] - d[1]
    print(s)
    exit()
    
print(n - max(U) - max(D))

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import Counter



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

v0 = v[0:n-1:2]
v1 = v[1:n:2]

c0 = Counter(v0).most_common()
c1 = Counter(v1).most_common()


if len(set(v0)) == len(set(v1)) == 1:
    if c0[0] == c1[0]:
        ans = len(v0)
    else:
        ans = 0
else:
    if c0[0] != c1[0]:
        ans = n - c0[0][1] - c1[0][1]
    else:
        ans = min(n - c0[0][1] - c1[1][1], n - c0[1][1] - c1[0][1])
print(ans)

Solution (Python):
import collections


def solve():

    n = int(input())
    v = list(map(int, input().split()))
    v0 = v[::2]
    v0_counter = collections.Counter(v0).most_common()
    v1 = v[1::2]
    v1_counter = collections.Counter(v1).most_common()

    if v0_counter[0][0] != v1_counter[0][0]:
        print(n - v0_counter[0][1] - v1_counter[0][1])
        exit()
    else:
        if len(v0_counter) == 1 or len(v1_counter) == 1:
            print(n // 2)
            exit()
        else:
            print(n - max(v0_counter[0][1] + v1_counter[1][1], v0_counter[1][1] + v1_counter[0][1]))


if __name__ == '__main__':
    solve()

Solution (Python):
from collections import Counter

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

v0 = v[0:n-1:2]
v1 = v[1:n:2]

c0 = Counter(v0).most_common()
c1 = Counter(v1).most_common()

if len(set(v0)) == len(set(v1)) == 1:
    if c0[0] == c1[0]:
        res = len(v0)
    else:
        res = 0

else:
    if c0[0] != c1[0]:
        res = n - c0[0][1] - c1[0][1]
    else:
        res = min(n - c0[0][1] - c1[1][1], n - c0[1][1] - c1[0][1])

print(res)

Solution (Python):
from collections import Counter

n = int(input())
L = list(map(int, input().split()))
L1 = L[::2]
L2 = L[1::2]
c1 = Counter(L1).most_common()
c2 = Counter(L2).most_common()
if len(set(L1)) == len(set(L2)) == 1:
    if c1[0] == c2[0]:
        print(len(L1))
    else:
        print(0)
else:
    if c1[0] != c2[0]:
        print(n - c1[0][1] - c2[0][1])
    else:
        print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))

Solution (Python):
N = int(input())
V = list(map(int, input().split()))

V_ODD = [v for i,v in enumerate(V) if i%2==1]
V_EVEN = [v for i,v in enumerate(V) if i%2==0]

import collections

V_ODD_SORTED = sorted(list(zip(collections.Counter(V_ODD).values(), collections.Counter(V_ODD).keys())), reverse=True)
V_EVEN_SORTED = sorted(list(zip(collections.Counter(V_EVEN).values(), collections.Counter(V_EVEN).keys())), reverse=True)

ans_list = []

if V_ODD_SORTED[0][1] == V_EVEN_SORTED[0][1]:
    if len(V_ODD_SORTED) > 1:
        tmp = len(V)//2 - V_ODD_SORTED[1][0]
        tmp += len(V)//2 - V_EVEN_SORTED[0][0]
        ans_list.append(tmp)
        
    if len(V_EVEN_SORTED) > 1:
        tmp = len(V)//2 - V_ODD_SORTED[0][0]
        tmp += len(V)//2 - V_EVEN_SORTED[1][0]
        ans_list.append(tmp)

    if len(V_ODD_SORTED) == 1 and len(V_EVEN_SORTED) == 1:
        ans_list.append(len(V)//2)
        
else:
    tmp = len(V)//2 - V_ODD_SORTED[0][0]
    tmp += len(V)//2 - V_EVEN_SORTED[0][0]
    ans_list.append(tmp)
    
print(min(ans_list))

Solution (Python):
n = int(input())
v = list(map(int, input().split()))

if len(set(v)) == 1:
    print(n // 2)
else:
    cnt_even = [[0, i] for i in range(10 ** 5 + 1)]
    cnt_odd = [[0, i] for i in range(10 ** 5 + 1)]
    for i in range(n):
        if i % 2 == 0:
            cnt_even[v[i]][0] += 1
        else:
            cnt_odd[v[i]][0] += 1

    cnt_even.sort()
    cnt_odd.sort()

    if cnt_even[-1][1] == cnt_odd[-1][1]:
        print(n - max(cnt_even[-1][0] + cnt_odd[-2][0], cnt_even[-2][0] + cnt_odd[-1][0]))
    else:
        print(n - cnt_even[-1][0] - cnt_odd[-1][0])

Solution (Python):
from collections import Counter
N = int(input())
numbers = [int(i) for i in input().split()]

o = Counter(numbers[::2]).most_common()
e = Counter(numbers[1::2]).most_common()

if o[0][0] == e[0][0]:
    if len(o) == 1:
        output = N // 2
    else :
        e1, e2 = e[0][1], e[1][1]
        o1, o2 = o[0][1], o[1][1]
        
        output = min(N-e1-o2, N-e2-o1)
else :
    output = N - o[0][1] - e[0][1]

print(output)

Solution (Python):
from collections import Counter
 
N = int(input())
l = list(map(int, input().split()))
 
o = Counter(l[::2]).most_common()
e = Counter(l[1::2]).most_common()
 
if o[0][0] == e[0][0]:
    if len(o) == 1:
        print(N//2)
    else:
        e1, e2 = o[0][1], o[1][1]
        o1, o2 = e[0][1], e[1][1]
 
        res = min(N-e1-o2, N-e2-o1)
        print(res)
else:
    print(N - o[0][1] - e[0][1])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))

odd={}
even={}
total={}

for i in range(n):
    t=a[i]
    if i%2==0:
        if t in odd:
            odd[t]+=1
        else:
            odd[t]=1
    else:
        if t in even:
            even[t]+=1
        else:
            even[t]=1
    if t in total:
        total[t]+=1
    else:
        total[t]=1

l=len(odd)+len(even)

odd=sorted(odd.items(),key=lambda x: x[1],reverse=True)
even=sorted(even.items(),key=lambda x: x[1],reverse=True)
total=sorted(total.items(),key=lambda x: x[1],reverse=True)

ans=0

if len(total)==1:
    print(n//2)
    exit(0)

ans=n
cnt1=0
for i in odd:
    if cnt1==2:
        break
    cnt2=0
    for j in even:
        if cnt2==2 or i[0]==j[0]:
            continue
    
        ans=min(ans,n-i[1]-j[1])
        cnt2+=1
    cnt1+=1

print(ans)

Solution (Python):
from collections import Counter

N = int(input())
V = tuple(map(int, input().split(' ')))

v1 = V[::2]
v2 = V[1::2]

v1_count = Counter(v1)
v1_count[-1] = 0
v2_count = Counter(v2)
v2_count[-1] = 0

v1 = sorted([(value, key) for key, value in v1_count.items()], reverse=True)
v2 = sorted([(value, key) for key, value in v2_count.items()], reverse=True)

if v1[0][1] == v2[0][1]:
    print(min(N - v1[0][0] - v2[1][0], N - v2[0][0] - v1[1][0]))
else:
    print(N - v1[0][0] - v2[0][0])

Solution (Python):
n = int(input())
V = list(map(int, input().split()))

import sys
from collections import Counter

C0 = Counter(V[0::2])
C1 = Counter(V[1::2])

n0 = C0.most_common()[0][0]
n1 = C1.most_common()[0][0]

minV = min(V)
if all([v == minV for v in V]):
    print(len(V)//2)
    sys.exit()

if n0 == n1:
    if C0.most_common()[1][1] >= C1.most_common()[1][1]:
        n0 = C0.most_common()[1][0]
    else:
        n1 = C1.most_common()[1][0]
    
count = 0
for v in V[0::2]:
    if v != n0:
        count += 1

for v in V[1::2]:
    if v != n1:
        count += 1
print(count)

Solution (Python):
n = int(input())
v = [0] + list(map(int, input().split()))

odd = [v[i] for i in range(1, n+1, 2)]
even = [v[i] for i in range(2, n+1, 2)]

from collections import Counter
counter_odd = dict(Counter(odd))
counter_even = dict(Counter(even))

counter_odd[0] = 0
counter_even[0] = 0

counter_odd = list(counter_odd.items())
counter_even = list(counter_even.items())

counter_odd.sort(reverse=True, key=lambda x: x[1])
counter_even.sort(reverse=True, key=lambda x: x[1])

max_odd = counter_odd[0]
max_even = counter_even[0]

if max_odd[0] != max_even[0]:
    ans = len(odd) - max_odd[1] + len(even) - max_even[1]
    print(ans)
else: 
    semi_max_odd = counter_odd[1]
    semi_max_even = counter_even[1]
    loss_odd = max_odd[1] - semi_max_odd[1]
    loss_even = max_even[1] - semi_max_even[1]
    if loss_odd < loss_even:
        ans = len(odd) - semi_max_odd[1] + len(even) - max_even[1]
    else:
        ans = len(odd) - max_odd[1] + len(even) - semi_max_even[1]
    print(ans)

Solution (Python):

import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


def zz():
    return list(map(int, input().split()))


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


n = z()
v = zz()
a_lis = v[0::2]
b_lis = v[1::2]

a_all = [0]*(1 + 10**5)
b_all = [0]*(1 + 10**5)
for a in a_lis:
    a_all[a] += 1

for b in b_lis:
    b_all[b] += 1
nums = list(range(0, len(a_all)))
a_all = zip(a_all, nums)
b_all = zip(b_all, nums)
a_all = sorted(a_all, reverse=True)
b_all = sorted(b_all, reverse=True)

a_num_1, fixed_a_value = a_all[0]
b_num_1, fixed_b_value = b_all[0]
a_num_2 = a_num_1
b_num_2 = b_num_1

if (fixed_a_value == fixed_b_value):
    a_num_1, fixed_a_value = a_all[0]
    b_num_1, fixed_b_value = b_all[1]
    a_num_2, fixed_a_value = a_all[1]
    b_num_2, fixed_b_value = b_all[0]

ans = min(n-a_num_1-b_num_1, n-a_num_2-b_num_2)
print(ans)

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
dic1,dic2 = {},{}
c1,c2=0,0
for i in range(0,n,2):
  if v[i] in dic1.keys():
    dic1[v[i]] += 1
  else:
    dic1[v[i]] = 1
  c1 += 1

for i in range(1,n,2):
  if v[i] in dic2.keys():
    dic2[v[i]] += 1
  else:
    dic2[v[i]] = 1
  c2 += 1

dic1 = sorted(dic1.items(), key = lambda x : x[1], reverse=True)
dic2 = sorted(dic2.items(), key = lambda x : x[1], reverse=True)
if len(dic1) == 1:
  dic1.append((0,0))
if len(dic2) == 1:
  dic2.append((0,0))

ans = 0
if dic1[0][0] != dic2[0][0]:
  ans = c1 - dic1[0][1] + c2 - dic2[0][1]
else:
  x = c1 - dic1[0][1] + c2 - dic2[1][1]
  y = c1 - dic1[1][1] + c2 - dic2[0][1]
  ans = min(x,y)

print(ans)

Solution (Python):

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

u = v[1::2]
d = v[0::2]
    



U = [0] * 100010
for i in range(len(u)):
    U[u[i]] += 1
    
D = [0] * 100010
for i in range(len(d)):
    D[d[i]] += 1
   
if U.index(max(U)) == D.index(max(D)):
    u = sorted(U, reverse=True)
    d = sorted(D, reverse=True)
    s = n - u[1] - d[0] if u[1] > d[1] else n - u[0] - d[1]
    print(s)
    exit()
    
print(n - max(U) - max(D))

Solution (Python):
import sys
from collections import Counter
n=int(input())
v=[int(x) for x in input().split()]

v1=[] 
v2=[] 

for i in range(n):
    if i%2==0:
        v1.append(v[i])
    else:
        v2.append(v[i])

m1=Counter(v1).most_common()
m2=Counter(v2).most_common()




ans=0
for i in range(min(len(m1),len(m2))):
    
    if m1[i][0]!=m2[i][0]:
        ans=sum(list(m1[j][1] for j in range(i+1,len(m1))))+sum(list(m2[j][1] for j in range(i+1,len(m2))))
        print(ans)
        sys.exit()
    
    else:
        
        if m1[i][1]>m2[i][1]:
            ans=m2[i][1]+sum(list(m1[j][1] for j in range(i+1,len(m1))))+sum(list(m2[j][1] for j in range(i+2,len(m2))))
            print(ans)
            sys.exit()
        
        
        elif m1[i][1]<m2[i][1]:
            ans=m1[i][1]+sum(list(m1[j][1] for j in range(i+2,len(m1))))+sum(list(m2[j][1] for j in range(i+1,len(m2))))
            print(ans)
            sys.exit()
            
        
        else:
            
            cnt1=m1[i][1]+sum(list(m1[j][1] for j in range(i+2,len(m1)))) + sum(list(m2[j][1] for j in range(i+1,len(m2))))
            cnt2=m2[i][1]+sum(list(m2[j][1] for j in range(i+2,len(m2)))) + sum(list(m1[j][1] for j in range(i+1,len(m1))))
            ans=min(cnt1,cnt2)
            print(ans)
            sys.exit()

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
d1 = {}
d2 = {}

for i in range(0,n//2):
  a1 = v[2*i]
  a2 = v[2*i+1]
  
  if a1 not in d1:
    d1[a1] = 1
  else:
    d1[a1] += 1
    
  if a2 not in d2:
    d2[a2] = 1
  else:
    d2[a2] += 1


l1 = list(sorted(d1.items(), key=lambda x:x[1]))
l2 = list(sorted(d2.items(), key=lambda x:x[1]))


if len(set(v)) == 1:
  print(n//2)
  exit()
if l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) >= 2:
  print(min(n - l1[-1][1] - l2[-2][1],n - l1[-2][1] - l2[-1][1]))
elif l1[-1][0] == l2[-1][0] and len(l1) == 1 and len(l2) >= 2:
  print(n - l1[-1][1] - l2[-2][1])
elif l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) == 1:
  print(n - l1[-2][1] - l2[-1][1])
else:
  print(n - l1[-1][1] - l2[-1][1])

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
a = l()
b1 = []
b2 = []
for i in range(N):
    if i%2==0:
        b1.append(a[i])
    else:
        b2.append(a[i])
c1 = Counter(b1)
c2 = Counter(b2)
k1,v1 = c1.most_common()[0]
k2,v2 = c2.most_common()[0]
ans = v1+v2
v3 = 0
v4 = 0
if k1 == k2:
    if len(list(c2.values())) > 1:
        v4 = c2.most_common()[1][1]
    if len(list(c1.values())) > 1:
        v3 = c1.most_common()[1][1]
    ans = max(v1+v4,v2+v3)
print(N-ans)

Solution (Python):
from collections import Counter

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

x = Counter(v[::2]).most_common(2)
y = Counter(v[1::2]).most_common(2)
ans = n
if x[0][0] == y[0][0]:
  if len(x) == len(y) == 1:
    ans = n//2
  else:
    s = max([a[1] for a in x]) + min([b[1] for b in y])
    t = min([a[1] for a in x]) + max([b[1] for b in y])
    ans -= max(s, t)
else:
  ans -= x[0][1] + y[0][1]
print(ans)

Solution (Python):
from collections import*
n,*v=map(int,open(0).read().split())
a,b=[Counter(v[i::2]).most_common()+[(0,0)]for i in(0,1)]
s,x=a[0]
t,y=b[0]
print(n-[x+y,max(x+b[1][1],y+a[1][1])][s==t])

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
a=n//2
dp=[[0,0]for i in range(10**5+1)]
bp=[[0,0]for i in range(10**5+1)]
for i in range(n):
  if i%2==0:
    dp[v[i]][0]+=1
    dp[v[i]][1]=v[i]
  else:
    bp[v[i]][0]+=1
    bp[v[i]][1]=v[i]
dp.sort(reverse=True)
bp.sort(reverse=True)
if bp[0][1]==dp[0][1]:
  if dp[1][0]>=bp[1][0]:
    dp[0][0]=dp[1][0]
  else:
    bp[0][0]=bp[1][0]
print(a-dp[0][0]+a-bp[0][0])

Solution (Python):
from collections import Counter

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    n = ii()
    v = list(mi())
    ve = [v[i] for i in range(n) if i%2==0]
    vo = [v[i] for i in range(n) if i%2==1]

    ce = Counter(ve)
    co = Counter(vo)

    if ce.most_common()[0][0] == co.most_common()[0][0]:
        if len(ce.most_common()) > 1 and len(co.most_common()) > 1:
            if ce.most_common()[1][1] > co.most_common()[1][1]:
                ne = ce.most_common()[1][1]
                no = ce.most_common()[0][1]
            else:
                ne = ce.most_common()[0][1]
                no = co.most_common()[1][1]
        else:
            ne = ce.most_common()[0][1]
            no = 0
    else:
        ne = ce.most_common()[0][1]
        no = co.most_common()[0][1]

    print(n-ne-no)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
a=Counter(v[0::2]).most_common()
b=Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0]!=b[0][0]:print(n-(a[0][1]+b[0][1]))
else:print(n-max(a[0][1]+b[1][1],a[1][1]+b[0][1]))

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
a=Counter(v[0::2]).most_common()
b=Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0]!=b[0][0]:
    print(n-(a[0][1]+b[0][1]))
else:
    print(min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1])))

Solution (Python):
from collections import Counter
d = [Counter(), Counter()]
n = int(input())
v = list(map(int, input().split()))
for i, vi in enumerate(v):
    d[i&1][vi] += 1
a = []
for i in range(2):
    a.append(sorted(d[i].keys(), key=lambda k: d[i][k], reverse=True))
c = [ai[:2] for ai in a]
if len(c[0]) == len(c[1]) == 1 and c[0][0] == c[1][0]:
    print(n // 2)
else:
    ans = 1001001001
    for ci in c[0]:
        for cj in c[1]:
            if ci == cj:
                continue
            cnt = sum(v for k, v in d[0].items() if k != ci) + sum(v for k, v in d[1].items() if k != cj)
            ans = min(ans, cnt)
    print(ans)

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v1 = v[::2]
v2 = v[1::2]
C1 = Counter(v1)
C2 = Counter(v2)
if C1.most_common(1)[0][0]!=C2.most_common(1)[0][0]: 
  print((n//2-C1.most_common(1)[0][1])+(n//2-C2.most_common(1)[0][1]))
elif C1.most_common(1)[0][1]==C2.most_common(1)[0][1]==n//2:
  print(n//2)
elif C1.most_common(1)==C2.most_common(1) and C1.most_common(2)[1][1] >= C2.most_common(2)[1][1]:
  print((n//2-C1.most_common(2)[1][1])+(n//2-C2.most_common(1)[0][1]))
else:
  print((n//2-C1.most_common(1)[0][1])+(n//2-C2.most_common(2)[1][1]))

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v1 = v[::2]
v2 = v[1::2]
C1 = Counter(v1)
C2 = Counter(v2)
if C1.most_common(1)[0][0]!=C2.most_common(1)[0][0]: 
  print((n//2-C1.most_common(1)[0][1])+(n//2-C2.most_common(1)[0][1]))
elif C1.most_common(1)[0][1]==C2.most_common(1)[0][1]==n//2:
  print(n//2)
elif C1.most_common(1)==C2.most_common(1) and C1.most_common(2)[1][1] >= C2.most_common(2)[1][1]:
  print((n//2-C1.most_common(2)[1][1])+(n//2-C2.most_common(1)[0][1]))
else:
  print((n//2-C1.most_common(1)[0][1])+(n//2-C2.most_common(2)[1][1]))

Solution (Python):
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
even = [[0,i] for i in range(10**5+5)]
odd = [[0,i] for i in range(10**5+5)]
numnum = 0
for i in range(n):
    if even[v[i]][0] == 0 and odd[v[i]][0] == 0:
        numnum += 1
    if i % 2 == 0:
        even[v[i]][0] += 1
    else:
        odd[v[i]][0] += 1
if numnum == 1:
    print(n // 2)
    exit()
even.sort(key=lambda x:x[0], reverse=True)
odd.sort(key=lambda x:x[0], reverse=True)
if n == 2:
    print(0)
    exit()
e0, e1, o0, o1 = even[0][1], even[1][1], odd[0][1], odd[1][1]
if e0 != o0:
    print(n - even[0][0] - odd[0][0])
elif e0 != o1 and e1 != o0:
    print(min(n - even[0][0] - odd[1][0], n - even[1][0] - odd[0][0]))
elif e0 != o1:
    print(n - even[0][0] - odd[1][0])
else:
    print(n - even[1][0] - odd[0][0])

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v1 = v[::2]
v2 = v[1::2]

C1 = Counter(v1)
C2 = Counter(v2)



if C1.most_common(1)[0][0]!=C2.most_common(1)[0][0]: 
  print((n//2-C1.most_common(1)[0][1])+(n//2-C2.most_common(1)[0][1]))
  exit()
  
elif C1.most_common(1)[0][1]==C2.most_common(1)[0][1]==n//2:
  print(n//2)
  exit()
  
elif C1.most_common(1)==C2.most_common(1) and C1.most_common(2)[1][1] >= C2.most_common(2)[1][1]:
  print((n//2-C1.most_common(2)[1][1])+(n//2-C2.most_common(1)[0][1]))
  exit()

else:
  print((n//2-C1.most_common(1)[0][1])+(n//2-C2.most_common(2)[1][1]))
  exit()

Solution (Python):
from collections import Counter

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

e=Counter(v[::2]).most_common() + [(0,0)]
o=Counter(v[1::2]).most_common() + [(0,0)]


if e[0][0]!=o[0][0]:
    print(n-e[0][1]-o[0][1])
else:
    print(min(n-e[0][1]-o[1][1],n-e[1][1]-o[0][1]))

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

Aone = A[0]
counter = 0

for i in range (0, n):
	if A[i] == Aone:
		counter+=1
	else:
		break

if counter == n:
	print(int(n/2))
	exit()

k = int(len(A)/2)
maxA = max(A)

Odd = []
Even = []

for i in range (0, k):
	Odd.append(A[2*i])
	Even.append(A[2*i+1])

Oddcount = [0]*maxA
Evencount = [0]*maxA

for i in range (0, k):
	Oddcount[Odd[i]-1]+=1
	Evencount[Even[i]-1]+=1

Oddcount2 = sorted(Oddcount.copy())
Evencount2 = sorted(Evencount.copy())

if Oddcount.index(Oddcount2[-1]) != Evencount.index(Evencount2[-1]):
	print(2*k-Oddcount2[-1]-Evencount2[-1])
elif Oddcount2[-2] >= Evencount2[-2]:
	print(2*k-Oddcount2[-2]-Evencount2[-1])
else:
	print(2*k-Oddcount2[-1]-Evencount2[-2])

Solution (Python):
import itertools
from collections import Counter


n = int(input())
v = list(map(int, input().split()))
ev_cnt = Counter(v[::2])
od_cnt = Counter(v[1::2])
ev_cnt[-1] = 0
od_cnt[-2] = 0
ev = ev_cnt.most_common(2)
od = od_cnt.most_common(2)
ans = n
for (k1, v1), (k2, v2) in itertools.product(ev, od):
    if k1 == k2:
        continue
    x = (n - v1 - v2)
    ans = min(ans, x)
print(ans)

Solution (Python):
n=int(input())
v=list(map(int, input().split()))
even=[0]*(10**6 + 1)
odd=[0]*(10**6 + 1)



for i in range(n):
    if i%2==0:
        even[v[i]]+=1
    else:
        odd[v[i]]+=1

a=max(even)
M=even.index(a)
even[M]=0
a_second=max(even)
even[M]=a

b=max(odd)
N=odd.index(b)
odd[N]=0
b_second=max(odd)
odd[N]=b


if M!=N:
    ans=sum(even)-a + sum(odd)-b
    print(ans)
else:
    ans=min(sum(even)-a + sum(odd)-b_second, sum(even)-a_second + sum(odd)-b)
    print(ans)

Solution (Python):
n=int(input())
v=list(map(int, input().split()))
even=[0]*(10**6 + 1)
odd=[0]*(10**6 + 1)



for i in range(n):
    if i%2==0:
        even[v[i]]+=1
    else:
        odd[v[i]]+=1

a=max(even)
M=even.index(a)
even[M]=0
a_second=max(even)
even[M]=a

b=max(odd)
N=odd.index(b)
odd[N]=0
b_second=max(odd)
odd[N]=b


if M!=N:
    ans=sum(even)-a + sum(odd)-b
    print(ans)
else:
    ans=min(sum(even)-a + sum(odd)-b_second, sum(even)-a_second + sum(odd)-b)
    print(ans)

Solution (Python):
n=int(input())
V=list(map(int,input().split()))

A=[V[i] for i in range(0,n,2)]
B=[V[i] for i in range(1,n,2)]

import collections
  
C = collections.Counter(A)
D = collections.Counter(B)
  
if C.most_common()[0][0] != D.most_common()[0][0]:
  print(len(A)+len(B)-C.most_common()[0][1]-D.most_common()[0][1])
else:
  if len(C)!=1 and len(D)!=1:
    print( min(len(A)+len(B)-C.most_common()[0][1]-D.most_common()[1][1],
            len(A)+len(B)-C.most_common()[1][1]-D.most_common()[0][1]) )
  elif len(C)!=1 and len(D)==1:
    print( min(len(A)+len(B)-C.most_common()[0][1]-D.most_common()[0][1],
            len(A)+len(B)-C.most_common()[1][1]-D.most_common()[0][1]) )
  elif len(C)==1 and len(D)!=1:
    print( min(len(A)+len(B)-C.most_common()[0][1]-D.most_common()[1][1],
            len(A)+len(B)-C.most_common()[0][1]-D.most_common()[0][1]) )
  else:
    print(min(len(A),len(B)))

Solution (Python):
from collections import Counter

n = int(input())

lis = list(map(int, input().split()))

t = len(lis)

a = Counter(lis[0::2]).most_common()
b = Counter(lis[1::2]).most_common()


ans2 = 1001001001
ans3 = 1001001001
ans4 = 1001001001

if a[0][0] != b[0][0]:
    ans = t - a[0][1] - b[0][1]
    print(ans)
    
else:
    if len(a) != 1:
        ans2 = t - a[1][1] - b[0][1]
    if len(b) != 1:
        ans3 = t - a[0][1]-b[1][1]
    else:
        ans4 = t/2
        
    print(int(min(ans2, ans3, ans4)))

Solution (Python):
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
A = Counter(V[0::2]).most_common(2)
B = Counter(V[1::2]).most_common(2)
A.append((0,0))
B.append((0,0))
if A[0][0]!=B[0][0]:
    print(n-(A[0][1]+B[0][1]))
else:
    print(min(n-(A[1][1]+B[0][1]),n-(A[0][1]+B[1][1])))

Solution (Python):
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
a=Counter(V[0::2]).most_common(2)
b=Counter(V[1::2]).most_common(2)
a.append((0,0))
b.append((0,0))
if a[0][0]!=b[0][0]:
    print(n-(a[0][1]+b[0][1]))
else:
    print(min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1])))

Solution (Python):
from collections import Counter
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A1 = A[::2]
    A2 = A[1::2]
    C1 = Counter(A1).most_common()
    C2 = Counter(A2).most_common()
    if len(set(A)) == 1:
        print(n // 2)
    elif C1[0][0] == C2[0][0]:
        print(n - max(C1[0][1] + C2[1][1], C1[1][1] + C2[0][1]))
    else:
        print(n - C1[0][1] - C2[0][1])

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v1, v2 = v[::2], v[1::2]
vv1 = Counter(v1).most_common()
vv2 = Counter(v2).most_common()

if len(set(v)) == 1:
    print(n//2)
elif vv1[0] != vv2[0]:
    print(n - vv1[0][1] - vv2[0][1])
else:
    print(n - max(vv1[1][1] + vv2[0][1], vv1[0][1] + vv2[1][1]))

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v1, v2 = [], []
for i in range(n):
    if i%2:
        v1.append(v[i])
    else:
        v2.append(v[i])
vv1 = Counter(v1).most_common()
vv2 = Counter(v2).most_common()
if vv1[0] != vv2[0]:
    print(n - vv1[0][1] - vv2[0][1])
else:
    if len(vv1) == len(vv2) == 1:
        print(n - max(vv1[0][1], vv2[0][1]))
    elif len(vv1) == 1 and len(vv2) == 2:
        print(n - vv1[0][1] - vv2[1][1])
    elif len(vv1) == 2 and len(vv2) == 1:
        print(n - vv1[1][1] - vv2[0][1])
    else:
        print(n - max(vv1[1][1] + vv2[0][1], vv1[0][1] + vv2[1][1]))

Solution (Python):
import sys, re
from math import ceil, floor, sqrt, pi, factorial
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext

def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    num_list = i_list()

    zero_list = []
    one_list = []
    for i in range(n):
        if i % 2 == 0:
            zero_list.append(num_list[i])
        else:
            one_list.append(num_list[i])

    zero_c = Counter(zero_list)
    one_c = Counter(one_list)

    zero_saihin_key = zero_c.most_common()[0][0]
    zero_saihin_val = zero_c.most_common()[0][1]
    one_saihin_key = one_c.most_common()[0][0]
    one_saihin_val = one_c.most_common()[0][1]

    if zero_saihin_key != one_saihin_key:
        print(n - zero_saihin_val - one_saihin_val)
        exit()

    if num_list.count(zero_saihin_key) == n:
        print(n//2)
        exit()

    if len(zero_c) == 1:
        zero_saihin_val2 = zero_saihin_val
    else:
        zero_saihin_val2 = zero_c.most_common()[1][1]

    if len(one_c) == 1:
        one_saihin_val2 = one_saihin_val
    else:
        one_saihin_val2 = one_c.most_common()[1][1]

    count1 = n - zero_saihin_val - one_saihin_val2
    count2 = n - zero_saihin_val2 - one_saihin_val

    print(min(count1, count2))

if __name__ == '__main__':
    main()