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( )))

v1 = v[0::2]
v2 = v[1::2]



from  collections import Counter

n1 = len(v1)
n2 = len(v2)
v11 = Counter(v1)
v21 = Counter(v2)




c1 = v11.most_common(2)
c2 = v21.most_common(2)







if c1[0][0]!=c2[0][0]:
    print(n1-c1[0][1]+n2-c2[0][1])
else:
    try:
        ans1 = n1-c1[1][1]+n2-c2[0][1]
        ans2 = n1-c1[0][1]+n2-c2[1][1]
        print(min(ans1,ans2))
    except:
        try:
            ans1 = n1-c1[1][1]+n2-c2[0][1]
            
            print(ans1)
        except:
            try:
                ans2 = n1-c1[0][1]+n2-c2[1][1]
                print(ans2)
            except:
                print(len(v2))

Solution (Python):
import sys
from collections import defaultdict

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



def main():
	n = int(input())
	al = list(IN())
	odd_dd=defaultdict(lambda : 0)
	odd_dd[-1]=0
	even_dd=defaultdict(lambda :0)
	even_dd[-1]=0
	
	for i, v in enumerate(al):
		if i%2==0:
			odd_dd[v] += 1
		else:
			even_dd[v] += 1
	
	odd_ll=[(odd_dd[key], key) for key in odd_dd.keys()]
	even_ll=[(even_dd[key], key) for key in even_dd.keys()]
	
	odd_ll.sort(reverse=True)
	even_ll.sort(reverse=True)
	kk=n//2
	pa(odd_ll)
	pa(even_ll)
	
	
	if odd_ll[0][1] == even_ll[0][1]:
		ra=(kk-odd_ll[0][0])+(kk-even_ll[1][0])
		rb=(kk-odd_ll[1][0])+(kk-even_ll[0][0])
		return min(ra, rb)
	else:
		ret= (kk-odd_ll[0][0])+(kk-even_ll[0][0])
		return ret
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
from collections import Counter

n = int(input())
u = [int(i) for i in input().split()]
e = Counter(u[0::2]).most_common() + [(0, 0)]
o = Counter(u[1::2]).most_common() + [(0, 0)]

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

Solution (Python):
from collections import Counter
 
n = int(input())
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()

v_odd_common.append((0,0))
v_even_common.append((0,0))

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

Solution (Python):
from collections import defaultdict

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

dda= defaultdict(int)
ddb= defaultdict(int)


for i in range(N):
    if i%2==0:
        dda[v[i]]+=1
    else:
        ddb[v[i]]+=1

La=[]
Lb=[]

for k,v in dda.items():
    La.append((v,k))
    
for k,v in ddb.items():
    Lb.append((v,k))
        
La.sort()
Lb.sort()

ma=La[-1][0]
mb=Lb[-1][0]
ans=ma+mb

if La[-1][1]==Lb[-1][1]:
    if len(La)!=1:
        m2a=La[-2][0]
    else:
        m2a=0
    if len(Lb)!=1:
        m2b=Lb[-2][0]
    else:
        m2b=0
    ans=ma+max(m2a,m2b)
    
print(N-ans)

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

even_v=[]
odd_v=[]
for i in range(N):
    if i%2==0:
        even_v.append(v[i])
    else:
        odd_v.append(v[i])

import collections
even_c = collections.Counter(even_v)
odd_c = collections.Counter(odd_v)

even_num = even_c.most_common()[0][0]
odd_num = odd_c.most_common()[0][0]
even_cnt = even_c.most_common()[0][1]
odd_cnt = odd_c.most_common()[0][1]

if even_num == odd_num:
    if len(odd_c.most_common())==1 and len(even_c.most_common())==1: 
        odd_num=even_num+1
    elif len(odd_c.most_common())!=1 and len(even_c.most_common())==1: 
        odd_num = odd_c.most_common()[1][0]
    elif len(odd_c.most_common())==1 and len(even_c.most_common())!=1: 
        even_num = even_c.most_common()[1][0]
    else:
        if odd_cnt==even_cnt:
            even_cnt2= even_c.most_common()[1][1]
            odd_cnt2 = odd_c.most_common()[1][1]
            if even_cnt2>odd_cnt2:
                even_num = even_c.most_common()[1][0]
            else:
                odd_num = odd_c.most_common()[1][0]
        elif odd_cnt>even_cnt:
            even_num = even_c.most_common()[1][0]
        else:
            odd_num = odd_c.most_common()[1][0]
