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

Solution (Python):
import math
import collections
from operator import mul
from functools import reduce



n=int(input())
v=list(map(int,input().split()))
v1=sorted(v[::2])
v2=sorted(v[1::2])

c1 = collections.Counter(v1).most_common(2)
c2 = collections.Counter(v2).most_common(2)

m1=10000000000000000000000


for ci1 in c1:
    for ci2 in c2:
        if ci1[0]!=ci2[0]:
            m1=min(m1,(len(v1)-ci1[1])+(len(v2)-ci2[1]))
        else:
            m1=min(m1,(len(v1)-ci1[1])+(len(v2)))
            m1=min(m1,(len(v2)-ci2[1])+(len(v1)))
print(m1)

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

judge_2n_1 = {}
judge_2n = {}

for i in range(n):
    if i % 2 == 0:
        if v[i] not in judge_2n_1.keys():
            judge_2n_1[v[i]] = 1
        else:
            judge_2n_1[v[i]] += 1
    else:
        if v[i] not in judge_2n.keys():
            judge_2n[v[i]] = 1
        else:
            judge_2n[v[i]] += 1

judge_2n = sorted(judge_2n.items(), key=lambda x: x[1], reverse=True)
judge_2n_1 = sorted(judge_2n_1.items(), key=lambda x: x[1], reverse=True)
answer = n - 1

for i in judge_2n[:2]:
    for j in judge_2n_1[:2]:
        if i[0] != j[0]:
            answer = min(answer, n - i[1] - j[1])
        else:
            answer = min(answer, n - max(i[1], j[1]))

print(answer)

Solution (Python):
import collections

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

