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

odev = [{}, {}]

for i in range(N):
  odev[i%2][v[i]] = odev[i%2].get(v[i],0) + 1

for i in range(2):
  odev[i] = sorted(odev[i].items(), key=lambda x: x[1], reverse=True)

sameChr = odev[0][0][0] == odev[1][0][0]
odev = [list(map(lambda x: x[1], odev[0])), list(map(lambda x: x[1], odev[1]))]

if(sameChr):
  if(len(odev[0]) > 1 and len(odev[1]) > 1):
    print(N - max(odev[0][1] + odev[1][0], odev[0][0] + odev[1][1]))
  elif(len(odev[0]) == 1 and len(odev[1]) == 1):
    print(N // 2)
  elif(len(odev[0]) == 1):
    print(N - odev[0][0] + odev[1][1])
  else:
    print(N - odev[0][1] + odev[1][0])
else:
  print(N - odev[0][0] - odev[1][0])

Solution (Python):
def list_count(my_list,n,x):
    dic={} 
    for i in range(x,n,2):
        if my_list[i] in dic: 
            dic[my_list[i]]+=1 
        else: 
            dic[my_list[i]]=1 
    return dic

n=int(input())
v=list(map(int,input().split()))
dic0=list_count(v,n,0)
dic1=list_count(v,n,1)
a=[[0,0],[0,0]]
b=[[0,0],[0,0]]
for i in dic0.keys():
    if a[0][1]<=dic0[i]:
        a[1][0]=a[0][0]
        a[1][1]=a[0][1]
        a[0][0]=i
        a[0][1]=dic0[i]
    elif a[1][1]<dic0[i]:
        a[1][0]=i
        a[1][1]=dic0[i]
for i in dic1.keys():
    if b[0][1]<=dic1[i]:
        b[1][0]=b[0][0]
        b[1][1]=b[0][1]
        b[0][0]=i
        b[0][1]=dic1[i]
    elif b[1][1]<dic1[i]:
        b[1][0]=i
        b[1][1]=dic1[i]
if a[0][0]==b[0][0]:
    print(n-max(a[0][1]+b[1][1],a[1][1]+b[0][1]))
else:
    print(n-a[0][1]-b[0][1])

Solution (Python):
import collections
n = int(input())
v = list(map(int,input().split()))
if collections.Counter(v).most_common()[0][1] == n:
    print(n//2)
    exit()
c = collections.Counter(v[::2])
d = collections.Counter(v[1::2])
c_ = c.most_common()[0][1]
d_ = d.most_common()[0][1]
e = 0
if c.most_common()[0][0] == d.most_common()[0][0]:
    if len(c.most_common()) == 1:
        d_ = d.most_common()[1][1]
    elif len(d.most_common()) == 1:
        c_ = c.most_common()[1][1]
    else:
        if c.most_common()[1][1] < d.most_common()[1][1]:
            d_ = d.most_common()[1][1]
        else:
            c_ = c.most_common()[1][1]
    
cnt = (n//2) - c_
cnt += (n//2) - d_
print(cnt+e)

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

from collections import Counter
A = Counter(V[::2])
B = Counter(V[1::2])

ac = sorted(A.items(), key=lambda x: -x[1])
bc = sorted(B.items(), key=lambda x: -x[1])

if len(ac) == 1 and len(bc) == 1:
    if ac[0][0] == bc[0][0]:
        print(h)
    else:
        print(0)
elif len(ac) == 1:
    print(h-bc[0][1])
elif len(bc) == 1:
    print(h-ac[0][1])
elif ac[0][0] == bc[0][0]:
    if ac[0][1]-ac[1][1] == bc[0][1]-bc[1][1]:
        if ac[0][1] >= bc[0][1]:
            print((h-ac[0][1]) + (h-bc[1][1]))
        else:
            print((h-ac[1][1]) + (h-bc[0][1]))
    elif ac[0][1]-ac[1][1] > bc[0][1]-bc[1][1]:
        print((h-ac[0][1]) + (h-bc[1][1]))
    else:
        print((h-ac[1][1]) + (h-bc[0][1]))
else:
    print((h-ac[0][1]) + (h-bc[0][1]))

Solution (Python):
from collections import Counter

def main():
	n = int(input())
	w = input().split()
	a = Counter(w[::2]).most_common(2)
	b = Counter(w[1::2]).most_common(2)
	if a[0][0]!=b[0][0]:
		stay = a[0][1] + b[0][1]
	elif a[0][1]==b[0][1]==n // 2:
		stay = n // 2
	else:
		stay = max(a[0][1] + b[1][1], a[1][1] + b[0][1])
	print(n - stay)

if __name__=="__main__":
	main()

Solution (Python):
from collections import defaultdict

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



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

if N == 2:
    print(1)
    exit()




d_even = defaultdict(int)
d_odd = defaultdict(int)

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

l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

if l_even[0][0] != l_odd[0][0]:
    print(N - l_even[0][1] - l_odd[0][1])
else:
    
    ans1 = N - l_even[0][1] - l_odd[1][1]
    ans2 = N - l_even[1][1] - l_odd[0][1]
    print(min(ans1, ans2))

Solution (Python):

from collections import defaultdict

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

if N == 2:
    if V[0] == V[1]:
        print(0)
    else:
        print(1)
    exit()

d_even = defaultdict(int)
d_odd = defaultdict(int)

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

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


l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

if l_even[0][0] != l_odd[0][0]:
    print(N - l_even[0][1] - l_odd[0][1])
else:
    print(min(N - l_even[0][1] - l_odd[1][1], N - l_even[1][1] - l_odd[0][1]))

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

v1 = collections.Counter(vl[0::2])
v2 = collections.Counter(vl[1::2])


v1s = []
for a,b in v1.items():
    v1s.append((b,a))

v2s = []
for a,b in v2.items():
    v2s.append((b,a))

v1s = sorted(v1s)
v2s = sorted(v2s)

if v1s[-1][1] != v2s[-1][1]:
    print(n - v1s[-1][0] - v2s[-1][0])
else:
    if len(v2s) == 1:
        p2 = 0
    else:
        p2 = v2s[-2][0]
    if len(v1s) == 1:
        p1 = 0
    else:
        p1 = v1s[-2][0]
    ans = min(n - v1s[-1][0] - p2, n - p1 - v2s[-1][0])
    print(ans)

Solution (Python):
from collections import Counter


def solve(n, v):
    origin_odd = [v[i] for i in range(n) if i % 2 == 1]
    origin_even = [v[i] for i in range(n) if i % 2 == 0]

    o = Counter(origin_odd).most_common()
    e = Counter(origin_even).most_common()

    o.sort(key=lambda k: k[1])
    e.sort(key=lambda k: k[1])
    
    o_p = o[-1]
    e_p = e[-1]
    ans = 0
    if len(o) == 1 and len(e) == 1:
        if o_p[0] == e_p[0]:
            ans = n//2
        else:
            ans = 0
    elif len(o) == 1:
        if o_p[0] == e_p[0]:
            e_s = e[-2]
            ans = n - (o_p[1]+e_s[1])
        else:
            ans = n - (o_p[1]+e_p[1])
    elif len(e) == 1:
        if o_p[0] == e_p[0]:
            o_s = o[-2]
            ans = n - (e_p[1]+o_s[1])
        else:
            ans = n - (e_p[1]+o_p[1])
    else:
        o_s = o[-2]
        e_s = e[-2]
        if o_p[0] == e_p[0]:
            o_s = o[-2]
            e_s = e[-2]
            ans = n-(max(o_p[1]+e_s[1], o_s[1]+e_p[1]))
        else:
            ans = n-(o_p[1]+e_p[1])

    return ans


if __name__ == '__main__':
    n = int(input())
    v = list(map(int, input().split()))
    print(solve(n, v))

Solution (Python):
from collections import Counter

n=int(input())
V=list(map(int,input().split()))
V_1=[(0,0)]+sorted(Counter([V[i] for i in range(n) if i%2==0]).items(), key=lambda x:x[1])
V_2=[(0,0)]+sorted(Counter([V[j] for j in range(n) if j%2==1]).items(), key=lambda x:x[1])

a,b=V_1[-1][0],V_2[-1][0]

if a==b:
    if V_1[-2][1]>V_2[-2][1]:a=V_1[-2][0]
    else:b=V_2[-2][0]

cnt=0
for i in range(n):
    if i%2==0:
        if V[i]!=a:cnt +=1
    else:
        if V[i]!=b:cnt +=1

print(cnt)

Solution (Python):
from collections import Counter

N = int(input())
l = list(map(int, input().split(' ')))
l_odd = l[0::2]
l_even = l[1::2]
dict_odd = Counter(l_odd)
dict_even = Counter(l_even)
most_odd = dict_odd.most_common()[0][0]
most_even = dict_even.most_common()[0][0]

if dict_odd.most_common()[0][1] == dict_even.most_common()[0][1] == N / 2:
    if most_odd == most_even:
        ans = N / 2
    else:
        ans = 0

elif dict_odd.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_even.most_common()[0][1]

elif dict_even.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_odd.most_common()[0][1]

elif most_odd != most_even:
    ans = N - dict_odd.most_common()[0][1] - dict_even.most_common()[0][1]

else:
    ans = N - max(dict_odd.most_common()[0][1] + dict_even.most_common()[1][1], dict_even.most_common()[0][1] + dict_odd.most_common()[1][1])

print(int(ans))

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
v_odd = []
v_even = []
d_odd = {}
d_even = {}
o = []
e = []
for i in range(n//2):
    a = v[2*i]
    b = v[2*i+1]
    if a in d_odd:
        d_odd[a] += 1
    else:
        d_odd[a] = 1
        o.append(a)
    if b in d_even:
        d_even[b] += 1
    else:
        d_even[b] = 1
        e.append(b)
O = 0
E = 0
o_max = 0
o_second = 0
e_max = 0
e_second = 0
for i in o:
    x = d_odd[i]
    if x >= o_max:
        O = i
        o_max = x
d_odd.pop(O)
o.remove(O)
for i in o:
    x = d_odd[i]
    if x >= o_second:
        o_second = x
for i in e:
    y = d_even[i]
    if y >= e_max:
        E = i
        e_max = y
d_even.pop(E)
e.remove(E)
for i in e:
    y = d_even[i]
    if y >= e_second:
        e_second = y
if O == E:
    m = max(o_max+e_second,e_max+o_second)
else:
    m = o_max + e_max
print(n-m)

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

evenv, oddv = Counter(v[0::2]).most_common(), Counter(v[1::2]).most_common()
ans = 0
if evenv == oddv and len(evenv) == 1:
    ans = n // 2
elif evenv[0][0] == oddv[0][0]:
    ans = n - max(evenv[0][1] + oddv[1][1], evenv[1][1] + oddv[0][1])
else:
    ans = n - evenv[0][1] - oddv[0][1]
print(ans)

Solution (Python):

import collections
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 i%2==1]

a=collections.Counter(a)
b=collections.Counter(b)
a=a.most_common()
b=b.most_common()
if len(a)==len(b)==1:
    if a[0][0]==b[0][0]:
        print(int(N/2))
    else:
        print(0)
elif len(a)==1 and len(b)>=2:
    print(N-(b[0][1] if a[0][0]!=b[0][0] else b[1][1])-a[0][1])
elif len(a)>=2 and len(b)==1:
    print(N-(a[0][1] if a[0][0]!=b[0][0] else a[1][1])-b[0][1])
elif len(a)>=2 and len(a)>=2:
    print(min(N-(b[0][1] if a[0][0]!=b[0][0] else b[1][1])-a[0][1],N-(a[0][1] if a[0][0]!=b[0][0] else a[1][1])-b[0][1]))

Solution (Python):
from collections import Counter
n = int(input())
array = list(map(int,input().split()))
if len(set(array)) == 1:
    print(n//2)
    exit()
gu = []
ki = []
for i in range(n):
    if i % 2 == 0:
        gu.append(array[i])
    else:
        ki.append(array[i])
gu_c = Counter(gu)
ki_c = Counter(ki)
gu_m = gu_c.most_common()
ki_m = ki_c.most_common()
if gu_m[0][0] != ki_m[0][0]:
    print(n-(gu_m[0][1]+ki_m[0][1]))
elif gu_m[0][1] < ki_m[0][1]:
    print(n-(gu_m[1][1]+ki_m[0][1]))
elif gu_m[0][1] > ki_m[0][1]:
    print(n-(gu_m[0][1]+ki_m[1][1]))
else:
    print(n-(gu_m[0][1]+max(gu_m[1][1],ki_m[1][1])))

Solution (Python):
from collections import Counter
n = int(input())
array = list(map(int,input().split()))
if len(set(array)) == 1:
    print(n//2)
    exit()
gu = []
ki = []
for i in range(n):
    if i % 2 == 0:
        gu.append(array[i])
    else:
        ki.append(array[i])
gu_c = Counter(gu)
ki_c = Counter(ki)
if gu_c.most_common()[0][0] != ki_c.most_common()[0][0]:
    print(n-(gu_c.most_common()[0][1]+ki_c.most_common()[0][1]))
elif gu_c.most_common()[0][1] < ki_c.most_common()[0][1]:
    print(n-(gu_c.most_common()[1][1]+ki_c.most_common()[0][1]))
elif gu_c.most_common()[0][1] > ki_c.most_common()[0][1]:
    print(n-(gu_c.most_common()[0][1]+ki_c.most_common()[1][1]))
else:
    print(n-(gu_c.most_common()[0][1]+max(gu_c.most_common()[1][1],ki_c.most_common()[1][1])))

Solution (Python):
import collections
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 i%2==1]

a=collections.Counter(a)
b=collections.Counter(b)
a=a.most_common()
b=b.most_common()
if len(a)==len(b)==1:
    if a[0][0]==b[0][0]:
        print(int(N/2))
    else:
        print(0)
elif len(a)==1 and len(b)>=2:
    print(N-(b[0][1] if a[0][0]!=b[0][0] else b[1][1])-a[0][1])
elif len(a)>=2 and len(b)==1:
    print(N-(a[0][1] if a[0][0]!=b[0][0] else a[1][1])-b[0][1])
elif len(a)>=2 and len(a)>=2:
    print(min(N-(b[0][1] if a[0][0]!=b[0][0] else b[1][1])-a[0][1],N-(a[0][1] if a[0][0]!=b[0][0] else a[1][1])-b[0][1]))

Solution (Python):
import collections
n = int(input())
v = list(map(int,input().split()))
ve = [v[2*i] for i in range(n//2)]
vo = [v[2*i + 1] for i in range(n//2)]
Cve = collections.Counter(ve)
Cvo = collections.Counter(vo)
Cve1 = Cve.most_common()[0]
Cvo1 = Cvo.most_common()[0]
if len(Cve) == 1 and len(Cvo) == 1: 
    if Cve1[0] == Cvo1[0]: ans = n//2 
    else: ans = 0 
elif len(Cve) == 1 and len(Cvo) > 1: 
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cvo2[1] 
    else: ans = n//2 - Cvo1[1] 
elif len(Cve) > 1 and len(Cvo) == 1: 
    Cve2 = Cve.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cve2[1] 
    else: ans = n//2 - Cve1[1] 
else:
    Cve2 = Cve.most_common()[1]
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] != Cvo1[0]: ans = n - Cve1[1] - Cvo1[1] 
    if Cve1[0] == Cvo1[0]:
        if Cve1[1] < Cvo1[1]: ans = n - Cve2[1] - Cvo1[1]
        elif Cve2[1] > Cvo2[1] : ans = n - Cve2[1] - Cvo1[1]
        else: ans = n - Cve1[1] - Cvo2[1]
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a1=[a[i] for i in range(0,len(a),2)]
a2=[a[i] for i in range(1,len(a),2)]

import collections
c1=collections.Counter(a1)
c2=collections.Counter(a2)

c1=sorted(c1.items(),key=lambda x:x[1],reverse=True)
c2=sorted(c2.items(),key=lambda x:x[1],reverse=True)
ans=0
if c1[0][0]==c2[0][0]:
  if len(c1)==1:
    ans+=(n//2)
  elif c1[1][1]<=c2[1][1]:
    ans+=(n//2)-c1[0][1]
    ans+=(n//2)-c2[1][1]
  else:
    ans+=(n//2)-c1[1][1]
    ans+=(n//2)-c2[0][1]
else:
  ans+=(n//2)-c1[0][1]
  ans+=(n//2)-c2[0][1]

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a1=[a[i] for i in range(0,len(a),2)]
a2=[a[i] for i in range(1,len(a),2)]

import collections
c1=collections.Counter(a1)
c2=collections.Counter(a2)

c1=sorted(c1.items(),key=lambda x:x[1],reverse=True)
c2=sorted(c2.items(),key=lambda x:x[1],reverse=True)
ans=0
if c1[0][0]==c2[0][0]:
  if len(c1)==1:
    ans+=(n//2)
  elif c1[1][1]<=c2[1][1]:
    ans+=(n//2)-c1[0][1]
    ans+=(n//2)-c2[1][1]
  else:
    ans+=(n//2)-c1[1][1]
    ans+=(n//2)-c2[0][1]
else:
  ans=0
  ans+=(n//2)-c1[0][1]
  ans+=(n//2)-c2[0][1]

print(ans)

Solution (Python):

import sys
import collections





import operator as op




def main():
    
    n, *v = (int(x) for x in sys.stdin.read().split())

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


    o_c = collections.Counter(odds)
    e_c = collections.Counter(evens)
    
    o_c = sorted(list((k, v) for k, v in o_c.items()), key=op.itemgetter(1), reverse=True)
    e_c = sorted(list((k, v) for k, v in e_c.items()), key=op.itemgetter(1), reverse=True)

    ans = n
    if o_c[0][0] != e_c[0][0]:
        ans = n - o_c[0][1] - e_c[0][1]
    else:
        if len(o_c) == 1 and len(e_c) == 1:
            ans = n - n // 2
        elif len(o_c) == 1 and len(e_c) >= 2:
            ans = n - e_c[1][1]
        elif len(o_c) >= 2 and len(e_c) == 1:
            ans = n - o_c[1][1]
        else:
            ans = n - max(o_c[0][1] + e_c[1][1], o_c[1][1] + e_c[0][1])
    
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
ls=[int(s) for s in input().split()]
dic1={}
dic2={}
i=0
while i<N:
  if ls[i] in dic1:
    dic1[ls[i]]+=1
  else:
    dic1[ls[i]]=1
  if ls[i+1] in dic2:
    dic2[ls[i+1]]+=1
  else:
    dic2[ls[i+1]]=1  
  i+=2
ls1=sorted(list(dic1.items()),key=lambda x : -x[1])
ls2=sorted(list(dic2.items()),key=lambda x : -x[1])



if ls1[0][0]!=ls2[0][0]:
  print(N-ls1[0][1]-ls2[0][1])
elif len(ls1)==1:
  
  if len(ls2)==1:
    print(N//2)
  
  else:
    print(N//2-ls2[1][1])

elif len(ls2)==1:
  print(N//2-ls1[1][1])
else:
  
  if ls1[1][1]>ls2[1][1]:
    
    print(N-ls1[1][1]-ls2[0][1])
  else:
    
    print(N-ls2[1][1]-ls2[0][1])

Solution (Python):
import collections
N = int(input())
V = list(map(int,input().split()))
V_even = V[::2]
V_odd = V[1::2]
V_even_counter = collections.Counter(V_even)
V_odd_counter = collections.Counter(V_odd)
if V_even_counter.most_common()[0][0] != V_odd_counter.most_common()[0][0]:
    ans = N - V_even_counter.most_common()[0][1] - V_odd_counter.most_common()[0][1]
else:
    if len(V_even_counter) > 1 and len(V_odd_counter) > 1:
        ans = N - max(V_even_counter.most_common()[0][1] + V_odd_counter.most_common()[1][1],\
            V_even_counter.most_common()[1][1] + V_odd_counter.most_common()[0][1])
    elif len(V_even_counter) == 1 and len(V_odd_counter) > 1:
        ans = N - V_even_counter.most_common()[0][1] - V_odd_counter.most_common()[1][1]
    elif len(V_even_counter) > 1 and len(V_odd_counter) == 1:
        ans = N - V_even_counter.most_common()[1][1] + V_odd_counter.most_common()[0][1]
    else:
        ans = N//2
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
v = [x for x in input().split()]
if len(set(v)) == 1:
  print(len(v)//2)
  exit()
v_even = Counter(v[::2])
v_odd = Counter(v[1::2])
v_even_mc = v_even.most_common()
v_odd_mc = v_odd.most_common()

if v_even_mc[0] != v_odd_mc[0]:
  ans = (len(v)//2 - v_even_mc[0][1]) + (len(v)//2 - v_odd_mc[0][1])
else:  
  ans_e = (len(v)//2 - v_even_mc[0][1]) + (len(v)//2 - v_odd_mc[1][1])
  ans_o = (len(v)//2 - v_even_mc[1][1]) + (len(v)//2 - v_odd_mc[0][1])
  ans = min(ans_e, ans_o)
print(ans)

Solution (Python):
n = int(input())
v = input().split()
o = {"":0}
e = {"":0}
for s in v[::2]:
    if s in o:
        o[s] += 1
    else:
        o[s] = 1

for s in v[1::2]:
    if s in e:
        e[s] += 1
    else:
        e[s] = 1

o = sorted(o.items(), key=lambda x:x[1])
e = sorted(e.items(), key=lambda x:x[1])

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

Solution (Python):
from sys import stdin
from itertools import groupby

n = int(stdin.readline().rstrip())

li = list(map(int,stdin.readline().rstrip().split()))

li1 = []
li2 = []

for i in range(n):
    if i % 2 == 0:
        li1.append(li[i])
    else:
        li2.append(li[i])

li1.sort()
li2.sort()

lin = []
lin2 = []

for key, value in groupby(li1):
    lin.append((key,len(list(value))))
for key, value in groupby(li2):
    lin2.append((key,len(list(value))))

lin.sort(key=lambda x:(x[1]))
lin2.sort(key=lambda x:(x[1]))

point = 0

if lin[-1][0] == lin2[-1][0] and lin[-1][1] == lin2[-1][1]:
    if len(lin) == 1:
        print(n//2)
    else:
        if lin[-2][1] >= lin2[-2][1]:
            print(n-lin[-2][1]-lin2[-1][1])
        else:
            print(n-lin[-1][1]-lin2[-2][1])

elif lin[-1][0] == lin2[-1][0]:
    if len(lin) == 1:
        print(n//2-lin2[-2][1])
    elif len(lin2) == 1:
        print(n//2-lin[-2][1])
    else:
        if lin[-2][1] >= lin2[-2][1]:
            print(n-lin[-2][1]-lin2[-1][1])
        else:
            print(n-lin[-1][1]-lin2[-2][1])
else:
    print(n-lin[-1][1]-lin2[-1][1])

Solution (Python):
from sys import stdin
from itertools import groupby

n = int(stdin.readline().rstrip())

li = list(map(int,stdin.readline().rstrip().split()))

li1 = []
li2 = []

for i in range(n):
    if i % 2 == 0:
        li1.append(li[i])
    else:
        li2.append(li[i])

li1.sort()
li2.sort()

lin = []
lin2 = []

for key, value in groupby(li1):
    lin.append((key,len(list(value))))
for key, value in groupby(li2):
    lin2.append((key,len(list(value))))

lin.sort(key=lambda x:(x[1]))
lin2.sort(key=lambda x:(x[1]))

point = 0

if lin[-1][0] == lin2[-1][0] and lin[-1][1] == lin2[-1][1]:
    if len(lin) == 1:
        print(n//2)
    else:
        if lin[-2][1] >= lin2[-2][1]:
            print(n-lin[-2][1]-lin2[-1][1])
        else:
            print(n-lin[-1][1]-lin2[-2][1])

elif lin[-1][0] == lin2[-1][0]:
    if len(lin) == 1:
        print(n//2-lin2[-2][1])
    elif len(lin2) == 1:
        print(n//2-lin[-2][1])
    else:
        if lin[-2][1] >= lin2[-2][1]:
            print(n-lin[-1][1]-lin2[-2][1])
        else:
            print(n-lin[-2][1]-lin2[-1][1])
else:
    print(n-lin[-1][1]-lin2[-1][1])

Solution (Python):

n = int(input())
v = list(map(lambda x: int(x), input().split(' ')))


import collections
even_frq_dict = collections.defaultdict(int)
len_even = 0
for i in range(0, n, 2):
    even_frq_dict[v[i]] += 1
    len_even += 1

len_odd = 0
odd_frq_dict = collections.defaultdict(int)
for i in range(1, n, 2):
    odd_frq_dict[v[i]] += 1
    len_odd += 1


even_frqs = list(sorted(list(even_frq_dict.items()), key=lambda x: x[1]))
odd_frqs = list(sorted(list(odd_frq_dict.items()), key=lambda x: x[1]))

if len(even_frqs) == 1 and len(odd_frqs) == 1:
    if even_frqs[0][0] == odd_frqs[0][0]:
        print(min(len_even, len_odd))
    else:
        print(0)
    exit()
elif len(even_frqs) == 1:
    print(len_odd - odd_frqs[-1][1])
    exit()
elif len(odd_frqs) == 1:
    print(len_even - even_frqs[-1][1])
    exit()


e_num1, e_frq1 = even_frqs[-1]
e_num2, e_frq2 = even_frqs[-2]
o_num1, o_frq1 = odd_frqs[-1]
o_num2, o_frq2 = odd_frqs[-2]

ans = 0
if e_num1 == o_num1:
    cnd1 = (len_even - e_frq2) + (len_odd - o_frq1)
    cnd2 = (len_even - e_frq1) + (len_odd - o_frq2)
    ans = min(cnd1, cnd2)

else:
    ans = (len_even - e_frq1) + (len_odd - o_frq1)

print(ans)

Solution (Python):
from collections import Counter
N = int(input())
v = list(map(int, input().split()))
v1 = Counter(v[::2]).most_common(2)+[(0,0)]
v2 = Counter(v[::-2]).most_common(2)+[(0,0)]
if v1[0][0] == v2[0][0]:
    print(N -max(v1[0][1]+v2[1][1],
                 v1[1][1]+v2[0][1]))
else:
    print(N-v1[0][1]-v2[0][1])

Solution (Python):
from collections import Counter

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

v1 = Counter(v[::2])
v2 = Counter(v[1::2])
v1 = v1.most_common()
v2 = v2.most_common()

no_change = 0
no_change1 = 0
no_change2 = 0

no_change1 += v1[0][1]
for i in v2:
    if i[0] != v1[0][0]:
        no_change1 += i[1]
        break

no_change2 += v2[0][1]
for i in v1:
    if i[0] != v2[0][0]:
        no_change2 += i[1]
        break

no_change = max(no_change1, no_change2)

print(n-no_change)

Solution (Python):
import heapq

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

one = V[::2]
two = V[1:][::2]

one,two

one_count={}
one_len=len(one)
for o in one:
    if o in one_count:
        one_count[o] += 1
    else:
        one_count[o] = 1

for k,v in one_count.items():
    one_count[k] = one_len-v
one_count[10**6]=one_len
temp = [[k,v] for k,v in one_count.items()]
one = heapq.nsmallest(3,temp, key=lambda x: x[1])


two_len=len(two)
two_count={}

for t in two:
    if t in two_count:
        two_count[t] += 1
    else:
        two_count[t] = 1

for k,v in two_count.items():
    two_count[k] = two_len-v
two_count[10**6]=two_len
temp = [[k,v] for k,v in two_count.items()]
two = heapq.nsmallest(3,temp, key=lambda x: x[1])

mins = 1000000

for [one_key, one_value] in one:
    for [two_key, two_value] in two:
        if one_key != two_key:
            if (one_value + two_value) < mins:
                mins = one_value + two_value
print(mins)

Solution (Python):
n = int(input())
vl = list(map(int,input().split()))
v1 = vl[::2]
v2 = vl[1::2]

def count(a):
  d = dict()
  for i in a:
    if i not in d:
      d[i] = 1
    else:
      d[i] += 1
  l = []
  for i in d:
    l.append([d[i],i])
  l.append([0,0])
  l.sort(reverse=1)
  return l

v1 = count(v1)
v2 = count(v2)
if v1[0][1] != v2[0][1]:
  print(n-v1[0][0]-v2[0][0])
elif v1[1][0]+v2[0][0] > v1[0][0]+v2[1][0]:
  print(n-v1[1][0]-v2[0][0])
else:
  print(n-v1[0][0]-v2[1][0])

Solution (Python):
n = int(input())
vl = list(map(int,input().split()))
v1 = vl[::2]
v2 = vl[1::2]

def count(a):
  d = dict()
  for i in a:
    if i not in d:
      d[i] = 1
    else:
      d[i] += 1
  l = []
  for i in d:
    l.append([d[i],i])
  l.append([0,0])
  l.sort(reverse=1)
  return l

v1 = count(v1)
v2 = count(v2)
if v1[0][0] == v1[1][0] or v2[0][0] ==v2[1][0]:
  print(n-v1[0][0]-v2[0][0])
elif v1[0][1] != v2[0][1]:
  print(n-v1[0][0]-v2[0][0])
elif v1[1][0]+v2[0][0] > v1[0][0]+v2[1][0]:
  print(n-v1[1][0]-v2[0][0])
else:
  print(n-v1[0][0]-v2[1][0])

Solution (Python):
from collections import Counter

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

odd = []
even = []

for m in range(0,n, 2):
    odd.append(V[m])
for m in range(1,n, 2):
    even.append(V[m])

odd_c = Counter(odd)
even_c = Counter(even)

odd_c_sort = sorted(odd_c.items(), key = lambda x:x[1], reverse = True)
even_c_sort = sorted(even_c.items(), key = lambda x:x[1], reverse = True)

if len(odd_c_sort) == len(even_c_sort) == 1:
    if odd_c_sort[0][0] == even_c_sort[0][0]:
        ans = n/2
    else:
        ans = 0
elif len(odd_c_sort) == 1:
    if odd_c_sort[0][0] == even_c_sort[0][0]:
        ans = n/2 - even_c_sort[1][1]
    else:
        ans = n/2 - even_c_sort[0][1]
elif len(even_c_sort) == 1:
    if even_c_sort[0][0] == odd_c_sort[0][0]:
        ans = n/2 - odd_c_sort[1][1]
    else:
        ans = n/2 - odd_c_sort[0][1]
else:
    if odd_c_sort[0][0] != even_c_sort[0][0]:
        ans = n - odd_c_sort[0][1] - even_c_sort[0][1]
    else:
        ans = min((n - odd_c_sort[0][1] - even_c_sort[1][1]), (n - odd_c_sort[1][1] - even_c_sort[0][1]))

print(int(ans))

Solution (Python):
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])
v1.sort()
v2.sort()

cnt1 = []
cnt2 = []
now = v1[0]
con = 1
for i in range(1, len(v1)):
	if now == v1[i]:
		con += 1
	else:
		cnt1.append([con, now])
		now = v1[i]
		con = 1
cnt1.append([con, now])
now = v2[0]
con = 1
for i in range(1, len(v2)):
	if now == v2[i]:
		con += 1
	else:
		cnt2.append([con, now])
		now = v2[i]
		con = 1
cnt2.append([con, now])

cnt1.sort()
cnt2.sort()
if cnt1[len(cnt1)-1][1] != cnt2[len(cnt2)-1][1]:
	p1 = [cnt1[i][0] for i in range(len(cnt1))]
	p2 = [cnt2[i][0] for i in range(len(cnt2))]
	print(sum(p1[:len(p1)-1])+sum(p2[:len(p2)-1]))
else:
	p1 = [cnt1[i][0] for i in range(len(cnt1))]
	p2 = [cnt2[i][0] for i in range(len(cnt2))]
	ans = min(sum(p1[:len(p1)-2])+p1[len(p1)-1]+sum(p2[:len(p2)-1]), sum(p1[:len(p1)-1])+p2[len(p2)-1]+sum(p2[:len(p2)-2]))
	print(ans)

Solution (Python):
n=int(input())
l=[int(i) for i in input().split()]
if len(set(l))==1:
    print(n//2)
    exit()
even=[l[i] for i in range(n) if i%2==0]
odd=[l[i] for i in range(n) if i&1]
from collections import Counter 
c1=Counter(even)
c2=Counter(odd)
a=[i for i in c1]
b=[i for i in c2]
maxi=max(c1.values())
maxi=max(maxi,max(c2.values()))
a.sort(key=lambda x:-c1[x])
b.sort(key=lambda x:-c2[x])
for a1 in a: 
    for b1 in b: 
        if a1==b1:
            continue 
        maxi=max(maxi,c1[a1]+c2[b1])
        break 
print(n-maxi)

Solution (Python):
def main():
    n = int(input())
    v = list(map(int,input().split()))
    odd={}
    even={}
    for i in range(n):
        if i%2==0:
            if v[i] not in odd:
                odd[v[i]]=1
            else:
                odd[v[i]]+=1
        else:
            if v[i] not in even:
                even[v[i]]=1
            else:
                even[v[i]]+=1
    cnt_o=[]
    cnt_e=[]
    for i in odd:
        cnt_o.append([odd[i],i])
    for i in even:
        cnt_e.append([even[i],i])
    cnt_o.append([0,10**6])
    cnt_e.append([0,10**6])
    cnt_o.sort(reverse=True)
    cnt_e.sort(reverse=True)
    if cnt_o[0][1]!=cnt_e[0][1]:
        print(n-cnt_o[0][0]-cnt_e[0][0])
        return
    else:
        print(min(n-cnt_o[1][0]-cnt_e[0][0],n-cnt_o[0][0]-cnt_e[1][0]))
        return
if __name__ == "__main__":
    main()

Solution (Python):
import collections


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

V1 = V[::2]
V2 = V[1::2]

V1_mosts = collections.Counter(V1).most_common()
V2_mosts = collections.Counter(V2).most_common()

if V1_mosts[0][0] != V2_mosts[0][0]:
    print(N - V1_mosts[0][1] - V2_mosts[0][1])

else:
    costs = []

    costs.append(N - V1_mosts[0][1] - V2_mosts[1][1] if len(V2_mosts) >= 2 else N // 2)
    costs.append(N - V2_mosts[0][1] - V1_mosts[1][1] if len(V1_mosts) >= 2 else N // 2)

    print(min(costs))

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

    ans = 0
    odic = {"0": 0}
    edic = {"0": 0}

    for i in range(int(n/2)):
        if str(v[i*2]) in odic:
            odic[str(v[i*2])] = odic[str(v[i*2])] + 1
        else:
            odic[str(v[i*2])] = 1
        if str(v[i*2 + 1]) in edic:
            edic[str(v[i*2 + 1])] = edic[str(v[i*2 + 1])] + 1
        else:
            edic[str(v[i*2 + 1])] = 1
    
    ols = sorted(odic.values(), reverse=True)
    els = sorted(edic.values(), reverse=True)


    if max(odic, key=odic.get) != max(edic, key=edic.get):
        ans = n - ols[0] - els[0]
    else:
        if ols[0]+els[1] < ols[1]+els[0]:
            ans = n - ols[1] - els[0]
        else:
            ans = n - ols[0] - els[1]

    print(ans)    

if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter

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

even = V[0::2]
odd = V[1::2]
even_counter = Counter(even).most_common(2)
odd_counter = Counter(odd).most_common(2)












if even_counter[0][0] != odd_counter[0][0]:
    ans = len(V) - even_counter[0][1] - odd_counter[0][1]
else:
    if len(even_counter) == 1 and len(odd_counter) == 1:
        ans = len(V) // 2
    else:
        ans = len(V) - max(even_counter[0][1]+odd_counter[1][1],
                           even_counter[1][1]+odd_counter[0][1])

print(ans)

Solution (Python):
from collections import Counter

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

even = V[0::2]
odd = V[1::2]
even_max_cnt = Counter(even).most_common(2)
odd_max_cnt = Counter(odd).most_common(2)

if even_max_cnt[0][0] != odd_max_cnt[0][0]:
    ans = len(V) - even_max_cnt[0][1] - odd_max_cnt[0][1]
else:
    if len(even_max_cnt) == 1 or len(odd_max_cnt) == 1:
        ans = len(V) // 2
    else:
        ans = len(V) - max(even_max_cnt[0][1]+odd_max_cnt[1][1],
                           even_max_cnt[1][1]+odd_max_cnt[0][1])

print(ans)

Solution (Python):
import collections as coll

n = int(input())
v = list(map(int,input().split()))
even = v[0::2]
odd = v[1::2]

oddc = coll.Counter(odd).most_common()[:2]
evenc = coll.Counter(even).most_common()[:2]

if(len(oddc) == 1):
	oddc.append((0,0))
if(len(evenc) == 1):
	evenc.append((0,0))


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