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

first = {}
second = {}

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

first = sorted(first.items(), key=lambda x: x[1])
second = sorted(second.items(), key=lambda x: x[1])

f = first.pop()
s = second.pop()

if f[0] == s[0]:
    if len(first) >= 1:
        if len(second) >= 1:
            f2 = first.pop()
            s2 = second.pop()

            if f2[1] + s[1] > f[1] + s2[1]:
                f = f2
            else:
                s = s2
        else:
            s = second.pop()
    elif len(second) >= 1:
        f = first.pop()
    else:
        s = (0, 0)

print(n-f[1]-s[1])

Solution (Python):
from  collections import Counter

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

c = Counter(v[::2])
d = Counter(v[1::2])

x = c.most_common()
y = d.most_common()

s = 0

if x[0][0] == y[0][0]:
    if len(x) > 1 and len(y) > 1:
        s = min(n - x[0][1] - y[1][1], n - x[1][1] - y[0][1])
    elif len(x) > 1:
        s = n - x[1][1] - y[0][1]
    elif len(y) > 1:
        s = n - x[0][1] - y[1][1]
    else:
        s = n // 2
else:
    s = n - x[0][1] - y[0][1]

print(s)

Solution (Python):
def find_max( list ):
    x = 0
    x2 = 0
    x_i = 0
    x2_i = 0
    for i in range( len(list) ):
        if x < list[i]:
            x = list[i]
            x_i = i
    for i in range( len(list) ):
        if i == x_i:
            continue
        if x2 < list[i] <= x:
            x2 = list[i]
            x2_i = i
    return x,x2,x_i,x2_i

n = int( input() )
v = list ( int(x) for x in input().split() )

v_sort = sorted( v )

v_odd = [ 0 for i in range( v_sort[-1] + 1 ) ]

v_eve = [ 0 for i in range( v_sort[-1] + 1 ) ]

for i in range( n ):
    if i % 2 == 0:
        v_eve[ v[i] ] += 1
    if i % 2 == 1:
        v_odd[ v[i] ] += 1

vex,vex2,vex_i,vex2_i = find_max( v_eve )
vox,vox2,vox_i,vox2_i = find_max( v_odd )

ok = 0

if vex_i != vox_i:
    ok = vex + vox
else:
    ok = max( vex + vox2 , vex2 + vox )