ans=0

for i in range(N):
    if i%2==0:
        num=even_num
    else:
        num=odd_num
    if num!=v[i]:
        ans+=1

print(ans)

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

even=[(0,0)]+sorted(Counter(V[::2]).items(), key=lambda x:x[1])
odd=[(0,0)]+sorted(Counter(V[1::2]).items(), key=lambda x:x[1])

if even[-1][0]==odd[-1][0]:
    if even[-2][1]>odd[-2][1]:even=even[-2][0];odd=odd[-1][0]
    else:even=even[-1][0];odd=odd[-2][0]
else:even=even[-1][0];odd=odd[-1][0]

cnt=0
for i,j in enumerate(V):
    if i%2==0 and j!=even:cnt +=1
    elif i%2==1 and j!=odd:cnt +=1

print(cnt)

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

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
from collections import defaultdict
dict_odd=defaultdict(lambda :0)
dict_even=defaultdict(lambda :0)
dict_even[0],dict_odd[0]=0,0
for i in range(0,n,2):
    dict_even[v[i]]+=1

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

even_val=list(dict_even.items())
odd_val=list(dict_odd.items())
even_val=sorted(even_val,reverse=True,key=lambda x: x[1])
odd_val=sorted(odd_val,reverse=True,key=lambda x: x[1])

if even_val[0][0]!=odd_val[0][0]:
    print(n-odd_val[0][1]-even_val[0][1])
else:
    ans1=n-odd_val[1][1]-even_val[0][1]
    ans2=n-odd_val[0][1]-even_val[1][1]
    print(min(ans1,ans2))

Solution (Python):
import itertools
from collections import Counter

N = int(input())
V = [int(x) for x in 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)
    if ans > x:
        ans = x

print(ans)

Solution (Python):
import collections

N = int(input())
V = [int(x) for x in input().split()]

Va, Vb = [], []
for i in range(N):
    if i % 2 == 0:
        Va.append(V[i])
    else:
        Vb.append(V[i])

Va_most = collections.Counter(Va).most_common()
Vb_most = collections.Counter(Vb).most_common()