vlist1=[vlist[2*i] for i in range(n//2)]
vlist2=[vlist[2*i+1] for i in range(n//2)]



vc1=collections.Counter(vlist1).most_common()
vc2=collections.Counter(vlist2).most_common()



if vc1[0][0]!=vc2[0][0]:
    print(n-vc1[0][1]-vc2[0][1])
elif len(vc1)==1 and len(vc2)==1:
    print(n//2)
elif len(vc1)==1:
    print(n//2-vc2[1][1])
elif len(vc2)==1:
    print(n//2-vc1[1][1])
else:
    if vc1[0][1]>vc2[0][1]:
        print(n-vc1[0][1]-vc2[1][1])
    elif vc1[0][1]<vc2[0][1]:
        print(n-vc1[1][1]-vc2[0][1])
    else:
        max_2nd=max(vc1[1][1],vc2[1][1])
        print(n-vc1[0][1]-max_2nd)

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

count1 = {}
count2 = {}

for i in range(n):
    if i%2==0:
        if lst[i] in count1:
            count1[lst[i]] += 1
        else:
            count1[lst[i]] = 1
    else:
        if lst[i] in count2:
            count2[lst[i]] += 1
        else:
            count2[lst[i]] = 1

sorted1 = sorted(count1.items(), key=lambda x:x[1], reverse=True)
sorted2 = sorted(count2.items(), key=lambda x:x[1], reverse=True)

sorted1.append((-1,0))
sorted2.append((-1,0))

if sorted1[0][0]!=sorted2[0][0]:
    print(n-sorted1[0][1]-sorted2[0][1])
else:
    a = n-sorted1[0][1]-sorted2[1][1]
    b = n-sorted1[1][1]-sorted2[0][1]
    print(min(a,b))

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

cnt1 = {}
cnt2 = {}

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

sorted_cnt1 = sorted(cnt1.items(), key = lambda x: x[1], reverse = True)
sorted_cnt2 = sorted(cnt2.items(), key = lambda x: x[1], reverse = True)

sorted_cnt1.append((-1,0))
sorted_cnt2.append((-1,0))

if sorted_cnt1[0][0] != sorted_cnt2[0][0]:
    print(n - sorted_cnt1[0][1] - sorted_cnt2[0][1])
else:
    print(n - max(sorted_cnt1[0][1] + sorted_cnt2[1][1], sorted_cnt1[1][1]+sorted_cnt2[0][1]))

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

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

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

judge_2n_1 = {}
judge_2n = {}

for i in range(n):
    if i % 2 == 0:
        if v[i] not in judge_2n_1.keys():
            judge_2n_1[v[i]] = 1
        else:
            judge_2n_1[v[i]] += 1
    else:
        if v[i] not in judge_2n.keys():
            judge_2n[v[i]] = 1
        else:
            judge_2n[v[i]] += 1

judge_2n = sorted(judge_2n.items(), key=lambda x: x[1], reverse=True)
judge_2n_1 = sorted(judge_2n_1.items(), key=lambda x: x[1], reverse=True)
answer = n - 1

for i in judge_2n[:2]:
    for j in judge_2n_1[:2]:
        if i[0] != j[0]:
            answer = min(answer, n - i[1] - j[1])
        else:
            answer = min(answer, n - max(i[1], j[1]))

print(answer)

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

judge_2n_1={}
judge_2n={}

for i in range(n):
    if i%2==0:
        if v[i] not in judge_2n_1.keys():
            judge_2n_1[v[i]]=1
        else:
            judge_2n_1[v[i]]+=1
    else:
        if v[i] not in judge_2n.keys():
            judge_2n[v[i]]=1
        else:
            judge_2n[v[i]]+=1




judge_2n=sorted(judge_2n.items(),key=lambda x:x[1],reverse=True)
judge_2n_1=sorted(judge_2n_1.items(),key=lambda x:x[1],reverse=True)
answer=n-1

for i in judge_2n[:2]:
    for j in judge_2n_1[:2]:
        if i[0]!=j[0]:
            answer=min(answer,n-i[1]-j[1])
        else:
            answer=min(answer,n-max(i[1],j[1]))
print(answer)

Solution (Python):
import collections

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

vlist1=[vlist[2*i] for i in range(n//2)]
vlist2=[vlist[2*i+1] for i in range(n//2)]



vc1=collections.Counter(vlist1).most_common()
vc2=collections.Counter(vlist2).most_common()



if vc1[0][0]!=vc2[0][0]:
  print(n-vc1[0][1]-vc2[0][1])
elif len(vc1)==1 and len(vc2)==1:
  print(n//2)
elif len(vc1)==1:
  print(n//2-vc2[1][1])
elif len(vc2)==1:
  print(n//2-vc1[1][1])
else:
  if vc1[0][1]>vc2[0][1]:
    print(n-vc1[0][1]-vc2[1][1])
  elif vc1[0][1]<vc2[0][1]:
    print(n-vc1[1][1]-vc2[0][1])
  else:
    max_2nd=max(vc1[1][1],vc2[1][1])
    print(n-vc1[0][1]-max_2nd)

Solution (Python):
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
VO=[]
VE=[]
for i in range(n):
  if i%2==1:
    VO.append(V[i])
  else:
    VE.append(V[i])
vo=Counter(VO).most_common(2)
ve=Counter(VE).most_common(2)
if ve[0][0]!=vo[0][0]:
  ans=n-ve[0][1]-vo[0][1]
else:
  if len(ve)==1 and len(vo)==1:
    ans=n//2
  elif len(ve)==1:
    ans=n-ve[0][1]-vo[1][1]
  elif len(vo)==1:
    ans=n-vo[0][1]-ve[1][1]
  else:
    ans=min((n-ve[0][1]-vo[1][1]),(n-vo[0][1]-ve[1][1]))    
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
*v, = map(int, input().split())
v_even, v_odd = v[::2], v[1::2]
even = Counter(v_even).most_common(2)
odd = Counter(v_odd).most_common(2)

ans = 0

if even[0][0] != odd[0][0]:
    ans = n - odd[0][1] - even[0][1]

else:
    if len(even) == 1 and len(odd) == 1:
        ans = n // 2
        
    elif len(even) == 1:
        ans = n - even[0][1] - odd[1][1]
        
    elif len(odd) == 1:
        ans = n - even[1][1] - odd[0][1]
        
    else:
        ans = min(n - even[0][1] - odd[1][1], 
                  n - even[1][1] - odd[0][1])
                  
print(ans)

Solution (Python):
N=int(input())
V1,V2={},{}
ans = N-1
for n,i in enumerate(list(map(int,input().split(' ')))):
    if n%2==0:
        V1.setdefault(i,0)
        V1[i]+=1
    else:
        V2.setdefault(i,0)
        V2[i]+=1
V1=sorted(V1.items(),key=lambda x:x[1],reverse=True)
V2=sorted(V2.items(),key=lambda x:x[1],reverse=True)
cut = max(V1[0][1],V2[0][1])
for i in V1[:2]:
    for j in V2[:2]:
        if i[0]!=j[0]:
            ans = min(ans,N-i[1]-j[1])
        else:
            ans = min(ans,N-max(i[1],j[1]))
print(ans)

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

list_Vx = []
list_Vy = []

for i, s in enumerate(list_V):
    if i % 2 == 0:
        list_Vx.append(s)
    else:
        list_Vy.append(s)

list_Vx_Count = [0 for _ in range(pow(10, 5))]
list_Vy_Count = [0 for _ in range(pow(10, 5))]

for i in list_Vx:
    list_Vx_Count[i-1] += 1
for i in list_Vy:
    list_Vy_Count[i-1] += 1

ans = n - max(list_Vx_Count) - max(list_Vy_Count)

if list_Vx_Count.count(max(list_Vx_Count)) == 1 and list_Vy_Count.count(max(list_Vy_Count)):
    if list_Vx_Count.index(max(list_Vx_Count)) == list_Vy_Count.index(max(list_Vy_Count)):
        ans = n - max(max(list_Vx_Count)+sorted(list_Vx_Count)[-2], max(list_Vy_Count)+sorted(list_Vy_Count)[-2])

print(ans)

Solution (Python):
from collections import Counter

n,*v = map(int,open(0).read().split())
v0,v1 = Counter(v[::2]),Counter(v[1::2])
len0,len1 = len(v0),len(v1)
if len0==1 and len1==1:
    if v0.keys() != v1.keys():
        print(0)
    else:
        sv = sorted(v1.values())[0]
        print(sv)
elif len0 == 1:
    print(sum(v1.values()) - max(v1.values()))
elif len1 == 1:
    print(sum(v0.values()) - max(v0.values()))
else:
    v0_1,v0_2 = v0.most_common(2)
    v1_1,v1_2 = v1.most_common(2)
    if v0_1[0] != v1_1[0]:
        sum0 = sum(v0.values()) - v0_1[1]
        sum1 = sum(v1.values()) - v1_1[1]
        print(sum0 + sum1)
    else:
        sum0 = sum(v0.values())
        sum1 = sum(v1.values())
        sum0_1 = sum0 - v0_1[1]
        sum0_2 = sum0 - v0_2[1]
        sum1_1 = sum1 - v1_1[1]
        sum1_2 = sum1 - v1_2[1]
        print(min(sum0_1 + sum1_2 , sum0_2 + sum1_1))

Solution (Python):
n,*v = map(int,open(0).read().split())
v0,v1 = {},{}
flg = True
for i in v:
    if flg:
        v0[i]= v0[i]+1 if i in v0 else 1
    else:    
        v1[i]= v1[i]+1 if i in v1 else 1
    flg = not flg
len0,len1 = len(v0),len(v1)
if len0==1 and len1==1:
    if v0.keys() != v1.keys():
        print(0)
    else:
        sv = sorted(v1.values())[0]
        print(sv)
elif len0 == 1:
    sort_v1 = sorted(v1.items(),key=lambda x:x[1])
    sum1 = sum(v1.values())
    print(sum1 - max(v1.values()))
elif len1 == 1:
    sort_v0 = sorted(v0.items(),key=lambda x:x[1])
    sum0 = sum(v0.values())
    print(sum0 - max(v0.values()))
else:
    sort_v1 = sorted(v1.items(),key=lambda x:x[1])
    sort_v0 = sorted(v0.items(),key=lambda x:x[1])
    
    if sort_v0[-1][0] != sort_v1[-1][0]:
        sum0 = sum(v0.values()) - sort_v0[-1][1]
        sum1 = sum(v1.values()) - sort_v1[-1][1]
        print(sum0 + sum1)
    else:
        sum0 = sum(v0.values())
        sum1 = sum(v1.values())
        sum0_1 = sum0 - sort_v0[-1][1]
        sum0_2 = sum0 - sort_v0[-2][1]
        sum1_1 = sum1 - sort_v1[-1][1]
        sum1_2 = sum1 - sort_v1[-2][1]
        print(min(sum0_1 + sum1_2 , sum0_2 + sum1_1))

Solution (Python):
from collections import Counter
n = int(input())
v = [int(x) for x in input().split()]
li_odd = v[0:n:2]
li_even = v[1:n:2]

if len(v) == v.count(v[0]):
    print(len(v)//2)
else:
    c_odd = Counter(li_odd).most_common()
    c_even = Counter(li_even).most_common()
    if c_odd[0][0] != c_even[0][0]:
        print(len(li_odd) - c_odd[0][1] + len(li_even) - c_even[0][1])
    else:
        ans1 = len(li_odd) - c_odd[1][1] + len(li_even) - c_even[0][1]
        ans2 = len(li_odd) - c_odd[0][1] + len(li_even) - c_even[1][1]
        print(min(ans1,ans2))

Solution (Python):
import collections
n = int(input())
v = list(map(int,(input().split())))
even = []
odd =  []
for i in range(0,n,2):
    even.append(v[i])
for i in range(1,n,2):
    odd.append(v[i])

ce = collections.Counter(even)
co = collections.Counter(odd)

emax1,omax1 = ce.most_common()[0][1],co.most_common()[0][1]

if len(ce.most_common()) == 1:
    emax2 = 0
else:
    emax2 = ce.most_common()[1][1]
if len(co.most_common()) == 1:
    omax2 = 0
else:
    omax2 = co.most_common()[1][1]

if ce.most_common()[0][0] == co.most_common()[0][0]:
    ans = n - max(emax1+omax2, emax2+omax1)
else:
    ans = n - (emax1+omax1)
print(ans)

Solution (Python):
from collections import Counter

def main():
    
    N = int(input())
    V = list(map(int,input().split()))
    odd = V[1::2]
    even = V[0::2]
    mode_o = Counter(odd).most_common()
    mode_o.append([0,0])
    mode_e = Counter(even).most_common()
    mode_e.append([0,0])
    ans = 0
    if mode_o[0][0] != mode_e[0][0]:
        ans = N-mode_o[0][1]-mode_e[0][1]
    else:
        ans = N - max(mode_e[0][1]+mode_o[1][1],mode_e[1][1]+mode_o[0][1])
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
n,*v=map(int,open(0).read().split())
s=sorted(Counter(v[::2]).items(),key=lambda x:x[1])
t=sorted(Counter(v[1::2]).items(),key=lambda x:x[1])
if s[-1][0]==t[-1][0]:
  if len(s)==1 and len(t)==1:
    print(n//2)
  elif len(s)==1:
    print(n-s[0][1]-t[-2][1])
  elif len(t)==1:
    print(n-s[-2][1]-t[0][1])
  else:
    if s[-2][1]<t[-2][1]:
      print(n-s[-1][1]-t[-2][1])
    else:
      print(n-s[-2][1]-t[-1][1])
else:
  print(n-s[-1][1]-t[-1][1])

Solution (Python):
import collections

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

if len(set(A)) == 1:
    print(n//2)
    
else:
    k = []
    g = []
    for i in range(n):
        if i%2 == 0:
            k.append(A[i])
        else:
            g.append(A[i])
    
    ck = collections.Counter(k) 
    ckk, ckv = zip(*ck.most_common())
    cg = collections.Counter(g) 
    cgk, cgv = zip(*cg.most_common())
    if ckk[0] == cgk[0]:
            print(min((n - ckv[0] - cgv[1]), (n - ckv[1] - cgv[0])))
    else:
        print(n - ckv[0] - cgv[0])

Solution (Python):
from collections import Counter
n=int(input())
V=list(map(int, input().split()))
even=Counter(V[::2]).most_common(2)
odd=Counter(V[1::2]).most_common(2)
if even[0][0] != odd[0][0]:
    print(n-even[0][1]-odd[0][1])
else:
    if len(even) == 1 or len(odd) == 1: 
        print(n//2)
    else:
        print(n-max(even[0][1]+odd[1][1], even[1][1]+odd[0][1]))

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

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

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

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

Solution (Python):


from collections import defaultdict


n = int(input())
v = tuple(int(i) for i in input().split())

def f(v):
    d = defaultdict(int)
    d[0] = 0

    for i in v:
        d[i] += 1
    return sorted(d.items(), key=lambda x: x[1], reverse=True)

t1 = f(v[::2])
t2 = f(v[1::2])

if t1[0][0] == t2[0][0]:
    if t1[0][1] + t2[1][1] > t1[1][1] + t2[0][1]:
        print(n - t1[0][1] - t2[1][1])
    else:
        print(n - t1[1][1] - t2[0][1])
else:
    print(n - t1[0][1] - t2[0][1])

Solution (Python):

from collections import Counter, deque






import sys
sys.setrecursionlimit(10 ** 5 + 10)


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

    E=[]
    O=[]

    for i in range(n):
        if i%2==0:
            E.append(V[i])
        else:
            O.append(V[i])

    e=Counter(E)
    o=Counter(O)

    if e.most_common()[0][0] != o.most_common()[0][0]:
        print(n-e.most_common()[0][1]-o.most_common()[0][1])
    else:
        if len(e.most_common()) ==1:
            if  len(o.most_common())==1:
                print(n//2)
            else:
                print(n-e.most_common()[0][1]-o.most_common()[1][1])
        elif len(o.most_common())==1:
            print(n - e.most_common()[1][1] - o.most_common()[0][1])
        else:
            print(min(n-e.most_common()[1][1]-o.most_common()[0][1], \
                      n-e.most_common()[0][1]-o.most_common()[1][1]))

resolve()

Solution (Python):
from collections import Counter

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

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

cntV1,cntV2=Counter(v1),Counter(v2)
cntV1,cntV2=cntV1.most_common(2),cntV2.most_common(2)
cntV1.append((0,0))
cntV2.append((0,0))

if cntV1[0][0]!=cntV2[0][0]:
    ans=N-(cntV1[0][1]+cntV2[0][1])
else:
    ans=max(cntV1[0][1]+cntV2[1][1],cntV1[1][1]+cntV2[0][1])
    ans=N-ans

print(ans)

Solution (Python):
from collections import Counter

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


V_even = Counter(V[::2]+[0])
V_odd = Counter(V[1::2]+[0])

ans = 0

if len(set(V)) == 1:
  ans = n//2
elif V_odd.most_common()[0][0]==V_even.most_common()[0][0]:
  ans += min((n//2)-V_odd.most_common(2)[1][1]+(n//2)-V_even.most_common(2)[0][1],
             (n//2)-V_odd.most_common(2)[0][1]+(n//2)-V_even.most_common(2)[1][1])
else:
  ans += (n//2)-V_odd.most_common()[0][1]+(n//2)-V_even.most_common()[0][1]

print(ans)

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

d1 = {}
d2 = {}

largest_key1 = 0
largest_val1 = 0

larger_key1 = 0
larger_val = 0

largest_key2 = 0
largest_val2 = 0

larger_key2 = 0
larger_val2=0

if n == 2 and v[1] == v[2]:
    print(1)
    exit()
elif n == 2:
    print(0)
    exit()

for i in range(0, n, 2):
    if v[i] in d1:
        d1[v[i]] += 1
    else:
        d1[v[i]] = 1
    if d1[v[i]] >= largest_val1:
        if largest_key1 == v[i]:
            largest_val1 += 1
        else:
            larger_key1 = largest_key1
            larger_val1 = largest_val1
            largest_key1 = v[i]
            largest_val1 = d1[v[i]]
    elif d1[v[i]] >= larger_val1:
        larger_key1 = v[i]
        larger_val1 = d1[v[i]]

for i in range(1, n, 2):
    if v[i] in d2:
        d2[v[i]] += 1
    else:
        d2[v[i]] = 1
    if d2[v[i]] >= largest_val2:
        if largest_key2 == v[i]:
            largest_val2 += 1
        else:
            larger_key2 = largest_key2
            larger_val2 = largest_val2
            largest_key2 = v[i]
            largest_val2 = d2[v[i]]
    elif d2[v[i]] >= larger_val2:
        larger_key2 = v[i]
        larger_val2 = d2[v[i]]

if largest_key1 != largest_key2:
    print(n - largest_val1 - largest_val2)
else:
    print(n-max(largest_val1 + larger_val2, larger_val1 + largest_val2))

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    n=int(readline())
    v=list(map(int,readline().split()))

    d0=dict()
    d1=dict()
    for i in range(0,n-1,2):
        if v[i] not in d0:
            d0[v[i]]=1
        else:
            d0[v[i]]+=1
    for i in range(1,n,2):
        if v[i] not in d1:
            d1[v[i]]=1
        else:
            d1[v[i]]+=1

    d0=sorted(d0.items(),key=lambda x:x[1],reverse=True)
    d1=sorted(d1.items(),key=lambda x:x[1],reverse=True)

    if d0[0][0]!=d1[0][0]:
        print(n-d0[0][1]-d1[0][1])
    else:
        if len(d0)!=1 and len(d1)!=1:
            m0=n-d0[0][1]-d1[1][1]
            m1=n-d0[1][1]-d1[0][1]
            print(min(m0,m1))
        elif len(d0)==1 and len(d1)==1:
            print(n//2)
        elif len(d0)==1:
            print(n-d0[0][1]-d1[1][1])
        else:
            print(n-d0[1][1]-d1[0][1])

if __name__=="__main__":
    main()

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

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

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

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

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

if len(set(lst)) == 1:
    print(n//2)
else:
    a = lst[0:n:2]
    b = lst[1:n:2]

    acnt = Counter(a)
    bcnt = Counter(b)

    amax = acnt.most_common()[0]
    bmax = bcnt.most_common()[0]
    if amax[0] != bmax[0]:
        print((n//2 - amax[1]) + (n//2 - bmax[1]))
    else:
        try:
            asecond = acnt.most_common()[1]
        except:
            asecond = (-1, 0)
        try:
            bsecond = bcnt.most_common()[1]
        except:
            bsecond = (-1, 0)
        res1 = (n//2 - amax[1]) + (n//2 - bsecond[1])
        res2 = (n//2 - asecond[1]) + (n//2 - bmax[1])
        print(min([res1, res2]))

Solution (Python):
from collections import Counter
n = int(input())
v = [i for i in map(int, input().split())]
v_e, v_o = v[0::2], v[1::2]
cnt_e, cnt_o = Counter(v_e), Counter(v_o)
val_e, val_o = list(cnt_e.values()), list(cnt_o.values())
val_e.sort()
val_o.sort()
val_e, val_o = val_e[::-1], val_o[::-1]
cnt_e = sorted(cnt_e.items(), key=lambda x:x[1])[::-1]
cnt_o = sorted(cnt_o.items(), key=lambda x:x[1])[::-1]
key_e, key_o = cnt_e[0][0], cnt_o[0][0]
if key_e == key_o:
    if len(val_e) == len(val_o) == 1:
        print(n // 2)
    elif len(val_e) == 1:
        print(n // 2 - val_o[1])
    elif len(val_o) == 1:
        print(n // 2 - val_e[1])
    else:
        print(min(n - val_e[0] - val_o[1], n - val_e[1] - val_o[0]))
else:
    if len(val_e) == len(val_o) == 1:
        print(0)
    elif len(val_e) == 1:
        print(n // 2 - val_o[0])
    elif len(val_o) == 1:
        print(n // 2 - val_e[0])
    else:
        print(n - val_o[0] - val_e[0])

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

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

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

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

ev = sorted([(k,i) for k, i in e.items()],key = lambda z:z[1],reverse = True) + [(0,0)]
od = sorted([(k,i) for k, i in o.items()],key = lambda z:z[1],reverse = True) + [(0,0)]

if ev[0][0] != od[0][0]:
    print(n - ev[0][1] - od[0][1])
else:
    print(n - max(ev[0][1] + od[1][1], ev[1][1] + od[0][1]))

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

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

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

Solution (Python):

from collections import Counter

n = int(input().strip())
v_list = list(map(int, input().rstrip().split()))


v_odd = [ v_list[i] for i in range(0,len(v_list),2) ]
v_even  = [ v_list[i] for i in range(1,len(v_list),2) ]

sort_cnt_v_odd  = sorted( Counter(v_odd).items(), key=lambda x:x[1], reverse=True)
sort_cnt_v_even = sorted(Counter(v_even).items(), key=lambda x:x[1], reverse=True)





if sort_cnt_v_odd[0][0] == sort_cnt_v_even[0][0] and len(sort_cnt_v_odd)==len(sort_cnt_v_even)==1:
    ans = len(v_odd)
else:


    ans = n
    for i_o, v_o  in sort_cnt_v_odd[:2]:
        for i_e, v_e in sort_cnt_v_even[:2]:
            if i_o != i_e:
                tmp = len(v_odd) - v_o + len(v_even) - v_e
                ans = min(ans, tmp)

print(ans)

Solution (Python):

from collections import Counter

n = int(input().strip())
v_list = list(map(int, input().rstrip().split()))


v_odd = [ v_list[i] for i in range(0,len(v_list),2) ]
v_even  = [ v_list[i] for i in range(1,len(v_list),2) ]

sort_cnt_v_odd  = sorted( Counter(v_odd).items(), key=lambda x:x[1], reverse=True)
sort_cnt_v_even = sorted(Counter(v_even).items(), key=lambda x:x[1], reverse=True)


ans=0


if sort_cnt_v_odd[0][0] != sort_cnt_v_even[0][0]:
    ans +=  len(v_odd) -  sort_cnt_v_odd[0][1]
    ans += len(v_even) - sort_cnt_v_even[0][1]
else:


    
    
    if len(sort_cnt_v_odd)==len(sort_cnt_v_even)==1:
        ans = len(v_odd)
        
    
    elif len(sort_cnt_v_odd)==1 and len(sort_cnt_v_even)!=1:
        ans =   len(v_odd) -  sort_cnt_v_odd[0][1] \
              + len(v_even) - sort_cnt_v_even[1][1]
        
    
    elif len(sort_cnt_v_odd)!=1 and len(sort_cnt_v_even)==1:
        ans =    len(v_odd) -  sort_cnt_v_odd[1][1] \
              + len(v_even) - sort_cnt_v_even[0][1]
        
    
    
    
    elif len(sort_cnt_v_odd)!=1 and len(sort_cnt_v_even)!=1:
        tmp1 =    len(v_odd) -   sort_cnt_v_odd[0][1] \
               + len(v_even) -  sort_cnt_v_even[1][1]
        
        tmp2 =    len(v_odd) -  sort_cnt_v_odd[1][1] \
               + len(v_even) - sort_cnt_v_even[0][1]
              
        ans = min(tmp1,tmp2)
        

print(ans)

Solution (Python):
from collections import Counter

def solve(n, v):
    
    if len(set(v)) == 1:
        return len(v) / 2

    odd = []
    even = []

    for i, k in enumerate(v):
        if i % 2 == 0:
            even.append(k)
        else:
            odd.append(k)

    odd_dic = Counter(odd).most_common()
    even_dic = Counter(even).most_common()

    ans = 0

    if odd_dic[0][0] == even_dic[0][0]:
        if odd_dic[0][1] > even_dic[0][1]:
            odd_v = odd_dic[0][0]
            even_v = even_dic[1][0]
        elif odd_dic[0][1] < even_dic[0][1]:
            odd_v = odd_dic[1][0]
            even_v = even_dic[0][0]
        else:
            if odd_dic[1][1] >= even_dic[1][1]:
                odd_v = odd_dic[1][0]
                even_v = even_dic[0][0]
            else:
                odd_v = odd_dic[0][0]
                even_v = even_dic[1][0]
    else:
        odd_v = odd_dic[0][0]
        even_v = even_dic[0][0]

    for i in range(len(even)):
        if even_v != even[i]:
           ans += 1

        if odd_v != odd[i]:
            ans += 1

    return ans

def test():
    assert solve(4, [3, 1, 3, 2]) == 1
    assert solve(6, [105, 119, 105, 119, 105, 119]) == 0
    assert solve(4, [1, 1, 1, 1]) == 2

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

if __name__ == '__main__':
    
    main()

Solution (Python):
from collections import Counter
N = int(input())
V = list(map(int,input().split()))
E = Counter(V[0::2]).most_common()+[(0,0)]
O = Counter(V[1::2]).most_common()+[(0,0)]

if E[0][0]!=O[0][0]:
  print(N-E[0][1]-O[0][1])
else:
  print(N-max(E[0][1]+O[1][1],E[1][1]+O[0][1]))

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


evens = C(v[::2]).most_common()
odds = C(v[1::2]).most_common()



if evens[0][0] != odds[0][0]:
    ans = n - (evens[0][1] + odds[0][1])


else:
    
    
    
    r = evens[0][1] + odds[1][1] if len(odds) > 1 else evens[0][1]
    s = evens[1][1] + odds[0][1] if len(evens) > 1 else odds[0][1]
    if r > s:
        ans = n - r
    else:
        ans = n - s

print(ans)

Solution (Python):
def main():
  n = int(input())
  v = input_list()
  evens = []
  odds = []
  vs = v[:]
  kind = len(set(vs))
  if kind == 1:
    print(n//2)
    exit(0)
  
  for i, vv in enumerate(v):
    if i % 2 == 0:
      evens.append(vv)
    else:
      odds.append(vv)
  ec = collections.Counter(evens)
  oc = collections.Counter(odds)
  m = n//2
  
  ans = 0
  em = ec.most_common()
  om = oc.most_common()
  if em[0][0] == om[0][0]:
    p1 = m-em[0][1] + m-om[1][1]
    p2 = m-em[1][1] + m-om[0][1]
    print(min(p1,p2))
  else:
    print(m-em[0][1] + m-om[0][1])
  
def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c 

import math
import fractions
import collections
from functools import reduce
main()

Solution (Python):
import sys
N = int(input())
L = [i for i in map(int,input().split())]
U = L[0::2]
V = L[1::2]
L = len(U) + len(V)
res = 0
from collections import Counter
oc_E2 = 0
oc_F2 = 0
A = Counter(U)
E1 = A.most_common(1)[0][0]
oc_E1 = A.most_common(1)[0][1]
C = Counter(V)
F1 = C.most_common(1)[0][0]
oc_F1 = C.most_common(1)[0][1]
if E1 != F1:
  print(L - oc_E1 - oc_F1)
  sys.exit(0)
else:
  L2 = [el for el in U if el != E1]
  oc_E2 = 0
  if L2 != []: 
    B = Counter(L2)
    E2 = B.most_common(1)[0][0]
    oc_E2 = B.most_common(1)[0][1]
  L3 = [el for el in V if el != F1]
  oc_F2 = 0
  if L3 != []:
    D = Counter(L3)
    F2 = D.most_common(1)[0][0]
    oc_F2 = D.most_common(1)[0][1]
print(min(L-oc_E1-oc_F2,L-oc_F1-oc_E2))

Solution (Python):


from collections import Counter


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

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

    arr_even = even.most_common()
    arr_odd = odd.most_common()

    sum_even = sum(x[1] for x in arr_even)
    sum_odd = sum(x[1] for x in arr_odd)

    min_sum = sum_even - arr_even[0][1] + N // 2

    for i, x in arr_even:
        for j, y in arr_odd:
            if i != j:
                cnt = sum_even - x + sum_odd - y
                min_sum = min(min_sum, cnt)
                break
            else:
                continue

    print(min_sum)


if __name__ == "__main__":
    main()

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

V1 = C(V[::2]).most_common()
V2 = C(V[1::2]).most_common()

if V1[0][0] != V2[0][0]:
  ans = n - (V1[0][1] + V2[0][1])
else:
  l = V1[0][1] + V2[1][1] if len(V2) > 1 else V1[0][1]
  r = V1[1][1] + V2[0][1] if len(V1) > 1 else V2[0][1] 
  if l >= r:
    ans = n - l
  else:
    ans = n - r
    
print(ans)

Solution (Python):
from collections import Counter

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

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

even_cnt = Counter(v_even).most_common() + [(0, 0)]
odd_cnt = Counter(v_odd).most_common() + [(0, 0)]

if even_cnt[0][0] != odd_cnt[0][0]:
    print(n//2 - even_cnt[0][1] + n//2 - odd_cnt[0][1])
else:
    print(min(n//2 - even_cnt[0][1] + n//2 - odd_cnt[1][1], n//2 - even_cnt[1][1] + n//2 - odd_cnt[0][1]))

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

V1 = C(V[::2]).most_common()
V2 = C(V[1::2]).most_common()

if V1[0][0] != V2[0][0]:
  ans = n - (V1[0][1] + V2[0][1])
else:
  l = V1[0][1] + V2[1][1] if len(V2) > 1 else V1[0][1]
  r = V1[1][1] + V2[0][1] if len(V1) > 1 else V2[0][1] 
  if l >= r:
    ans = n - l
  else:
    ans = n - r
print(ans)

Solution (Python):
from collections import Counter
from itertools import product
n = int(input())
*v, = map(int, input().split())
o = Counter(v[1::2])
e = Counter(v[::2])
o[0] = 0
e[0] = 0
o_ls = o.most_common(2)
e_ls = e.most_common(2)


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

print(ans)