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):
n  = int(input())
v = list(map(int, input().split()))

v0 =[]
v1 =[]

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

v0_count = [[0,0]]
v1_count = [[0,0]]


k = 0
for i in range(n//2):
  if v0[i] == v0_count[k][0]:
    v0_count[k][1] += 1
  else:
    v0_count.append([v0[i],1])
    k += 1


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

k = 0
for i in range(n//2):
  if v1[i] == v1_count[k][0]:
    v1_count[k][1] += 1
  else:
    v1_count.append([v1[i],1])
    k += 1


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

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

Solution (Python):
n=int(input())
V=list(map(int,input().split()))
O=[]
E=[]
for i in range(n//2):
    O.append(V[2*i])
    E.append(V[2*i+1])
O.sort()
E.sort()
CO=[]
CE=[]
no=O[0]
co=0
ne=E[0]
ce=0
for i in range(n//2):
    if O[i]==no:
        co+=1
    else:
        CO.append([co,no])
        co=1
        no=O[i]
    if E[i]==ne:
        ce+=1
    else:
        CE.append([ce,ne])
        ce=1
        ne=E[i]
CO.append([co,no])
CE.append([ce,ne])

CO=list(reversed(sorted(CO)))
CE=list(reversed(sorted(CE)))

if CO[0][1]==CE[0][1]:
    if len(CO)==1 and len(CE)==1:
        print(n//2)
    elif len(CO)==1:
        print(n-CO[0][0]-CE[1][0])
    elif len(CE)==1:
        print(n-CO[1][0]-CE[0][0])
    else:
        print(n-max(CO[0][0]+CE[1][0],CO[1][0]+CE[0][0]))
else:
    print(n-CO[0][0]-CE[0][0])

Solution (Python):


import fractions
import math
import io

data=int(input())

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

ki=[0]*100001
gu=[0]*100001

for i in range(data):
    if i%2==0:
        ki[array[i]]+=1
    else:
        gu[array[i]]+=1
km1=[max(ki),ki.index(max(ki))]
km2=[sorted(ki)[-2],ki.index(sorted(ki)[-2])]
gm1=[max(gu),gu.index(max(gu))]
gm2=[sorted(gu)[-2],gu.index(sorted(gu)[-2])]

if km1[1]!=gm1[1]:
    print(data-km1[0]-gm1[0])
else:
    if km1[0]-km2[0]>=gm1[0]-gm2[0]:
        print(data-km1[0]-gm2[0])
    else:
        print(data-gm1[0]-km2[0])

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
if n==2 and v[0]==v[1]:
    print(1)
else:
    c_e=[]
    c_o=[]
    for h in range(max(v)+1):
        c_e.append([0,h])
        c_o.append([0,h])

    for i in range(n):
        num=v[i]
        if i%2==0:
            c_e[num][0]+=1
        else:
            c_o[num][0]+=1

    c_e.sort(reverse=True)
    c_o.sort(reverse=True)
    ae=c_e[0][0]
    ao=c_o[0][0]

    if c_e[0][1]==c_o[0][1]:
        ae2=c_e[1][0]
        ao2=c_o[1][0]
        if ae2>=ao2:
            ae=ae2
        else:
            ao=ao2
            
    print(n-ae-ao)

Solution (Python):


import collections

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

v_even = collections.Counter(V[0::2])
v_odd  = collections.Counter(V[1::2])

v_even_s = sorted(v_even.items(), key=lambda x:x[1], reverse=True)
v_odd_s  = sorted(v_odd.items(), key=lambda x:x[1], reverse=True)

if len(set(V)) == 1:
    print(int(len(V)/2))
elif v_even_s[0][0] == v_odd_s[0][0]:
    if v_even_s[0][1] > v_odd_s[0][1]:
        print(len(V) - v_even_s[0][1] - v_odd_s[1][1])
    elif v_even_s[0][1] < v_odd_s[0][1]:
        print(len(V) - v_even_s[1][1] - v_odd_s[0][1])
    else:
        if v_even_s[1][1] > v_odd_s[1][1]:
            print(len(V) - v_even_s[1][1] - v_odd_s[0][1])
        else:
            print(len(V) - v_even_s[0][1] - v_odd_s[1][1])
else:
    print(len(V) - v_even_s[0][1] - v_odd_s[0][1])

Solution (Python):
import collections
n = int(input())
v_ls = list(map(int, input().split()))

v_ls0 = [0] * (n//2)
v_ls1 = [0] * (n//2)
for i in range(n):
    if i % 2 == 0:
        v_ls0[i//2] = v_ls[i]
    else:
        v_ls1[i//2] = v_ls[i]
counter0 = collections.Counter(v_ls0)
counter1 = collections.Counter(v_ls1)
value01, count01 = counter0.most_common(2)[0]
if len(counter0.most_common(2)) == 1:
    value02, count02 = 0,0
else:   
    value02, count02 = counter0.most_common(2)[1]
value11, count11 = counter1.most_common(2)[0]
if len(counter1.most_common(2)) == 1:
    value12, count12 = 0,0
else:
    value12, count12 = counter1.most_common(2)[1]

if value01 != value11:
    ans = n - count01 - count11
else:
    
    ans = n - count01 - count12
    ans = min(ans, n - count11 - count02)
print(ans)

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


dl={}
for i in range(n//2):
    j=2*i
    if v[j] in dl:
        dl[v[j]]+=1
    else:
        dl[v[j]]=1


dr={}
for i in range(n//2):
    j=2*i+1
    if v[j] in dr:
        dr[v[j]]+=1
    else:
        dr[v[j]]=1

maxli=max(dl,key=dl.get)
maxri=max(dr,key=dr.get)
if maxli!=maxri:
    print(n-dl[maxli]-dr[maxri])
else:
    lr=sorted(dr.values())
    ll=sorted(dl.values())
    
    s=max(lr[-2]+ll[-1] if len(lr)>1 else ll[-1],lr[-1]+ll[-2]if len(ll)>1 else lr[-1])
    print(n-s)

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

a1 = a[::2]
a2 = a[1::2]

from collections import defaultdict

d1 = defaultdict(int)
d1[0] = 0
for ai in a1:
	d1[ai] += 1  

d2 = defaultdict(int)
d2[0] = 0
for ai in a2:
	d2[ai] += 1  

an1 = list(d1.items())
an1.sort(key = lambda x: -x[1])

an2 = list(d2.items())
an2.sort(key = lambda x: -x[1])

if an1[0][0] == an2[0][0]:
	print(n - max(an1[0][1] + an2[1][1], an1[1][1] + an2[0][1]))
else:
	print(n - an1[0][1] - an2[0][1])

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
from collections import Counter
v0,v1 = [],[]
for i in range(n):
  if i % 2 == 0:
    v0.append(v[i])
  else:
    v1.append(v[i])
n0,n1 = len(v0),len(v1)
c0 = Counter(v0).most_common()
c1 = Counter(v1).most_common()
c0.append((0,0))
c1.append((0,0))
ans = n0+n1
if c0[0][0] == c1[0][0]:
  print(ans-max(c0[0][1]+c1[1][1],c0[1][1]+c1[0][1]))
else:
  print(ans-c0[0][1]-c1[0][1])

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

even = []
odd = []
for i in range(N):
    if i % 2 == 0:
        even.append(V[i])
    else:
        odd.append(V[i])

cnt_even = {}
for e in even:
    if e not in cnt_even:
        cnt_even[e] = 1
    else:
        cnt_even[e] += 1

cnt_odd = {}
for o in odd:
    if o not in cnt_odd:
        cnt_odd[o] = 1
    else:
        cnt_odd[o] += 1

cnt_even = [[v, k] for k, v in cnt_even.items()]
cnt_odd = [[v, k] for k, v in cnt_odd.items()]
cnt_even.sort(reverse=True)
cnt_odd.sort(reverse=True)

ce = cnt_even[0][0]
ce_num = cnt_even[0][1]
ce_res = sum([v for v, k in cnt_even[1:]])

co = cnt_odd[0][0]
co_num = cnt_odd[0][1]
co_res = sum([v for v, k in cnt_odd[1:]])

if ce_num != co_num:
    print(ce_res + co_res)
else:
    if len(cnt_even) > 1 and len(cnt_odd) > 1:
        ce_res_2 = ce_res - cnt_even[1][0] + ce
        co_res_2 = co_res - cnt_odd[1][0] + co
        res = min(ce_res + co_res_2, ce_res_2 + co_res)
    elif len(cnt_even) == 1 and len(cnt_odd) > 1:
        co_res_2 = co_res - cnt_odd[1][0] + co
        res = ce_res + co_res_2
    elif len(cnt_even) > 1 and len(cnt_odd) == 1:
        ce_res_2 = ce_res - cnt_even[1][0] + ce
        res = ce_res_2 + co_res
    else:
        res = min(ce, co)
    print(res)

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


if ve[0][0] == vo[0][0]:
    if len(ve) == len(vo) == 1:
        ans = n - max(ve[0][1], vo[0][1])
    else:
        ans = n - max(ve[0][1]+vo[1][1], vo[0][1]+ve[1][1])
else:
    ans = n - ve[0][1] - vo[0][1]
print(ans)

Solution (Python):
import collections

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

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

even_cnt = collections.Counter(even)
odd_cnt = collections.Counter(odd)


if even_cnt.most_common()[0][0] != odd_cnt.most_common()[0][0]:
    ans = n - even_cnt.most_common()[0][1]- odd_cnt.most_common()[0][1]
else:
    if even_cnt.most_common()[0][1] == odd_cnt.most_common()[0][1]:
        if len(even_cnt.most_common()) >= 2:
            ans = n - even_cnt.most_common()[0][1]- max(even_cnt.most_common()[1][1],odd_cnt.most_common()[1][1])
        else:
            ans = n//2
    else:
        if even_cnt.most_common()[0][1] > odd_cnt.most_common()[0][1]:
            ans = n - even_cnt.most_common()[0][1] - odd_cnt.most_common()[1][1]
        else:
            ans = n - odd_cnt.most_common()[0][1] - even_cnt.most_common()[1][1]
print(ans)

Solution (Python):
import collections
n = int(input())
v = list(map(int, input().split()))
v1 = []
v2 = []
for i in range(n):
    if (i%2==0):
        v1.append(v[i])
    else:
        v2.append(v[i])
w1 = collections.Counter(v1)
w2 = collections.Counter(v2)
w1 = w1.most_common()
w2 = w2.most_common()

if (w1[0][0] != w2[0][0]):
    print(n-w1[0][1]-w2[0][1])
    exit()
else:
    if len(w1) ==1:
        if len(w2) ==1:
            print(n//2)
        else:
            print(n-w1[0][1]-w2[1][1])
    else:
        if len(w2) ==1:
            print(n-w2[0][1]-w1[1][1])
        else:
            if (w1[0][1]-w1[1][1]) >= (w2[0][1]-w2[1][1]):
                print(n-w1[0][1]-w2[1][1])
            else:
                print(n-w2[0][1]-w1[1][1])

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
ve = Counter(v[::2]).most_common()
vo = Counter(v[1::2]).most_common()

if ve[0][0] == vo[0][0]:
    if len(ve) == len(vo) == 1:
        ans = n - max(ve[0][1], vo[0][1])
    else:
        ans = n - max(ve[0][1]+vo[1][1], vo[0][1]+ve[1][1])
else:
    ans = n - ve[0][1] - vo[0][1]
print(ans)

Solution (Python):
import numpy as np
n = int(input())
v = list(map(int, input().split()))
gu = [0] * (10**5 + 5)
ki = [0] * (10**5 + 5)

for i in range(n):
  if i % 2:
    ki[v[i]] += 1
  else:
    gu[v[i]] += 1
ki = np.array(ki)
gu = np.array(gu)

a = np.argmax(ki)
b = np.argmax(gu)

if a != b:
  print(n-ki[a]-gu[b])
else:
  gu = sorted(gu)
  ki = sorted(ki)
  print(min(n-ki[-1] - gu[-2], n-ki[-2]-gu[-1]))

Solution (Python):
import sys
from collections import Counter
sys.setrecursionlimit(10 ** 6)

def main():
    N = int(input())
    V = list(map(int, sys.stdin.readline().rstrip().split()))
    c0 = Counter([v for i, v in enumerate((V)) if i % 2 == 0])
    c1 = Counter([v for i, v in enumerate((V)) if i % 2 == 1])

    if c0.most_common()[0][0] == c1.most_common()[0][0]:
        if len(c0.most_common()) == 1:
            m = c1.most_common()[0][1]
            print(m)
        elif len(c1.most_common()) == 1:
            m = c0.most_common()[0][1]
            print(m)
        else:
            m = max(c0.most_common()[0][1] + c1.most_common()[1][1], c0.most_common()[1][1] + c1.most_common()[0][1])
            print(N - m)
    else:
        m = c0.most_common()[0][1] + c1.most_common()[0][1]
        print(N - m)


if __name__ == '__main__':
    main()

Solution (Python):













mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    V = readInts()
    from collections import Counter
    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])))
if __name__ == '__main__':
  main()

Solution (Python):
import collections
n=int(input())
A=list(map(int,input().split()))
A0=[]
A1=[]
for i in range(n):
  if i%2==0:
    A0.append(A[i])
  else:
    A1.append(A[i])
A00=collections.Counter(A0)
A11=collections.Counter(A1)
A000=A00.most_common()
A111=A11.most_common()
A000.append(("-1",0))
A111.append(("-1",0))
if A000[0][0]!=A111[0][0]:
  print(n-A000[0][1]-A111[0][1])
else:
  print(min(n-A000[1][1]-A111[0][1],n-A000[0][1]-A111[1][1]))

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))

a = [v[i] for i in range(n) if i % 2 == 0]
b = [v[i] for i in range(n) if not i % 2 == 0]

a_count = Counter(a)
b_count = Counter(b)

a_sorted = sorted(a_count.items(), key=lambda x:x[1], reverse=True)
b_sorted = sorted(b_count.items(), key=lambda x:x[1], reverse=True)
ans = 0
if not a_sorted[0][0] == b_sorted[0][0]:
    ans = n - a_sorted[0][1] - b_sorted[0][1]
else:
    if len(b_sorted) == 1 and len(a_sorted) == 1:
        ans = n - a_sorted[0][1]
    elif len(b_sorted) == 1:
        ans = n - a_sorted[0][1]
    elif len(a_sorted) == 1:
        ans = n - b_sorted[0][1]
    else:
        ans = n - max(a_sorted[0][1] + b_sorted[1][1], a_sorted[1][1] + b_sorted[0][1])

print(ans)

Solution (Python):
from collections import defaultdict


def main():

    n = int(input())

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

    odd = defaultdict(int)
    even = defaultdict(int)
    odd[0] = 0
    even[0] = 0

    for i, num in enumerate(v):
        
        if (i % 2) == 0:
            even[num] += 1
        elif (i % 2) == 1:
            
            odd[num] += 1

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

    ans_list = []
    for ev in even_list[:2]:
        for od in odd_list[:2]:
            if ev[0] != od[0]:
                ans = 0
                ans += n - (ev[1] + od[1])
                ans_list.append(ans)

    print(min(ans_list))


main()

Solution (Python):
from collections import defaultdict


def main():

    n = int(input())

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

    odd = defaultdict(int)
    even = defaultdict(int)
    odd[0] = 0
    even[0] = 0

    for i, num in enumerate(v):
        
        if (i % 2) == 0:
            even[num] += 1
        elif (i % 2) == 1:
            
            odd[num] += 1

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

    if a[0][0] != b[0][0]:
        ans = n - a[0][1] - b[0][1]
    else:
        ans = n - max(a[0][1] + b[1][1], a[1][1] + b[0][1])

    print(ans)


main()

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

d_odd = {0:0}
d_even = {0:0}

ans = 0
for i in range(n):
    if i % 2 == 0:
        if v[i] in d_odd:
            d_odd[v[i]] += 1
        else:
            d_odd[v[i]] = 1
    else:
        if v[i] in d_even:
            d_even[v[i]] += 1
        else:
            d_even[v[i]] = 1

x = sorted(d_odd.items(), key=lambda x: x[1], reverse=1)
y = sorted(d_even.items(), key=lambda x: x[1], reverse=1)

if x[0][0] != y[0][0]:
    ans = n - x[0][1] - y[0][1]
else:
    ans = n - max(x[0][1]+y[1][1], x[1][1]+y[0][1])

print(ans)

Solution (Python):
import collections
n, *v = map(int, open(0).read().split())

v1 = [0] * (n // 2)
v2 = [0] * (n // 2)

for i in range(n // 2):
    v1[i] = v[2 * i]
    v2[i] = v[2 * i + 1]

v1_cnt = collections.Counter(v1)
v2_cnt = collections.Counter(v2)

v1_cnt_l = sorted(list(v1_cnt.values()))
v2_cnt_l = sorted(list(v2_cnt.values()))



if max(v1_cnt, key=v1_cnt.get) == max(v2_cnt, key=v2_cnt.get):
    if 1 < len(v1_cnt_l) and 1 < len(v2_cnt_l):
        
        num1 = sum(v1_cnt_l) - v1_cnt_l[-1]
        num1 += sum(v2_cnt_l) - v2_cnt_l[-2]
    
        num2 = sum(v1_cnt_l) - v1_cnt_l[-2]
        num2 += sum(v2_cnt_l) - v2_cnt_l[-1]
    
        num = min(num1, num2)
    elif 1 < len(v1_cnt_l):
        
        num = sum(v1_cnt_l) - v1_cnt_l[-2]
        num += sum(v2_cnt_l) - v2_cnt_l[-1]
    elif 1 < len(v2_cnt_l):
        
        num = sum(v1_cnt_l) - v1_cnt_l[-1]
        num += sum(v2_cnt_l) - v2_cnt_l[-2]
    else:
        
        num = n // 2
        
else:
    num = sum(v1_cnt_l) - v1_cnt_l[-1]
    num += sum(v2_cnt_l) - v2_cnt_l[-1]

print(num)

Solution (Python):
from collections import Counter


def solve():

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

    evens = []
    odds = []

    for i in range(n):
        v = vlist[i]
        if i % 2 == 0:
            evens.append(v)
        else:
            odds.append(v)

    evensCollection = Counter(evens).most_common()
    oddsCollection = Counter(odds).most_common()

    evensCollection.append([0, 0])
    oddsCollection.append([0, 0])

    if evensCollection[0][0] != oddsCollection[0][0]:
        print(n - (evensCollection[0][1] + oddsCollection[0][1]))

    else:
        print(min(n-(evensCollection[1][1]+oddsCollection[0][1]),
                  n-(evensCollection[0][1]+oddsCollection[1][1])))


if __name__ == "__main__":
    solve()

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

odd = [[0, i] for i in range(100001)]
even = [[0, i] for i in range(100001)]

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

odd.sort()
even.sort()

if odd[-1][1] != even[-1][1]:
  print(n - odd[-1][0] - even[-1][0])
else:
  print(n - max(odd[-2][0] + even[-1][0], odd[-1][0] + even[-2][0]))

Solution (Python):
import sys
from collections import Counter

n, *v = map(int, sys.stdin.read().split())

def main():
    c1 = sorted(Counter(v[::2]).items(), key=lambda x: -x[1])
    c2 = sorted(Counter(v[1::2]).items(), key=lambda x: -x[1])
    if c1[0][0] != c2[0][0]: res = n - c1[0][1] - c2[0][1]
    else:
        if len(c1) > len(c2): c1, c2 = c2, c1
        if len(c2) == 1: res = n // 2
        else:
            if len(c1) == 1: res = n - c1[0][1] - c2[1][1]
            else:
                res = n - max(c1[0][1] + c2[1][1], c1[1][1] + c2[0][1])
    print(res)

if __name__ ==  '__main__':
    main()

Solution (Python):
from collections import Counter

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

v_even,v_odd = [],[]
for i in range(n):
    if i % 2 == 0:
        v_even.append(v[i])
    else:
        v_odd.append(v[i])

c_even = Counter(v_even)
c_odd = Counter(v_odd)

if len(set(v)) == 1:
    ans = n // 2
elif len(set(v_even)) == 1:
    if c_even.most_common()[0][0] == c_odd.most_common()[0][0]:
        ans = (n // 2) - c_odd.most_common()[1][1]
    else:
        ans = (n // 2) - c_odd.most_common()[0][1]
elif len(set(v_odd)) == 1:
    if c_odd.most_common()[0][0] == c_even.most_common()[0][0]:
        ans = (n // 2) - c_even.most_common()[1][1]
    else:
        ans = (n // 2) - c_even.most_common()[0][1]
else:
    if c_odd.most_common()[0][0] != c_even.most_common()[0][0]:
        ans = n - c_even.most_common()[0][1] - c_odd.most_common()[0][1]
    else:
        ans = n - c_even.most_common()[0][1] \
              - max(c_even.most_common()[1][1],c_odd.most_common()[1][1])

print(ans)

Solution (Python):





mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    V = readInts()
    from collections import Counter
    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])))

    """Fi = {}
    Se = {}

    for i in range(0,n,2): 
        print(i,len(V))
        if V[i] in Fi.keys():
            Fi[V[i]] += 1
        else:
            Fi[V[i]] = 1


    for i in range(1,n,2): 

        if V[i] in Se.keys():
            Se[V[i]] += 1
        else:
            Se[V[i]] = 1
    
    
    sortFi = sorted(Fi.items(), key=lambda x:x[1]) 
    sortSe = sorted(Se.items(), key = lambda x:x[1])
    
    
    
    k,v = sortFi[0]
    mostFi = k
    
    k,v = sortSe[0]
    mostSe = k
    if mostFi == mostSe:
        if len(sortSe) != 1:
            k,v = sortSe[1]
            mostSe = k
        else:
            mostSe = mostFi+1
    
    
    cnt = 0
    for k,v in Fi.items():
        if mostFi == k:
            pass
        else:
            cnt += v
    for k,v in Se.items():
        if mostSe == k:
            pass
        else:
            cnt += v
    print(cnt)
    """


if __name__ == '__main__':
  main()

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v1 = v[0::2]
v2 = v[1::2]
count1 = Counter(v1)
count2 = Counter(v2)
count1[0] = 0
count2[0] = 0
items1 = []
items2 = []
key1 = max(count1.keys(), key = count1.get)
items1.append([key1, count1[key1]])
del count1[key1]
key1 = max(count1.keys(), key = count1.get)
items1.append([key1, count1[key1]])

key2 = max(count2.keys(), key = count2.get)
items2.append([key2, count2[key2]])
del count2[key2]
key2 = max(count2.keys(), key = count2.get)
items2.append([key2, count2[key2]])

if items1[0][0] != items2[0][0]:
    m = items1[0][1] + items2[0][1]
else:
    m = max(items1[0][1] + items2[1][1], items1[1][1] + items2[0][1])
print(n - m)

Solution (Python):
from collections import Counter
import sys

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

A = V[0::2]
B = V[1::2]



cnt = 0

if len(set(V)) == 1:
    print(N // 2)
    sys.exit()

A_counter = Counter(A)
B_counter = Counter(B)

A_top2 = A_counter.most_common(2)
B_top2 = B_counter.most_common(2)

if A_top2[0][0] != B_top2[0][0]:
    cnt += len(A) - A_top2[0][1]
    cnt += len(B) - B_top2[0][1]
else:
    cnt = min(
        len(A) - A_top2[0][1] + len(B) - B_top2[1][1],
        len(A) - A_top2[1][1] + len(B) - B_top2[0][1],
    )

print(cnt)

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):
N = int(input())
arr = list(map(int, input().split()))
if len(set(arr)) == 1:
    print(N//2)
    exit()
A = []
B = []
for i in range(N):
    if i % 2 == 0:
        A.append(arr[i])
    else:
        B.append(arr[i])
from collections import Counter
A_counter = Counter(A)
B_counter = Counter(B)
if A_counter.most_common()[0][0] != B_counter.most_common()[0][0]:
    print(N-A_counter.most_common()[0][1]-B_counter.most_common()[0][1])
elif A_counter.most_common()[0][1] > B_counter.most_common()[0][1]:
    print(N-A_counter.most_common()[0][1]-B_counter.most_common()[1][1])
elif A_counter.most_common()[0][1] < B_counter.most_common()[0][1]:
    print(N-A_counter.most_common()[1][1]-B_counter.most_common()[0][1])
else:
    print(N-A_counter.most_common()[0][1]-max(A_counter.most_common()[1][1],B_counter.most_common()[1][1]))

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

from collections import Counter

def minus(lis):
    if len(set(lis))==1:
        return lis[0], 0, 10**9
    c = Counter(lis)
    f_key = max(c, key=c.get)
    second,first = sorted(c.values())[-2:]
    return f_key,len(lis)-first,len(lis)-second

def solve(n,v):
    if len(set(v))==1:
        return n//2
    Odd = [v[i] for i in range(n) if i%2==1]
    Even = [v[i] for i in range(n) if i%2==0]
    odd_key, odd_f,odd_s = minus(Odd)
    
    even_key, even_f,even_s = minus(Even)
    if odd_key == even_key:
        return min(odd_f+even_s,even_f+odd_s)
    
    return odd_f + even_f
print(solve(n,v))

Solution (Python):
from collections import Counter

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

c1 = Counter(v[::2])
c2 = Counter(v[1::2])
c1[0] = 0
c2[0] = 0
c1 = sorted(c1.items(), key=lambda x: x[1], reverse=True)
c2 = sorted(c2.items(), key=lambda x: x[1], reverse=True)

if c1[0][0] != c2[0][0]:
    ans = n - c1[0][1] - c2[0][1]
else:
    ans = min(n - c1[0][1] - c2[1][1], n - c2[0][1] - c1[1][1],)
print(ans)

Solution (Python):
def main():
  import collections 
  n=int(input())
  v=tuple(map(int,input().split()))
  a,b=collections.Counter(v[::2]).most_common(),collections.Counter(v[1::2]).most_common()
  if len(a)==len(b)==1:
    print(n//2 if a==b else 0)
  else:
    print(n+(-a[0][1]-b[0][1] if a[0][0]!=b[0][0] else (-a[0][1]-b[1][1] if b[1][1]>=a[1][1] else -a[1][1]-b[0][1])))
if __name__=='__main__':
  main()

Solution (Python):
import collections 
n=int(input())
v=list(map(int,input().split()))
c1,c2,ans=collections.Counter(v[::2]),collections.Counter(v[1::2]),0
a,b=c1.most_common(),c2.most_common()
if len(a)==len(b)==1:
  print(n//2 if a==b else 0)
  exit()
ans=n+(-a[0][1]-b[0][1] if a[0][0]!=b[0][0] else (-a[0][1]-b[1][1] if b[1][1]>=a[1][1] else -a[1][1]-b[0][1]))
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))

a = [v[i] for i in range(n) if i % 2]
b = [v[i] for i in range(n) if i % 2 == 0]
aa = Counter(a)
bb = Counter(b)
ans = 0

aas = sorted(aa.keys(), key=lambda key:aa[key], reverse=True)
bbs = sorted(bb.keys(), key=lambda key:bb[key], reverse=True)
if aas[0] != bbs[0]:
    ans += len(a) - aa[aas[0]]
    ans += len(b) - bb[bbs[0]]
else:
    if len(aa) == len(bb) and len(aa) == 1 and a[0] == b[0]:
        ans += min(len(a), len(b))
    else:
        s = len(a) - aa[aas[0]] + len(b) - bb[bbs[1]]
        t = len(a) - aa[aas[1]] + len(b) - bb[bbs[0]]
        ans = min(s,t)

print(ans)

Solution (Python):
n = int(input())
V = list(map(int,input().split()))
Ve = V[::2]
Vo = V[1::2]
from collections import Counter


Ve = list(Counter(Ve).items())
Ve.sort(key = lambda x:x[1], reverse = 1)
Vo = list(Counter(Vo).items())
Vo.sort(key = lambda x:x[1], reverse = 1)

if Ve[0][0] == Vo[0][0]:
  if len(Ve) == len(Vo) == 1:
    print(n//2)
  else:
    print(n - max(Ve[0][1]+Vo[1][1], Ve[1][1]+Vo[0][1]))
else:
  print(n-Ve[0][1]-Vo[0][1])

Solution (Python):
from collections import Counter
n = int(input())
s = list(map(int,input().split()))
s1 = []
s2 = []


for i in range(n):
  if i%2 == 1:
    s2.append(s[i])
  else:
    s1.append(s[i])

s1_counter = Counter(s1)
s2_counter = Counter(s2)
s1_len = len(s1)
s2_len = len(s2)
s1_most_common = s1_counter.most_common()
s2_most_common = s2_counter.most_common()

if s1_most_common[0][0] != s2_most_common[0][0]:
  print(s1_len-s1_most_common[0][1]+s2_len-s2_most_common[0][1])
else:  
  if len(s1_most_common) + len(s2_most_common) == 2:
    print(n//2)
  elif s1_most_common[0][1] > s2_most_common[0][1]:
    print(s1_len-s1_most_common[0][1]+s2_len-s2_most_common[1][1])
  elif s1_most_common[0][1] < s2_most_common[0][1]:
    print(s1_len-s1_most_common[1][1]+s2_len-s2_most_common[0][1])
  else:
    if s1_most_common[1][1] < s2_most_common[1][1]:
      print(s1_len-s1_most_common[0][1]+s2_len-s2_most_common[1][1])
    else:
      print(s1_len-s1_most_common[1][1]+s2_len-s2_most_common[0][1])

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
dict1 = {0:0}
dict2 = {0:0}
ans = 0
for i in v[::2]:
    if i not in dict1:
        dict1[i] = 1
    else:
        dict1[i] += 1
for i in v[1::2]:
    if i not in dict2:
        dict2[i] = 1
    else:
        dict2[i] += 1
lisa = sorted(dict1.items(),key=lambda x: x[1],reverse=1)
lisb = sorted(dict2.items(),key=lambda x: x[1],reverse=1)
if lisa[0][0] != lisb[0][0]:
    ans = n-lisa[0][1]-lisb[0][1]
else:
    ans = n-max(lisa[0][1]+lisb[1][1],lisa[1][1]+lisb[0][1])
print(ans)

Solution (Python):
import sys

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

a1 = {}
a2 = {}
for i in range(n) :
  a = v[i]
  if i%2 == 0 :
    if a in a1 :
      a1[a] += 1
    else :
      a1[a] = 1
  else :
    if a in a2 :
      a2[a] += 1
    else :
      a2[a] = 1

a1_s = sorted(a1.items(), key = lambda x : x[1], reverse = True)
a2_s = sorted(a2.items(), key = lambda x : x[1], reverse = True)

ans = n
for i in range(min(2,len(a1_s))) :
  for j in range(min(2,len(a2_s))) :
    if a1_s[i][0] == a2_s[j][0] :
      continue
    ans = min(ans,n-a1_s[i][1]-a2_s[j][1])

if len(a1_s) == 1 and len(a2_s) == 1 and ans == n :
  ans = n//2

print(ans)

Solution (Python):
"""

Counter

Counterを使わない場合、処理を間違えずに書くのに以外と苦労
"""
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from collections import Counter

def main():
    n = II()
    vv = MII()
    ee = Counter(vv[0::2])
    oo = Counter(vv[1::2])
    minv = 10**5
    ee1 = ee.most_common()[0]
    oo1 = oo.most_common()[0]
    if ee1[0] != oo1[0]:
        minv = min(minv, n - (ee1[1] + oo1[1]))
    else:
        ee2 = ee.most_common()[1] if len(ee) > 1 else (0, 0)
        oo2 = oo.most_common()[1] if len(oo) > 1 else (0, 0)
        minv = min(minv, n - (ee1[1] + oo2[1]))
        minv = min(minv, n - (ee2[1] + oo1[1]))
    print(minv)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int, input().split()))
b=[a[i] for i in range(n) if i%2==0]
c=[a[i] for i in range(n) if i%2==1]
b2=Counter(b)
c2=Counter(c)
b3=b2.most_common(2)
c3=c2.most_common(2)
ans=n
for i in b3:
    for j in c3:
        if i[0]!=j[0]:
            ans=min(ans,n-i[1]-j[1])
        else:
            ans=min(ans,n-max(i[1],j[1]))
print(ans)

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))

A=v[0::2]
B=v[1::2]
a=len(A)
b=len(B)




if Counter(A).most_common()[0][0] !=Counter(B).most_common()[0][0]:
    s=Counter(A).most_common()[0][1]
    t=Counter(B).most_common()[0][1]
    print( (a-s)+(b-t))
else:
  r=a
  s=b
  if Counter(A).most_common()[0][1]<a:
    o=Counter(A).most_common()[1][1]
    p=Counter(B).most_common()[0][1]
    r= (a-o)+(b-p)
  if Counter(B).most_common()[0][1]<b:
    w=Counter(A).most_common()[0][1]
    x=Counter(B).most_common()[1][1]
    s= (a-w)+(b-x)
  print(min( r, s))

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from collections import Counter

def main():
    n = II()
    vv = MII()
    ee = Counter(vv[0::2])
    oo = Counter(vv[1::2])
    minv = 10**5
    ee1 = ee.most_common()[0]
    oo1 = oo.most_common()[0]
    if ee1[0] != oo1[0]:
        minv = min(minv, n - (ee1[1] + oo1[1]))
    else:
        ee2 = ee.most_common()[1] if len(ee) > 1 else (0, 0)
        oo2 = oo.most_common()[1] if len(oo) > 1 else (0, 0)
        minv = min(minv, n - (ee1[1] + oo2[1]))
        minv = min(minv, n - (ee2[1] + oo1[1]))
    print(minv)

if __name__ == '__main__':
    main()