ans = n - ok
print( ans )

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
a = {}
b = {}
for i in range(n // 2):
    key_a = l[i * 2]
    key_b = l[i * 2 + 1]
    if key_a in a:
        a[key_a] = a[key_a] + 1
    else:
        a[l[i * 2]] = 1
    if key_b in b:
        b[key_b] = b[key_b] + 1
    else:
        b[key_b] = 1
a = sorted(a.items(), key=lambda x: x[1], reverse=True)
b = sorted(b.items(), key=lambda x: x[1], reverse=True)
ca_max = a[0][0]
cb_max = b[0][0]
ca_max_num = a[0][1]
cb_max_num = b[0][1]
same_num = ca_max_num + cb_max_num
if ca_max == cb_max:
    if len(a) > 1:
        next_ca_max = a[1][1]
    else:
        next_ca_max = 0
    if len(b) > 1:
        next_cb_max = b[1][1]
    else:
        next_cb_max = 0
    same_num = max(ca_max_num + next_cb_max, cb_max_num + next_ca_max)
print(n - same_num)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
a = {}
b = {}
for i in range(n // 2):
    key_a = l[i * 2]
    key_b = l[i * 2 + 1]
    if key_a in a:
        a[key_a] = a[key_a] + 1
    else:
        a[l[i * 2]] = 1
    if key_b in b:
        b[key_b] = b[key_b] + 1
    else:
        b[key_b] = 1
a = sorted(a.items(), key=lambda x: x[1], reverse=True)
b = sorted(b.items(), key=lambda x: x[1], reverse=True)




ca_max = a[0][0]
cb_max = b[0][0]
ca_max_num = a[0][1]
cb_max_num = b[0][1]
same_num = ca_max_num + cb_max_num
if ca_max == cb_max:
    if len(a) > 1:
        next_ca_max = a[1][1]
    else:
        next_ca_max = 0
    if len(b) > 1:
        next_cb_max = b[1][1]
    else:
        next_cb_max = 0
    same_num = max(ca_max_num + next_cb_max, cb_max_num + next_ca_max)
print(n - same_num)

Solution (Python):

from collections import Counter





def solve(n,v):
  if all(x == v[0] for x in v):
    return n//2
  v_even = v[::2]
  v_odd  = v[1::2]

  d_even = list(sorted(Counter(v_even).items(),key=lambda x: x[1],reverse=True))
  d_odd  = list(sorted(Counter(v_odd).items(),key=lambda x: x[1],reverse=True))
  e0 = d_even[0]
  o0 = d_odd[0]
  if e0[0] != o0[0]:
    return n - e0[1] - o0[1]
  e1 = d_even[1]
  o1 = d_odd[1]
  return min(n-e0[1]-o1[1],n-e1[1]-o0[1])



def main():
  N = int(input())
  
  v = list(map(int,input().split()))
  print(solve(N,v))
  return

if __name__ == '__main__':
  main()

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

v1 = [v[i] for i in range(n) if i%2 == 1]
v2 = [v[i] for i in range(n) if i%2 == 0]
            
import collections

v1n = collections.Counter(v1)
v2n = collections.Counter(v2)

v1ns = v1n.most_common(2)
v2ns = v2n.most_common(2)

a = v2ns[0][1]
c = v1ns[0][1]
if v1ns[0][0]!=v2ns[0][0]:
    print(n-a-c)
else:
    if len(v1ns)==1:
        d = 0
    else:
        d = v1ns[1][1]
    if len(v2ns)==1:
        b = 0
    else:
        b = v2ns[1][1]
    print(min(n-a-d,n-c-b))

Solution (Python):
import collections
N = int(input())

O = []
E = []
A = list(map(lambda a: int(a), input().split(" ")))
for i in range(N):
  if i % 2 == 0:
    E.append(A[i])
  else:
    O.append(A[i])

CE = collections.Counter(E)
CO = collections.Counter(O)
CE2 = CE.most_common(2)
CO2 = CO.most_common(2)
if CE2[0][0] != CO2[0][0]:
  print(len(E) + len(O) - CE2[0][1] - CO2[0][1])
elif CE2[0][0] == CO2[0][0]:
  if len(CE2) == 1 and len(CO2) == 1:
    print(min([CE2[0][1], CO2[0][1]]))
  elif len(CE2) > 1 and len(CO2) == 1:
    print(len(E) + len(O) - CE2[1][1] - CO2[0][1])
  elif len(CE2) == 1 and len(CO2) > 1:
    print(len(E) + len(O) - CE2[0][1] - CO2[1][1])
  elif CE2[0][1] + CO2[1][1] > CO2[0][1] + CE2[1][1]:
    print(len(E) + len(O) - CE2[0][1] - CO2[1][1])
  elif CE2[0][1] + CO2[1][1] <= CO2[0][1] + CE2[1][1]:
    print(len(E) + len(O) - CE2[1][1] - CO2[0][1])

Solution (Python):
import sys
from collections import Counter
from operator import itemgetter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    n, *V = map(int, read().split())

    counter1 = Counter(V[::2])
    counter2 = Counter(V[1::2])

    vec1 = sorted(counter1.items(), reverse=True, key=itemgetter(1))
    vec2 = sorted(counter2.items(), reverse=True, key=itemgetter(1))

    if vec1[0][0] != vec2[0][0]:
        ans = n - vec1[0][1] - vec2[0][1]
    elif len(vec1) == len(vec2) == 1:
        ans = n // 2
    else:
        tmp = []
        if len(vec1) > 1:
            tmp.append(vec1[1][1] + vec2[0][1])
        if len(vec2) > 1:
            tmp.append(vec1[0][1] + vec2[1][1])
        ans = n - max(tmp)

    print(ans)

    return


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
a=[0]*(10**5)
b=[0]*(10**5)
s,t=0,0
o,e,oi,ei=0,0,0,0
for i in range(1,n+1):
    if i%2==1:
        a[v[i-1]-1]+=1
        s+=1
    else:
        b[v[i-1]-1]+=1
        t+=1
o=max(a)
oi=[]
e=max(b)
ei=[]
for i in range(10**5):
    if a[i]==o:
        oi.append(i)
    if b[i]==e:
        ei.append(i)
if len(oi)==1 and len(ei)==1 and oi[0]==ei[0]:
    a.sort(reverse=True)
    b.sort(reverse=True)
    print(min(t-e+s-a[1],t-b[1]+s-o))
else:
    print(s+t-e-o)

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
odd = [0] * (10 ** 5 + 5)
even = [0] * (10 ** 5 + 5)
for i in range(n):
    if i % 2 == 0:
        even[v[i]] += 1
    else:
        odd[v[i]] += 1
sum_odd = sum(odd)
sum_even = sum(even)
ans = sum_odd + sum_even
max_odd = max(odd)
max_even = max(even)
if odd.index(max_odd) != even.index(max_even):
    print(sum_odd + sum_even - max_even - max_odd)
else:
    odd.sort()
    even.sort()
    if odd[-1] - odd[-2] > even[-1] - even[-2]:
        ans -= odd[-1] + even[-2]
    else:
        ans -= odd[-2] + even[-1]
    print(ans)

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

o = Counter(v[::2]).most_common()
e = Counter(v[1::2]).most_common()
if o[0][0] == e[0][0]:
  if len(o) == 1: print(e[0][1])
  else:
    o1,o2 = e[0][1], e[1][1]
    e1,e2 = o[0][1], o[1][1]
  
    ans = min(n-o1-o2, n-e1-e2)
    print(ans)
else: print(n-o[0][1]-e[0][1])

Solution (Python):
from collections import Counter
n = int(input())
ls = list(map(int,input().split()))
lso = ls[::2]
lse = ls[1::2]
lso.sort()
lse.sort(reverse=True)
co = Counter(lso)
ce = Counter(lse)
co1,co2 = co.most_common()[0][0],co.most_common()[0][1]
ce1,ce2 = ce.most_common()[0][0],ce.most_common()[0][1]
coo1,coo2,cee1,cee2 = 0,0,0,0
if co2 != n//2:
    coo1,coo2 = co.most_common()[1][0],co.most_common()[1][1]
if ce2 != n//2:
    cee1,cee2 = ce.most_common()[1][0],ce.most_common()[1][1]
if co1 == ce1:
    print(n-max(co2+cee2,ce2+coo2))
else:
    print(n-co2-ce2)

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

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

if f[0][0]!=b[0][0]:print(n-f[0][1]-b[0][1]);exit()

if f[0][1]==n//2:print(n//2)
else:print(n-b[0][1]-f[1][1] if f[1][1]>b[1][1] else n-f[0][1]-b[1][1])

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

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
m=n//2
x=[a[i] for i in range(n) if i%2==0] 
y=[a[i] for i in range(n) if i%2==1] 
x=sorted(x)
y=sorted(y)
inx=[]
iny=[]
p=1
q=1

for i in range(m-1):
    if x[i]==x[i+1]:
        p+=1
    else:
        inx.append([p,x[i]])
        p=1
inx.append([p,x[-1]])
for i in range(m-1):
    if y[i]==y[i+1]:
        q+=1
    else:
        iny.append([q,y[i]])
        q=1
iny.append([q,y[-1]])
inx=sorted(inx)
iny=sorted(iny)
inx.insert(0,[0,0])
iny.insert(0,[0,0])

if inx[-1][1]!=iny[-1][1]:
    print(2*m-inx[-1][0]-iny[-1][0])
else:
    print(min(2*m-inx[-1][0]-iny[-2][0],2*m-inx[-2][0]-iny[-1][0]))

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
odd = dict()
even = dict()
odd[-1] = 0
even[-1] = 0

for i in range(n):
    if (i + 1) % 2 == 1:
        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

odd_values = sorted(list(odd.values()), reverse=True)
for key, val in odd.items():
    if val == odd_values[0]:
        odd_1 = key
    elif val == odd_values[1]:
        odd_2 = key

even_values = sorted(list(even.values()), reverse=True)
for key, val in even.items():
    if val == even_values[0]:
        even_1 = key
    elif val == even_values[1]:
        even_2 = key

if odd_1 != even_1:
    res = n - odd_values[0] - even_values[0]
else:
    res = min(n - odd_values[0] - even_values[1], 
              n - odd_values[1] - even_values[0])
print(res)

Solution (Python):
import sys
from collections import Counter


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    V = nl()
    V_e = V[0::2]
    V_o = V[1::2]
    V_e_c = Counter(V_e)
    V_o_c = Counter(V_o)

    if V_e_c.most_common()[0][0] != V_o_c.most_common()[0][0]:
        ans = len(V) - \
            V_e_c.most_common()[0][1] - V_o_c.most_common()[0][1]

    else:
        if len(V_e_c.most_common()) == 1 or len(V_o_c.most_common()) == 1:
            if len(V_e_c.most_common()) == 1 and len(V_o_c.most_common()) == 1:
                ans = len(V) // 2
            else:
                if len(V_e_c.most_common()) != 1:
                    ans = len(V) // 2 - V_e_c.most_common()[1][1]
                else:
                    ans = len(V) // 2 - V_o_c.most_common()[1][1]

        else:
            ans = len(V) - max(
                V_e_c.most_common()[0][1] + V_o_c.most_common()[1][1],
                V_e_c.most_common()[1][1] + V_o_c.most_common()[0][1],
            )

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import Counter


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def get_ans(v, ans):
    while len(v) != 1:
        ans += v.pop()
    return ans


def main():
    n = ni()
    V = nl()
    V_e = V[0::2]
    V_o = V[1::2]
    V_e_c = Counter(V_e)
    V_o_c = Counter(V_o)
    
    

    if V_e_c.most_common()[0][0] != V_o_c.most_common()[0][0]:
        ans = len(V) - \
            V_e_c.most_common()[0][1] - V_o_c.most_common()[0][1]

    else:
        if len(V_e_c.most_common()) == 1 or len(V_o_c.most_common()) == 1:
            if len(V_e_c.most_common()) == 1 and len(V_o_c.most_common()) == 1:
                ans = len(V) // 2
            else:
                if len(V_e_c.most_common()) != 1:
                    ans = len(V) // 2 - V_e_c.most_common()[1][1]
                else:
                    ans = len(V) // 2 - V_o_c.most_common()[1][1]

        else:
            ans = len(V) - max(
                V_e_c.most_common()[0][1] + V_o_c.most_common()[1][1],
                V_e_c.most_common()[1][1] + V_o_c.most_common()[0][1],
            )

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import collections

n = int(input())
v = [int(i) for i in input().split()]
con_odd = []
con_even = []
for i in range(0,n,2):
    con_odd.append(v[i]) 
    con_even.append(v[i+1])

b = collections.Counter(con_odd)
c = sorted(b.items(), key=lambda x:x[1],reverse = True)
b_2 = collections.Counter(con_even)
c_2 = sorted(b_2.items(), key=lambda x:x[1],reverse = True)
if len(c) == 1 and len(c_2) == 1:
    if c[0][0] == c_2[0][0]:
        ans = n//2
    else:
        ans = 0
elif len(c) == 1 or len(c_2) == 1:
    if c[0][0] == c_2[0][0]:
        if len(c) == 1:
            ans_1 = len(con_odd) - c[0][1]
            ans_2 = len(con_even) - c_2[1][1]
            ans = ans_1 + ans_2
        else:
            ans_1 = len(con_odd) - c[1][1]
            ans_2 = len(con_even) - c_2[0][1]
            ans = ans_1 + ans_2
    else:
        ans_1 = len(con_odd) - c[0][1]
        ans_2 = len(con_even) - c_2[0][1]
        ans = ans_1 + ans_2
            
elif c[0][0] == c_2[0][0]:
    if c[0][1] + c_2[1][1] > c[1][1] + c_2[0][1]:
        ans_1 = len(con_odd) - c[0][1]
        ans_2 = len(con_even) - c_2[1][1]
        ans = ans_1 + ans_2
    else:
        ans_1 = len(con_odd) - c[1][1]
        ans_2 = len(con_even) - c_2[0][1]
        ans = ans_1 + ans_2
else:
    ans_1 = len(con_odd) - c[0][1]
    ans_2 = len(con_even) - c_2[0][1]
    ans = ans_1 + ans_2
print(ans)

Solution (Python):
n=int(input())
ar=[int(i) for i in input().strip().split(" ")]
from collections import defaultdict
ev=defaultdict(int)
od=defaultdict(int)

def g(i):
    return (i[1],i[0])

for i in range(0,n,2):
    od[ar[i]]+=1

for i in range(1,n,2):
    ev[ar[i]]+=1

odd=list(od.items())
even=list(ev.items())
odd.append((0,0))
even.append((0,0))
odd.sort(key=g)
even.sort(key=g)

o1=odd[-1]
o2=odd[-2]
e1=even[-1]
e2=even[-2]
if o1[0]!=e1[0]:
    print(n-o1[1]-e1[1])
else:
    a1=(n-o1[1]-e2[1])
    a2=(n-o2[1]-e1[1])
    print(min(a1,a2))

Solution (Python):
n=int(input())
l=list(map(int, input().split()))
l1=l[0::2]
l2=l[1::2]
import collections
c1 = collections.Counter(l1)


c2 =collections.Counter(l2)  
c0 =collections.Counter(l)
if len(c0)==1:
  print(int(n/2))
else:
  if c1.most_common()[0]==c2.most_common()[0]:
    print(min(n-c1.most_common()[0][1]-c2.most_common()[1][1], n-c1.most_common()[1][1]-c2.most_common()[0][1]))
  else:
    print(n-c1.most_common()[0][1]-c2.most_common()[0][1])

Solution (Python):
import collections

n=int(input())
m=n//2
a=list(map(int,input().split()))
g=[]
k=[]
for x in range(n):
  if (x+1)%2==1:
    k.append(a[x])
  else:
    g.append(a[x])
    
gg=collections.Counter(g)
kk=collections.Counter(k)
aa=collections.Counter(a)

if len(aa)==1:
  print(n//2)
  
else:
  if gg.most_common()[0]==kk.most_common()[0]:
    
      print(min(m-gg.most_common()[0][1]+m-kk.most_common()[1][1],m-kk.most_common()[0][1]+m-gg.most_common()[1][1]))
   
     
  else:
    print(n-gg.most_common()[0][1]-kk.most_common()[0][1])

Solution (Python):
import collections

n=int(input())
m=n//2
a=list(map(int,input().split()))
g=[]
k=[]
for x in range(n):
  if (x+1)%2==1:
    k.append(a[x])
  else:
    g.append(a[x])
    
gg=collections.Counter(g)
kk=collections.Counter(k)
aa=collections.Counter(a)

if len(aa)==1:
  print(n//2)
  
else:
  if gg.most_common()[0]==kk.most_common()[0]:
    if len(gg)>1 and len(kk)>1:
      print(min(m-gg.most_common()[0][1]+m-kk.most_common()[1][1],m-kk.most_common()[0][1]+m-gg.most_common()[1][1]))
    elif len(gg)==1:
      print(m-kk.most_common()[1][1])
    else:
      print(m-gg.most_common()[1][1])
  else:
    print(n-gg.most_common()[0][1]-kk.most_common()[0][1])

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
a = v[1::2]
b = v[0::2]
a2 = Counter(a)
b2 = Counter(b)

if a2.most_common()[0][0] != b2.most_common()[0][0]:
    print(n-a2.most_common()[0][1]-b2.most_common()[0][1])
else:
    if len(a2.most_common()) == len(b2.most_common()) == 1:
        print(len(a)-a2.most_common()[0][1]+len(b))
    elif len(a2.most_common()) == 1:
        if len(b)-b2.most_common()[1][1] >= len(a)+len(b)-b2.most_common()[0][1]:
            print(len(a)+len(b)-b2.most_common()[0][1])
        else:
            print(len(b)-b2.most_common()[1][1])
    elif len(b2.most_common()) == 1:
        if len(a)-a2.most_common()[1][1] >= len(a)+len(b)-a2.most_common()[0][1]:
            print(len(a)+len(b)-a2.most_common()[0][1])
        else:
            print(len(a)-a2.most_common()[1][1])
    else:
        if len(a)-a2.most_common()[0][1]+len(b)-b2.most_common()[1][1] >= len(a)-a2.most_common()[1][1]+len(b)-b2.most_common()[0][1]:
            print(len(a)-a2.most_common()[1][1]+len(b)-b2.most_common()[0][1])
        else:
            print(len(a)-a2.most_common()[0][1]+len(b)-b2.most_common()[1][1])

Solution (Python):
from collections import Counter

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

kisu = A[0::2]
gusu = A[1::2]

CK = Counter(kisu)
CG = Counter(gusu)
CKM = CK.most_common(2)
CGM = CG.most_common(2)

if len(CKM) == 1 and len(CGM) == 1:
    if CKM[0][0] == CGM[0][0]:
        ans = n // 2
    else:
        ans = 0
elif len(CKM) == 1:
    if CKM[0][0] == CGM[0][0]:
        ans = n // 2 - CGM[1][1]
    else:
        ans = n // 2 - CGM[0][1]
elif len(CGM) == 1:
    if CKM[0][0] == CGM[0][0]:
        ans = n // 2 - CKM[1][1]
    else:
        ans = n // 2 - CKM[0][1]
else:
    if CKM[0][0] == CGM[0][0]:
        ans1 = n // 2 - CKM[1][1] + n // 2 - CGM[0][1]
        ans2 = n // 2 - CGM[1][1] + n // 2 - CKM[0][1]
        ans = min(ans1, ans2)
    else:
        ans = n - (CKM[0][1] + CGM[0][1])

print(ans)

Solution (Python):
import copy
import numpy as np

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

cnta = np.zeros(10**5+1, dtype=int)
cntb = np.zeros(10**5+1, dtype=int)
for i in range(n//2):
    ca, cb = a[i], b[i]
    cnta[ca] += 1
    cntb[cb] += 1

la = np.zeros((2,2), dtype=int)
lb = np.zeros((2,2), dtype=int)
for i in range(2):
    ia = cnta.argmax()
    ib = cntb.argmax()
    la[i][0], la[i][1] = ia, cnta[ia]
    lb[i][0], lb[i][1] = ib, cntb[ib]
    cnta[ia] = 0
    cntb[ib] = 0

if la[0][0] != lb[0][0]:
    ans = n//2 - la[0][1] + n//2 - lb[0][1]
else:
    ans = min(n//2 - la[0][1] + n//2 - lb[1][1], n//2 - la[1][1] + n//2 - lb[0][1])
print(ans)

Solution (Python):
import collections as co
if __name__ == '__main__':

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

	S = A[1::2]
	T = A[0::2]

	total_cnt = 0

	
	U = set(A)
	if len(U) == 1:
		total_cnt = len(A[1::2])
		print(total_cnt)
		exit()

	c1 = []
	c2 = []
	
	s = co.Counter(S)
	c1 = s.most_common()
	
	c1.append((0,0))
	
	t = co.Counter(T)
	c2 = t.most_common()
	
	c2.append((0,0))


	
	
	if c1[0][0] != c2[0][0]:
		
		total_cnt = len(S) - c1[0][1] 
		total_cnt += len(T) - c2[0][1]
	else:
		
		if c1[0][1] > c2[0][1]:
			total_cnt = len(S) - c1[0][1]
			total_cnt += len(T) - c2[1][1]
		elif c1[0][1] < c2[0][1]:
			total_cnt = len(S) - c1[1][1]
			total_cnt += len(T) - c2[0][1]
		else:
			
			if c1[1][1] > c2[0][1]:
				total_cnt = len(S) - c1[1][1]
				total_cnt += len(T) - c2[0][1]
			elif c1[1][1] < c2[1][1]:
				total_cnt = len(T) - c2[1][1]
				total_cnt += len(S) - c1[0][1]
			else:
				
				total_cnt = len(S) - c1[1][1]
				total_cnt += len(T) - c2[0][1]
				
	print(total_cnt)

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

ans = 0
eve = V[0::2]
odd = V[1::2]
cntEve = collections.Counter(eve)
cntOdd = collections.Counter(odd)

if cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]:
    if len(cntEve) == 1 and len(cntOdd) > 1:
        ans = N - max(cntEve.most_common()[0][1],cntOdd.most_common()[0][1]) - cntOdd.most_common()[1][1]
    elif len(cntEve) > 1 and len(cntOdd) == 1:
        ans = N - max(cntEve.most_common()[0][1],cntOdd.most_common()[0][1]) - cntEve.most_common()[1][1]
    elif len(cntEve) == 1 and len(cntOdd) == 1:
        ans = N - max(cntEve.most_common()[0][1],cntOdd.most_common()[0][1])
    else:
        ans = N - max(cntEve.most_common()[0][1],cntOdd.most_common()[0][1]) - max(cntEve.most_common()[1][1],cntOdd.most_common()[1][1])
else:
    ans = N - int(cntEve.most_common()[0][1]) - int(cntOdd.most_common()[0][1])

print(ans)

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy


from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()

cnt_even = Counter(a[::2]).most_common()+[(0,0)]
cnt_odd = Counter(a[1::2]).most_common()+[(0,0)]

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

print(ans)

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy


from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()

cnt_even = defaultdict(int)
cnt_odd = defaultdict(int)
for i in range(0,n,2):
  cnt_even[a[i]] += 1
for i in range(1,n,2):
  cnt_odd[a[i]] += 1

cnt_even = list(reversed(sorted(cnt_even.items(),key=lambda x:x[1])))
cnt_odd  = list(reversed(sorted(cnt_odd.items(),key=lambda x:x[1])))

flg = False
for i in range(min(2,len(cnt_even),len(cnt_odd))):
  a,b = (cnt_even[i],cnt_odd[i])
  if a[0] != b[0]:
    if flg == False:
      n -= a[1]+b[1]
    else:
      n -= max(a[1],b[1])
    break
  else:
    n -= a[1]
    flg = True

print(n)

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

A={0:0}
B={0:0}
for i in range(N):
    v=V[i]
    if i%2==0:
        if v in A:
            A[v]+=1
        else:
            A[v]=1
    else:
        if v in B:
            B[v]+=1
        else:
            B[v]=1

P=max(A,key=lambda x:A[x])
Q=max(B,key=lambda x:B[x])

if P!=Q:
    print(N-(A[P]+B[Q]))
else:
    X=A[P]
    del A[P]
    R=max(A,key=lambda x:A[x])

    Y=B[Q]
    del B[Q]
    S=max(B,key=lambda x:B[x])

    print(N-max(X+A[R],Y+B[S]))

Solution (Python):
from collections import defaultdict
ODD = defaultdict(int)
EVEN = defaultdict(int)
ALL = set([])
N = int(input())

A = list(map(int,input().split()))
for i in range(N):
  ALL.add(A[i])
  if i%2 == 0:
    EVEN[A[i]] += 1
  else:
    ODD[A[i]] += 1
if len(ALL) == 1:
  ans = N//2
  print(ans)
  exit()
modd = max(ODD.values())
meven = max(EVEN.values())
mlodd = [];mleven = []
dicodd = sorted(ODD.items(), key=lambda x:x[1], reverse = True)
diceven = sorted(EVEN.items(), key=lambda x:x[1], reverse = True)
ans = N
if len(dicodd) > 1:
  X = [dicodd[0],dicodd[1]]
else:
  X = [dicodd[0]]
if len(diceven) > 1:
  Y = [diceven[0],diceven[1]]
else:
  Y = [diceven[0]]


for x,v in X:
  for y,w in Y:
    if x == y:
      continue
    temp = N-(v+w)
    ans = min(ans,temp)

print(ans)

Solution (Python):




import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()//2
lis=LI()
lis1=[]
lis2=[]
for i in range(n):
    lis1.append(lis[2*i])
    lis2.append(lis[2*i+1])
x=Counter(lis1).most_common(2)
y=Counter(lis2).most_common(2)


if len(x)==1:
    x.append((0,0))
if len(y)==1:
    y.append((-1,0))


if x[0][0]!=y[0][0]:
    print(2*n-x[0][1]-y[0][1])
else:
    cands=[]
    
    if x[1][0]!=y[0][0]:
        cands.append(2*n-x[1][1]-y[0][1])
    if x[0][0]!=y[1][0]:
        cands.append(2*n-x[0][1]-y[1][1])
    if x[1][0]!=y[1][0]:
        cands.append(2*n-x[1][1]-y[1][1])
    print(min(cands))

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

Solution (Python):
n = int(input())
V = list(map(int,input().split()))
Ce = {}
Co = {}
for i in range(n):
    v = V[i]
    if i%2==0:
        if v not in Ce:
            Ce[v]=0
        Ce[v] += 1
    else:
        if v not in Co:
            Co[v]=0
        Co[v] += 1
Ce = sorted(list(Ce.items()),key=lambda x:x[1],reverse=True)
Co = sorted(list(Co.items()),key=lambda x:x[1],reverse=True)
if Ce[0][0]!=Co[0][0]:
    cnt = 0
    for i in range(1,len(Ce)):
        cnt += Ce[i][1]
    for i in range(1,len(Co)):
        cnt += Co[i][1]
    print(cnt)
else:
    cnt1 = 0
    for i in range(1,len(Ce)):
        cnt1 += Ce[i][1]
    if Ce[0][1]>n//2:
        cnt1 += Ce[0][1]-n//2
    cnt1 += Co[0][1]
    for i in range(2,len(Co)):
        cnt1 += Co[i][1]
    cnt2 = 0
    for i in range(1,len(Co)):
        cnt2 += Co[i][1]
    if Co[0][1]>n//2:
        cnt2 += Co[0][1]-n//2
    cnt2 += Ce[0][1]
    for i in range(2,len(Ce)):
        cnt2 += Ce[i][1]
    print(min(cnt1,cnt2))

Solution (Python):
from collections import Counter
from heapq import heappop,heappush

N = int(input())
V = list(map(int, input().split()))
odd = Counter(V[::2])
odd[10**6] = 0
even = Counter(V[1::2])
even[10**6] = 0
heapodd = []
heapeven = []
for k,v in odd.items():
    heappush(heapodd,(-v,k))
for k,v in even.items():
    heappush(heapeven,(-v,k))

vo1,odd1 = heappop(heapodd)
vo2,odd2 = heappop(heapodd)
ve1,even1 = heappop(heapeven)
ve2,even2 = heappop(heapeven)

if odd1 != even1:
  print(N + vo1 + ve1)
else:
  print(min(N+ve1+vo2,N+vo1+ve2))

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

zero_d = {}
one_d = {}
for i,v in enumerate(vl):
    if i%2 == 0:
        zero_d.setdefault(v,0)
        zero_d[v] += 1
    else:
        one_d.setdefault(v,0)
        one_d[v] += 1

zero_l = sorted(zero_d.items(), reverse=True, key=lambda x:x[1])
one_l = sorted(one_d.items(), reverse=True, key=lambda x:x[1])


zero_l.append((-1,0))
one_l.append((-1,0))

zero_cnt = (n+1)//2
one_cnt = n//2
if zero_l[0][0] != one_l[0][0]:
    ans = n - zero_l[0][1] - one_l[0][1]
else:
    ans1 = n - zero_l[0][1] - one_l[1][1]
    ans2 = n - zero_l[1][1] - one_l[0][1]
    ans = min(ans1,ans2)

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
from collections import *

n = int(input())
v = list(map(int, input().split()))
cnt1 = Counter([v[i] for i in range(n) if i%2==0])
cnt2 = Counter([v[i] for i in range(n) if i%2==1])
cnt1[-1] = 0
cnt2[-1] = 0
k1 = [k for k in cnt1.keys()]
k1.sort(key=lambda x: cnt1[x], reverse=True)
k2 = [k for k in cnt2.keys()]
k2.sort(key=lambda x: cnt2[x], reverse=True)

if k1[0]!=k2[0]:
    print(n-cnt1[k1[0]]-cnt2[k2[0]])
else:
    print(min(n-cnt1[k1[0]]-cnt2[k2[1]], n-cnt1[k1[1]]-cnt2[k2[0]]))