if N == collections.Counter(V).most_common()[0][1]:
    print(N//2)
    exit()

if Va_most[0][0] == Vb_most[0][0]:
    typea = 10 ** 10
    if len(Vb_most) >= 2:
        typea = (len(Va) - Va_most[0][1]) + (len(Vb) - Vb_most[1][1])
    typeb = 10 ** 10
    if len(Va_most) >= 2:
        typeb = (len(Va) - Va_most[1][1]) + (len(Vb) - Vb_most[0][1])
    print(min(typea, typeb))
    exit()

print((len(Va) - Va_most[0][1]) + (len(Vb) - Vb_most[0][1]))

Solution (Python):
import collections
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(0,n,2):
    a.append(v[i])
    b.append(v[i+1])
    
a_count=collections.Counter(a)
b_count=collections.Counter(b)

if a_count.most_common()[0][0]==b_count.most_common()[0][0]:
    if a_count.most_common()[0][1]==n//2 :
        print(a_count.most_common()[0][1])
    else:
        print(min(n-a_count.most_common()[0][1]-a_count.most_common()[1][1],n-b_count.most_common()[0][1]-b_count.most_common()[1][1]))
else:
    ans=n-a_count.most_common()[0][1]-b_count.most_common()[0][1]
    print(ans)

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

import collections

E = []
O = []
for i, v in enumerate(V):
  if i % 2 == 0:
    E.append(v)
  else:
    O.append(v)

ec = collections.Counter(E)
oc = collections.Counter(O)
e_common = ec.most_common()
o_common = oc.most_common()

E1 = e_common[0][1]
E2 = 0
if len(e_common) > 1:
  E2 = e_common[1][1]

O1 = o_common[0][1]
O2 = 0
if len(o_common) > 1:
  O2 = o_common[1][1]

if e_common[0][0] == o_common[0][0]:
  A1 = N - E1 - O2
  A2 = N - O1 - E2
  print(min(A1, A2))
else:
  ans = N - E1 - O1
  print(ans)

Solution (Python):
from collections import Counter
N = int(input())
V = list(map(int,input().split(" ")))

V1 = V[::2]
V2 = V[1::2]
ans = 0
d1 = Counter(V1)
d2 = Counter(V2)
if len(d1) == 1 and V1 == V2:
    print(N//2)
    exit()
m1 = max(d1.items(), key = lambda x:x[1])
m2 = max(d2.items(), key = lambda x:x[1])
d1.pop(m1[0])
d2.pop(m2[0])
a = m1[1]
b = m2[1]
if m1[0] != m2[0]:
    if d1:
      ans += sum(d1.values())
    if d2:
      ans += sum(d2.values())
else:
    c = 0
    d = 0
    if d1:
	    c = max(d1.values())
    if d2:
	    d = max(d2.values())
    if c != 0:
        tmp = N-b-c
    if c == 0:
        tmp = N-b-a
    if d != 0:
        ttmp = N-a-d
    if d == 0:
        ttmp = N-a-b
    
    ans = min(tmp,ttmp)
print(ans)

Solution (Python):
x=int(input())
a=list(map(int,input().split()))
d=[0]*100001
d0=[0]*100001
p=0
q=0
m0=0
n0=0
m=n=0
for i in range(x):
    if i%2==0:
        d[a[i]]+=1
        if d[a[i]]>=p:
            p=max(p,d[a[i]])
            if a[i]!=m:
                m0=m
                m=a[i]
    else:
        d0[a[i]]+=1
        if d0[a[i]]>=q:
            q=max(q,d0[a[i]])
            if a[i]!=n:
                n0=n
                n=a[i]
if m==n:
    if d[m0]>d0[n0]:
        p=d[m0]
    else:
        q=d0[n0]
print(x-p-q)

Solution (Python):
def main():
    n = int(input())
    v = input().split(" ")
    even = {}
    odd = {}
    for i in range(n):
        if i % 2 == 0:
            even.setdefault(v[i], 0)
            even[v[i]] += 1
        else:
            odd.setdefault(v[i], 0)
            odd[v[i]] += 1
    even = sorted(even.items(), key=lambda x: x[1], reverse=True)
    odd = sorted(odd.items(), key=lambda x: x[1], reverse=True)
    
    if even[0][0] == odd[0][0]:
        if len(even) > 1 and len(odd) > 1:
            print(n - int(even[0][1]) - max(even[1][1], odd[1][1]))
        elif len(even) > 1:
            print(n - odd[0][1] - even[1][1])
        elif len(odd) > 1:
            print(n - even[0][1] - odd[1][1])
        else:
            print(n // 2)
    else:
        print(n - int(even[0][1]) - int(odd[0][1]))


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())

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

v1 = v[0::2]
v2 = v[1::2]



from  collections import Counter

n1 = len(v1)
n2 = len(v2)
v11 = Counter(v1)
v21 = Counter(v2)




c1 = v11.most_common(2)
c2 = v21.most_common(2)







if c1[0][0]!=c2[0][0]:
    print(n1-c1[0][1]+n2-c2[0][1])
else:
    try:
        ans1 = n1-c1[1][1]+n2-c2[0][1]
        ans2 = n1-c1[0][1]+n2-c2[1][1]
        print(min(ans1,ans2))
    except:
        try:
            ans1 = n1-c1[1][1]+n2-c2[0][1]
            
            print(ans1)
        except:
            try:
                ans2 = n1-c1[0][1]+n2-c2[1][1]
                print(ans2)
            except:
                print(len(v2))

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

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

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

odd.sort(reverse=True)
even.sort(reverse=True)

no1, o1 = odd[0]
no2, o2 = odd[1]
ne1, e1 = even[0]
ne2, e2 = even[1]


if e1 == o1:
  ans = min((n//2-ne1)+(n//2-no2), (n//2-ne2)+(n//2-no1))
else:
  ans = (n//2-ne1) + (n//2-no1)

print(ans)

Solution (Python):
from collections import Counter

n = int(input())
v = [int(_) for _ in input().split()]

odd = v[0:n:2]
even = v[1:n:2]

odClass = Counter(odd)
evClass = Counter(even)
mostOd = odClass.most_common()
mostEv = evClass.most_common()

numOd = mostOd[0]
numEv = mostEv[0]

if len(mostOd) == 1 and len(mostEv) == 1:
    if mostOd[0][0] == mostEv[0][0]:
        print(len(odd))
    else:
        print(0)
    exit()
elif len(mostOd) == 1 and len(mostEv) != 1:
    if mostOd[0][0] == mostEv[0][0]:
        numEv = mostEv[1]
elif len(mostOd) != 1 and len(mostEv) == 1:
    if mostOd[0][0] == mostEv[0][0]:
        numOd = mostOd[1]
elif len(mostOd) != 1 and len(mostEv) != 1:
    if mostOd[0][0] == mostEv[0][0]:
        if mostOd[0][1] == mostEv[0][1]:
            if mostOd[1][1] <= mostEv[1][1]:
                numEv = mostEv[1]
            else:
                numOd = mostOd[1]
        elif mostOd[0][1] < mostEv[0][1]:
            numOd = mostOd[1]
        else:
            numEv = mostEv[1]

print(len(odd) + len(even) - numOd[1] - numEv[1])

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

even_dict = {'dummy':0}
odd_dict = {'dummy':0}

for x in list(set(v)):
	even_dict[x] = 0
	odd_dict[x] = 0

for i in range(n):
	x = v[i]
	if(i % 2 == 0):
		odd_dict[x] += 1
	else:
		even_dict[x] += 1

even_sort = sorted(even_dict.items(), key=lambda x:x[1], reverse=True)
odd_sort = sorted(odd_dict.items(), key=lambda x:x[1], reverse=True)

if( even_sort[0][0] != odd_sort[0][0] ):
	ans =  n - even_sort[0][1] - odd_sort[0][1]
else:
	ans = min(n - even_sort[1][1] - odd_sort[0][1],
			 n - even_sort[0][1] - odd_sort[1][1])

print(ans)

Solution (Python):
n = int(input())
data_list = input().split()
odd_list = [data_list[i] for i in range(0, n, 2)]
even_list = [data_list[i] for i in range(1, n, 2)]

def make_dict(list):
  appeared = dict()
  for i in list:
    if not i in appeared:
      appeared[i] = 1
    else:
      appeared[i] += 1
  return appeared

odd_dict = make_dict(odd_list)
even_dict = make_dict(even_list)
odd_max = max(odd_dict.items(), key=lambda x: x[1])
even_max = max(even_dict.items(), key=lambda x: x[1])

if odd_max[0] != even_max[0]:
  print(n - (odd_max[1] + even_max[1]))
else:
  del odd_dict[odd_max[0]]
  del even_dict[even_max[0]]
  if len(odd_dict) == 0 and len(even_dict) == 0:
    print(n//2)
  elif len(odd_dict) == 0:
    even_second_max = max(even_dict.items(), key=lambda x: x[1])
    print(n//2 - even_second_max[1])
  elif len(even_dict) == 0:
    odd_second_max = max(odd_dict.items(), key=lambda x: x[1])
    print(n//2 - odd_second_max[1])
  else:
    odd_second_max = max(odd_dict.items(), key=lambda x: x[1])
    even_second_max = max(even_dict.items(), key=lambda x: x[1])
    print(n - max((odd_max[1] + even_second_max[1]), (odd_second_max[1] + even_max[1])))

Solution (Python):
from collections import Counter

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

odd = Counter()
even = Counter()

for i, v in enumerate(V):
    cnt = even if i % 2 else odd
    cnt[v] += 1

oddCmn = odd.most_common(2)
evenCmn = even.most_common(2)

oddCmn.append((0, 0))
evenCmn.append((0, 0))

od = 0
ev = 0
if oddCmn[od][0] == evenCmn[ev][0]:
    if oddCmn[od][1] + evenCmn[ev + 1][1] < evenCmn[ev][1] + oddCmn[od + 1][1]:
        od += 1
    else:
        ev += 1


print(N - oddCmn[od][1] - evenCmn[ev][1])

Solution (Python):
from collections import Counter

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

odd = Counter()
even = Counter()

for i, v in enumerate(V):
    cnt = even if i % 2 else odd
    cnt[v] += 1

oddCmn = odd.most_common(2)
evenCmn = even.most_common(2)

oddCmn.append((0, 0))
evenCmn.append((0, 0))

od = 0
ev = 0
if oddCmn[od][0] == evenCmn[ev][0]:
    if oddCmn[od][1] + oddCmn[od + 1][1] < evenCmn[ev][1] + evenCmn[ev + 1][1]:
        ev += 1
    else:
        od += 1


print(N - oddCmn[od][1] - evenCmn[ev][1])

Solution (Python):

from collections import Counter
n=int(input())
v=list(map(int,input().split()))
L=Counter(v[0::2]).most_common()
R=Counter(v[1::2]).most_common()


if L[0][0]!=R[0][0]:
    ans=n-L[0][1]-R[0][1]
elif len(R)!=1 and len(L)!=1:
    ans=n-max(L[0][1]+R[1][1],L[1][1]+R[0][1])
elif len(R)!=1 and len(L)==1:
    ans=n-R[1][1]-L[0][1]
elif len(R)==1 and len(L)!=1:
    ans=n-R[0][1]-L[1][1]
elif len(R)==1 and len(L)==1:
    ans=n//2
print(ans)

Solution (Python):

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

c0=Counter(v[0::2]).most_common()
c1=Counter(v[1::2]).most_common()

if c0[0][0]!=c1[0][0]:
    ans=n-c0[0][1]-c1[0][1]
elif len(c0)!=1 and len(c1)!=1:
    ans=n-max(c0[0][1]+c1[1][1],c0[1][1]+c1[0][1])
elif len(c0)!=1 and len(c1)==1:
    ans=n-c0[1][1]-c1[0][1]
elif len(c0)==1 and len(c1)!=1:
    ans=n-c0[0][1]-c1[1][1]
elif len(c0)==1 and len(c1)==1:
    ans=n//2
print(ans)

Solution (Python):
from collections import Counter
from itertools import product

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


O_cnt,E_cnt=Counter(V[::2]),Counter(V[1::2])
O_cnt[-1]=0
E_cnt[-2]=0


O_key,E_key=O_cnt.most_common(2),E_cnt.most_common(2)

ans=float('inf')

for O_k,E_k in product(O_key,E_key):
    if O_k[0]!=E_k[0]:
	    ans=min(ans,N-O_k[1]-E_k[1])
print(ans)

Solution (Python):
from collections  import Counter
n = int(input())
l = [int(i) for i in input().split()]
 
l1 = [l[i] for i in range(n) if i%2 ==0]
l2 = [l[i] for i in range(n) if i%2 ==1]
 
c1 = Counter(l1)
c2 = Counter(l2)
 
even1 = c1.most_common()[0][1]
even2 = c1.most_common()[1][1] if len(c1) > 1 else 0
odd1 = c2.most_common()[0][1]
odd2 = c2.most_common()[1][1] if len(c2) > 1 else 0

if c1.most_common()[0][0] == c2.most_common()[0][0]:
    ans = min((n - even1 - odd2),(n - odd1 - even2))
else:
    ans = (n//2 - even1) + (n//2 - odd1)
    
print(ans)

Solution (Python):
import itertools
"""
n = int(input())
m, a, r, c, h = [0] * 5
for i in range(n):
    s = input()
    if s[0] == "M": m += 1
    if s[0] == "A": a += 1
    if s[0] == "R": r += 1
    if s[0] == "C": c += 1
    if s[0] == "H": h += 1
x = [m, a, r, c, h]
y = ["M", "A", "R", "C", "H"]
ans = 0
for i in itertools.combinations(x, 3):
    ans += i[0] * i[1] * i[2]
print(ans)
"""


n = int(input())

v = list(map(int, input().split()))
a = [[0] * 100010 for _ in range(2)]
for i in range(n):
    a[i % 2][v[i]] += 1

od, ev = [], []
for i in range(100010):
    od.append([a[1][i], i])
    ev.append([a[0][i], i])
od.sort()
od.reverse()
ev.sort()
ev.reverse()
if od[0][1] != ev[0][1]: print(n - od[0][0] - ev[0][0])
else: print(n - max(od[0][0] + ev[1][0], od[1][0] + ev[0][0]))

Solution (Python):
from collections import Counter

def solve(n, V):
    if V.count(V[0]) == n:
        return n // 2
    return min(
        n - oc - ec
        for o, oc in Counter(V[0::2]).most_common(2)
        for e, ec in Counter(V[1::2]).most_common(2)
        if o != e
    )

_n = int(input())
_V = list(map(int, input().split()))
print(solve(_n, _V))

Solution (Python):
from collections import Counter

def solve(n, V):
    if len(set(V)) == 1:
        return n // 2
    return min(
        n - oc - ec
        for o, oc in Counter(V[0::2]).most_common(2)
        for e, ec in Counter(V[1::2]).most_common(2)
        if o != e
    )

_n = int(input())
_V = list(map(int, input().split()))
print(solve(_n, _V))

Solution (Python):
from collections import Counter

def solve(n, V):
    if len(set(V)) == 1:
        return n // 2
    odds = V[0::2]
    evens = V[1::2]
    return min(
        len(odds) - oc + len(evens) - ec
        for o, oc in Counter(odds).most_common(2)
        for e, ec in Counter(evens).most_common(2)
        if o != e
    )

_n = int(input())
_V = list(map(int, input().split()))
print(solve(_n, _V))

Solution (Python):
from collections import Counter

def solve(n, V):
    odds = V[0::2]
    evens = V[1::2]
    o2 = [k for k, c in Counter(odds).most_common(2)]
    e2 = [k for k, c in Counter(evens).most_common(2)]
    if len(o2) == 1 and o2 == e2:
        return n // 2
    return min(
        len(odds) - odds.count(o) + len(evens) - evens.count(e)
        for o in o2
        for e in e2
        if o != e
    )

_n = int(input())
_V = list(map(int, input().split()))
print(solve(_n, _V))

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter


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

odd = v[::-2]
even = v[::2]


o_elm = Counter(odd).most_common(2)+[(0,0)]
e_elm = Counter(even).most_common(2)+[(0,0)]
if o_elm[0][0]==e_elm[0][0]:
  print(N -max(o_elm[0][1]+e_elm[1][1], o_elm[1][1]+e_elm[0][1]))
else:
  print(N -o_elm[0][1] -e_elm[0][1])

Solution (Python):
import sys

stdin = sys.stdin

mod = 1000000007
inf = 1 << 60

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

from collections import Counter
from itertools import product

n = ni()
a = na()

even = Counter(a[::2])
odd = Counter(a[1::2])

even[-1] = 0
odd[-2] = 0

e = even.most_common(2)
o = odd.most_common(2)

ans = n
for (k1, v1), (k2, v2) in product(e, o):
    if k1 == k2:
        continue
    x = (n - v1 - v2)
    if ans > x:
        ans = x

print(ans)

Solution (Python):
from collections import Counter


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

o = []
e = []

for i in range(n):
    
    if i%2 == 1:
        e.append(v[i])
    else:
        o.append(v[i])

o = Counter(o)
e = Counter(e)








if o.most_common(1)[0][0] != e.most_common(1)[0][0]:
    
    ans = n - o.most_common(1)[0][1] - e.most_common(1)[0][1]
elif len(o) == 1 and len(e) == 1:
    
    ans = n/2
else:
    
    
    
    try:
        temp1 = n - o.most_common(2)[1][1] - e.most_common(1)[0][1]
    except:
        temp1 = 10**6
    try:
        temp2 = n - o.most_common(1)[0][1] - e.most_common(2)[1][1]
    except:
        temp2 = 10**6
    ans = min(temp1, temp2)

print(int(ans))

Solution (Python):
N=int(input())
A = list( map(int,input().split()))
C0 = [ [0,i] for i in range(100005) ]
C1 = [ [0,i] for i in range(100005) ]
for i in range(0,N,2):
    C0[A[i]][0] += 1
    C1[A[i+1]][0] += 1
C0.sort(reverse=True)
C1.sort(reverse=True)
if C0[0][1] == C1[0][1]:
    ans = N - max(C0[0][0]+C1[1][0], C0[1][0]+C1[0][0])
else:
    ans = N - C0[0][0] - C1[0][0]
print(ans)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
dic1={}
dic2={}
for i in range(n):
  if i%2==0:
    if l[i] in dic1:
      dic1[l[i]] += 1
    else:
      dic1[l[i]]=1
  else:
    if l[i] in dic2:
      dic2[l[i]] += 1
    else:
      dic2[l[i]]=1
dic1a = sorted(dic1.items(),key = lambda x:x[1])
dic2a = sorted(dic2.items(),key = lambda x:x[1]) 
 
if dic1a[-1][0] == dic2a[-1][0]:
    if len(dic1a) == len(dic2a) == 1:
        print(n//2)
    else:
        if dic1a[-2][1] >= dic2a[-2][1]:
            print(sum(dic2.values())-dic2a[-1][1]+sum(dic1.values())-dic1a[-2][1])
        else:
            print(sum(dic1.values())-dic1a[-1][1]+sum(dic2.values())-dic2a[-2][1])
else:
    print(sum(dic1.values())-dic1a[-1][1]+sum(dic2.values())-dic2a[-1][1])

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

m = max(v)+1
o = [0]*m
e = [0]*m

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

a = sorted(o)[-2:]
b = sorted(e)[-2:]


if o.index(a[1]) == e.index(b[1]):
    if a[0] >= b[0]:
        ans = n - o[o.index(a[0])] - e[e.index(b[1])]
    else:
        ans = n - o[o.index(a[1])] - e[e.index(b[0])]
else:
    ans = n - a[1] - b[1]
    
print(ans)

Solution (Python):
from collections import defaultdict as DD
import numpy as np
N = int(input())
v = list(map(int, input().split()))

E = DD(int)
O = DD(int)
E[-1] = 0
O[-1] = 0
for i in range(N):
  if i % 2 == 1:
    E[v[i]] += 1
  else:
    O[v[i]] += 1

NE = np.array(sorted(E.items(), key=lambda x: x[1], reverse = True))
NO = np.array(sorted(O.items(), key=lambda x: x[1], reverse = True))



ans = 0
if NE[0][0] == NO[0][0]:
  if len(NE) == 2 and  len(NO) == 2:
    ans = NE[0][1]
  else:
      ans = min(sum(NO[:,1]) - NO[1][1] + sum(NE[1:,1]), sum(NE[:,1]) - NE[1][1] + sum(NO[1:,1]))
else:
  ans = sum(NE[1:,1]) + sum(NO[1:,1])
print (ans)

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v_1 = v[0:n:2]
v_2 = v[1:n:2]
count_1 = dict(Counter(v_1))
count_2 = dict(Counter(v_2))


v1 = sorted(count_1.items(), key=lambda x:x[1], reverse=True)
v2 = sorted(count_2.items(), key=lambda x:x[1], reverse=True)


def calc(l):
    if len(l) == 1:
        return l[0][1]
    else:
        return l[0][1] - l[1][1]
    
    
if v1[0][0] == v2[0][0]:
    
    if calc(v1) > calc(v2):
        s1 = v1[0][0]
        if len(v2) == 1:
            s2 = s1 + 1
        else:
            s2 = v2[1][0]
    else:
        s2 = v2[0][0]
        if len(v1) == 1:
            s1 = s2 + 1
        else:
            s1 = v1[1][0]
else:
    s1 = v1[0][0]
    s2 = v2[0][0]

ans = n - v_1.count(s1) - v_2.count(s2)
print(ans)

Solution (Python):
import collections

n = int(input())
v = list(map(int, input().split()))
v_odd = collections.Counter(v[::2])
v_even = collections.Counter(v[1::2])

if v_odd == v_even and len(v_odd) == 1:
    print(n // 2)
    exit()
if v_odd.most_common()[0][0] != v_even.most_common()[0][0]:
    print(len(v[::2]) - v_odd.most_common()[0][1] + len(v[1::2]) - v_even.most_common()[0][1])
else:
    c1 = len(v[1::2]) - v_even.most_common()[0][1] + len(v[::2]) - v_odd.most_common()[1][1]
    c2 = len(v[1::2]) - v_even.most_common()[1][1] + len(v[::2]) - v_odd.most_common()[0][1]
    print(min(c1, c2))

Solution (Python):
import sys
from collections import Counter

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    V = LIST()
    a, b = [Counter(V[i::2]).most_common() + [(0, 0)] for i in (0, 1)]
    i, x = a[0]
    j, y = b[0]
    print(N - [x + y, max(x + b[1][1], y + a[1][1])][i == j])


if __name__ == '__main__':
    main()

Solution (Python):
import collections
n=int(input())
v=list(input().split())
ans=0

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

ep=collections.Counter(even).most_common()
op=collections.Counter(odd).most_common()
ep.append((0,0))
op.append((0,0))

if ep[0] != op[0]:
    ans=n-(ep[0][1]+op[0][1])
else:
    if len(even)-ep[1][1]<len(odd)-op[1][1]:
        ans=n-ep[1][1]-op[0][1]
    else:
        ans=n-ep[0][1]-op[1][1]
print(ans)

Solution (Python):
import collections

n = int(input())
v = [int(i) for i in input().split()]
o = collections.Counter(v[0::2])
e = collections.Counter(v[1::2])
o_count = o.most_common()[:2]
e_count = e.most_common()[:2]

ans = None
if o_count[0] != e_count[0]:
    ans = n - o_count[0][1] - e_count[0][1]
elif len(o_count) == 1 and len(e_count) == 1:
    ans = n // 2
elif len(o_count) == 1:
    ans = n//2 - e_count[1][1]
elif len(e_count) == 1:
    ans = n//2 - o_count[1][1]
else:
    ans = min(
        n - o_count[0][1] - e_count[1][1],
        n - e_count[0][1] - o_count[1][1]
    )
print(ans)

Solution (Python):
import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    n=int(input())
    v=list(map(int,input().split()))
    do=defaultdict(int)
    de=defaultdict(int)
    for i,x in enumerate(v):
        if i%2:
            do[x]+=1
        else:
            de[x]+=1
    o1,e1,o2,e2=0,0,0,0
    for x in do.keys():
        if do[x]>o1:
            o2=o1
            o1=do[x]
            o1n=x
        else:
            o2=max(o2,do[x])
    for x in de.keys():
        if de[x]>e1:
            e2=e1
            e1=de[x]
            e1n=x
        else:
            e2=max(e2,de[x])
    if o1n!=e1n:
        print(n-(o1+e1))
    else:
        print(n-max(o1+e2,o2+e1))
            
            

if __name__ == '__main__':
    main()

Solution (Python):

from collections import Counter
n = int(input())
a = list(map(int, input().split()))

odd = [a[i] for i in range(n) if i%2==0]
even = [a[i] for i in range(n) if i%2!=0]

cntOdd = Counter(odd).most_common(2)
cntEven = Counter(even).most_common(2)

 

if cntOdd[0][0] != cntEven[0][0]:
    print(n - cntOdd[0][1] - cntEven[0][1])
else:
    if len(cntEven) == 1 and len(cntEven):
        print(n//2)
    else:
        ans1 = n - cntOdd[1][1] - cntEven[0][1]
        ans2 = n - cntOdd[0][1] - cntEven[1][1]
        print(min(ans1, ans2))

Solution (Python):
from collections import Counter
n=int(input())
v = list(map(int,input().split()))
even = [v[i] for i in range(n) if i % 2 == 0]
odd = [v[i] for i in range(n) if i%2==1]
ct_even = Counter(even).most_common(2)
ct_odd = Counter(odd).most_common(2)
if ct_even[0][0]!=ct_odd[0][0]:
  print(n-ct_even[0][1]-ct_odd[0][1])
else:
  if len(ct_even)==1 and len(ct_odd)==1:
    print(n//2)
  elif len(ct_even)!=1 and len(ct_odd)==1:
    print(n//2 - ct_even[1][1])
  elif len(ct_even)==1 and len(ct_odd)!=1:
    print(n//2-ct_odd[1][1])
  else:
    k=max(ct_even[0][1]+ct_odd[1][1], ct_even[1][1]+ct_odd[0][1])
    print(n-k)

Solution (Python):
from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()
    if a[0][0] != b[0][0]:
        print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
    else:
        if a[0][1] < b[0][1]:
            print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        elif a[0][1] > b[0][1]:
            print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
        elif a[0][1] == b[0][1]:
            if len(a) != 1 and len(b) != 1:
                if a[1][1] > b[1][1]:
                    print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
                elif a[1][1] < b[1][1]:
                    print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
                elif a[1][1] == b[1][1]:
                    print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
            elif len(a) != 1:
                print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
            elif len(b) != 1:
                print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
else:
    print(len(v[1::2]))