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

n = len(v)
from collections import defaultdict
c0 = defaultdict(int)
for vi in v[0::2]:
    c0[vi] += 1
c1 = defaultdict(int)
for vi in v[1::2]:
    c1[vi] += 1

sc0 = sorted(c0.items(), key=lambda x: x[1])
sc1 = sorted(c1.items(), key=lambda x: x[1])




if sc0[-1][0] != sc1[-1][0]:
    
    print(n//2 - sc0[-1][1] + n//2 - sc1[-1][1])
    exit()
if len(sc0) == 1 and len(sc1) == 1:
    
    print(n//2)
    exit()
if sc0[-1][1] > sc1[-1][1]:
    
    print(n//2 - sc0[-1][1] + n//2 - sc1[-2][1])
    exit()
if sc0[-1][1] < sc1[-1][1]:
    
    print(n//2 - sc0[-2][1] + n//2 - sc1[-1][1])
    exit()
if sc0[-1][1] == sc1[-1][1]:
    if sc0[-2][1] < sc1[-2][1]:
        
        print(n//2 - sc0[-1][1] + n//2 - sc1[-2][1])
    else:
        
        print(n//2 - sc0[-2][1] + n//2 - sc1[-1][1])
    exit()

Solution (Python):
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split(' ')))
    v_odd, v_even = list(), list()
    for i in range(n):
        if i % 2 == 0:
            v_even.append(v[i])
        else:
            v_odd.append(v[i])
    assert len(v_odd) == len(v_even)
    odd_top2 = Counter(v_odd).most_common(2)
    even_top2 = Counter(v_even).most_common(2)
    if odd_top2[0][0] != even_top2[0][0]:
        print(n - odd_top2[0][1] - even_top2[0][1])
    else:
        d1 = n - odd_top2[0][1] - (0 if len(even_top2) == 1 else even_top2[1][1])
        d2 = n - even_top2[0][1] - (0 if len(odd_top2) == 1 else odd_top2[1][1])
        print(min([d1, d2]))


if __name__ == '__main__':
    main()

Solution (Python):




import math
import sys
import bisect
import heapq  

inf = 10 ** 15
mod = 10 ** 9 + 7
n = int(input())
v = list(map(int, input().split()))


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

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


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


maxeveni = -1

maxeven = 0

preeven = 0


maxoddi = -1

maxodd = 0

preodd = 0


for i in range(1, 100001):
    num = even[i]
    if maxeven <= num:
        maxeveni = i
        preeven = maxeven
        maxeven = num
    elif preeven <= num:
        preeven = num


for i in range(1, 100001):
    num = odd[i]
    if maxodd <= num:
        maxoddi = i
        preodd = maxodd
        maxodd = num
    elif preodd <= num:
        preodd = num

ans = 0


if maxeveni != maxoddi:
    ans = n - maxeven - maxodd

else:
    ans = min(n - preeven - maxodd, n - maxeven - preodd)
print(ans)

Solution (Python):
import numpy as np
n = int(input())
num_list = list(map(int,input().split()))

even_cnt = [0]*(10**5 + 10)
odd_cnt = [0]*(10**5 +10)
for i in range(n):
    if i % 2 == 0:
        even_cnt[num_list[i]] += 1
    else:
        odd_cnt[num_list[i]] += 1
ame = np.argmax(even_cnt)
amo = np.argmax(odd_cnt)
if ame != amo:
    print(len(num_list) - max(even_cnt) -  max(odd_cnt))
    
    
else:
    tmp_e_max =  max(even_cnt)
    tmp_o_max = max(odd_cnt)
    even_cnt[ame] = 0
    odd_cnt[amo] = 0
    if tmp_e_max-max(even_cnt) >=  tmp_o_max - max(odd_cnt):
        print(len(num_list) - max(odd_cnt) -  tmp_e_max)
    else:
        print(len(num_list) - max(even_cnt) -  tmp_o_max)

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
ans1=[0]*(10**5+1)
ans2=[0]*(10**5+1)
for i in v[0::2]:
  ans1[i]+=1
for i in v[1::2]:
  ans2[i]+=1
m1=max(ans1)
m2=max(ans2)
flag=False
for i in range(10**5+1):
  if ans1[i]==m1 and ans2[i]==m2:
    flag=True
    ans1.sort()
    ans2.sort()
    m12=ans1[-2]
    m22=ans2[-2]
    break
if len(set(v))==1:
  print(n//2)
elif flag==True:
  print(n-max(m12+m2,m1+m22))
else:
  print(n-m1-m2)

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

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

odd = defaultdict(int)
even = defaultdict(int)

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

evenMax = 0
oddMax = 0
ev = 0
evenList = []
oddList = []
for k, v in even.items():
    evenList.append((v, k))
for k, v in odd.items():
    oddList.append((v, k))

evenList.sort(reverse=True)
oddList.sort(reverse=True)

ans = 0

if evenList[0][1] == oddList[0][1]:
    ans = min(N - evenList[0][0] - oddList[1][0],
              N - evenList[1][0] - oddList[0][0])
else:
    ans = N - evenList[0][0] - oddList[0][0]

print(ans)

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

def mkdc(l):
    di=dict()
    for i in range(len(l)):
        if l[i] in di:
            di[l[i]]+=1
        else:
            di[l[i]]=1
    return di

e,o=[],[]      
for i in range(int(n/2)):
    e.append(v[2*i])
    o.append(v[2*i+1])

de=mkdc(e)
do=mkdc(o)

de=sorted(de.items(),key=lambda d: d[1],reverse=True)
do=sorted(do.items(),key=lambda d: d[1],reverse=True)
de.append((0,0))
do.append((0,0))


if do[0][0]==de[0][0]:
    print(n- do[0][1]-max(de[1][1],do[1][1]))
else:
    print(n-de[0][1]-do[0][1])

Solution (Python):




import itertools
import math
import fractions
import functools
l = [0]*(10**5+1)
r = [0]*(10**5+1)
 
n = int(input())
v = list(map(int, input().split()))
 
for i in range(n):
    if i % 2 == 0:
        l[v[i]] += 1
    else:
        r[v[i]] += 1
 
max_l = l.index(max(l))
max_r = r.index(max(r))
count = 0
 
if max_l == max_r:
    for i in range(len(r)):
        if r[i] == r[max_r]:
            r[i] = 0
        if l[i] == l[max_l]:
            l[i] = 0
if max(l) > max(r):
    max_l = l.index(max(l))
else:
    max_r = r.index(max(r))
 
for i in range(n):
    if i % 2 == 0 and v[i] != max_l:
        count += 1
    if i % 2 != 0 and v[i] != max_r:
        count += 1
print(count)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

n, *v = map(int, read().split())
g = Counter(v[::2]).most_common()
k = Counter(v[1::2]).most_common()
if g[0][0] == k[0][0]:
    if len(g) > 1:
        if len(k) > 1:
            print(n - max(g[0][1] + k[1][1], g[1][1] + k[0][1]))
        else:
            print(n - g[1][1] - k[0][1])
    elif len(k) > 1:
        print(n - g[0][1] - k[1][1])
    else:
        print(n // 2)
else:
    print(n - g[0][1] - k[0][1])

Solution (Python):
from collections import Counter
N = int(input())
V = [int(i) for i in input().split()]
Ki = []
Gu = []
switch = True
for i in range(N):
    if switch:
        Ki.append(V[i])
    else:
        Gu.append(V[i])
    switch = not switch

K = sorted(Counter(Ki).items(),key=lambda x:x[1],reverse=True)
G = sorted(Counter(Gu).items(),key=lambda x:x[1],reverse=True)
sk = len(K)
gk = len(G)
if sk==1 and gk==1:
    if G[0][0]==K[0][0]:
        print(N//2)
    else:
        print(0)
elif sk==1:
    if G[0][0]==K[0][0]:
        print(N-K[0][1]-G[1][1])
    else:
        print(N-K[0][1]-G[0][1])
elif gk == 1:
    if G[0][0]==K[0][0]:
        print(N-K[1][1]-G[0][1])
    else:
        print(N-K[0][1]-G[0][1])
else:
    if G[0][0] == K[0][0]:
        s1 = K[0][1]+G[1][1]
        s2 = K[1][1]+G[0][1]
        print(N-max(s1,s2))
    else:
        print(N-K[0][1]-G[0][1])

Solution (Python):
from collections import defaultdict

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

o=defaultdict(int)						
e=defaultdict(int)

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

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

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

if es[0][0]==os[0][0]:
	if len(es)==1 and len(os)==1:
		print(n-max(es[0][1],os[0][1]))
	elif len(es)==1:
		print(n-es[0][1]-os[1][1])
	elif len(os)==1:
		print(n-es[1][1]-os[0][1])
	else:
		print(n-max(es[0][1]+os[1][1],es[1][1]+os[0][1]))
else:
	print(n-es[0][1]-os[0][1])

Solution (Python):


import sys






















def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = int(input())
    L = list(map(int, input().split()))
    L_even = L[0:n:2]
    L_odd = L[1:n:2]

    def calc_appeared_times(L):
        d = dict()
        maximum = 0
        appeared_num = None
        for num in L:
            if num in d:
                d[num] += 1
            else:
                d[num] = 1
            if d[num] > maximum:
                maximum = d[num]
                appeared_num = num
        return appeared_num, d

    even_max_appeared, d_even = calc_appeared_times(L_even)
    odd_max_appeared, d_odd = calc_appeared_times(L_odd)
    if even_max_appeared != odd_max_appeared:
        print(n - d_even[even_max_appeared] - d_odd[odd_max_appeared])
    else:
        second_max_even = 0
        for k, v in d_even.items():
            if k != even_max_appeared and v > second_max_even:
                second_max_even = v
        second_max_odd = 0
        for k, v in d_odd.items():
            if k != odd_max_appeared and v > second_max_odd:
                second_max_odd = v
        if second_max_even >= second_max_odd:
            print(n - second_max_even - d_odd[odd_max_appeared])
        else:
            print(n - second_max_odd - d_even[even_max_appeared])


if __name__ == "__main__":
    main()

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

c_0 = collections.Counter(a[::2])
c_1 = collections.Counter(a[1::2])

if len(c_0.most_common()) == 1 and len(c_1.most_common()) == 1:
  if c_0.most_common()[0][0] == c_1.most_common()[0][0]:
    print(n // 2)
  else:
    print(0)
elif len(c_0.most_common()) == 1:
  if c_0.most_common()[0][0] == c_1.most_common()[0][0]:
    print(n // 2 - c_1.most_common()[1][1])
  else:
    print(n // 2 - c_1.most_common()[0][1])
elif len(c_1.most_common()) == 1:
  if c_0.most_common()[0][0] == c_1.most_common()[0][0]:
    print(n // 2 - c_0.most_common()[1][1])
  else:
    print(n // 2 - c_0.most_common()[0][1])
elif c_0.most_common()[0][0] == c_1.most_common()[0][0]:
  if c_0.most_common()[0][1] > c_1.most_common()[0][1]:
    print(n - c_0.most_common()[0][1] - c_1.most_common()[1][1])
  elif c_0.most_common()[0][1] < c_1.most_common()[0][1]:
    print(n - c_0.most_common()[1][1] - c_1.most_common()[0][1])
  else:
    print(n - c_0.most_common()[0][1] - max(c_0.most_common()[1][1],c_1.most_common()[1][1]))
else:
  print(n - c_0.most_common()[0][1] - c_1.most_common()[0][1])

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

d_odd=sorted(d_odd.items(),key=lambda x:x[1],reverse=True)
d_even=sorted(d_even.items(),key=lambda x:x[1],reverse=True)
if d_odd[0][0]!=d_even[0][0]:
    ans=(len(odd)-d_odd[0][1])+(len(even)-d_even[0][1])
else:
    if len(d_odd)==1 and len(d_even)==1:
        ans=len(odd)
    elif len(d_odd)==1:
        ans=(len(even)-d_even[1][1])
    elif len(d_even)==1:
        ans=(len(odd)-d_odd[1][1])
    else:
        x=(len(odd)-d_odd[1][1])+(len(even)-d_even[0][1])
        y=(len(odd)-d_odd[0][1])+(len(even)-d_even[1][1])
        ans=min(x,y)
print(ans)

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
a=sorted(v[::2])
b=sorted(v[1::2])
import itertools,heapq
ha=[]
hb=[]
ga = itertools.groupby(a)
gb = itertools.groupby(b)
for key,group in ga:
  heapq.heappush(ha, [-len(list(group)),key])
for key,group in gb:
  heapq.heappush(hb, [-len(list(group)),key])
A=heapq.heappop(ha)
B=heapq.heappop(hb)
if A[1]==B[1]:
  A2=heapq.heappop(ha) if len(ha)>0 else [0,0]
  B2=heapq.heappop(hb) if len(hb)>0 else [0,0]
  print(n+min(A[0]+B2[0],A2[0]+B[0]))
else:
  print(n+A[0]+B[0])

Solution (Python):
import collections
N = int(input())
V = [int(i) for i in input().split()]

C0 = collections.Counter(V[0::2])
C0[0] = 0

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

if C0.most_common()[0][0] != C1.most_common()[0][0]:
    print(N-C0.most_common()[0][1]-C1.most_common()[0][1])
else:
    print(min(N-C0.most_common()[0][1]-C1.most_common()[1][1],
              N-C0.most_common()[1][1]-C1.most_common()[0][1]))

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

l = []
r = []
al = []
for i, x in enumerate(A):
  if i % 2 == 0:
    l.append(x)
  else:
    r.append(x)
  al.append(x)

c = collections.Counter(l)
d = collections.Counter(r)
e = collections.Counter(al)

if len(e.keys()) <= 1:
  print(N//2)
  exit()
else:
  mx = -1
  ans = 0
  ck = max(c.items(), key=lambda x:x[1])[0]
  cmx = max(c.items(), key=lambda x:x[1])[1]

  dk = max(d.items(), key=lambda x:x[1])[0]
  dmx = max(d.items(), key=lambda x:x[1])[1]

  if ck == dk:
    if cmx > dmx:
      ans += N//2 - cmx
      ans += N//2 - d.most_common(2)[1][1]
    elif cmx < dmx:
      ans += N//2 - dmx
      ans += N//2 - c.most_common(2)[1][1]
    else:
      if c.most_common(2)[1][1] >= d.most_common(2)[1][1]:
        ans += N//2 - dmx
        ans += N//2 - c.most_common(2)[1][1]
      else:
        ans += N//2 - cmx
        ans += N//2 - d.most_common(2)[1][1]
  else:
      ans += N//2 - cmx
      ans += N//2 - dmx

print(ans)

Solution (Python):
import itertools
import math
import fractions
import functools
l = [0]*(10**5+10)
r = [0]*(10**5+10)

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

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

max_l = l.index(max(l))
max_r = r.index(max(r))
count = 0

if max_l == max_r:
    for i in range(len(r)):
        if r[i] == r[max_r]:
            r[i] = 0
        if l[i] == l[max_l]:
            l[i] = 0
if max(l) > max(r):
    max_l = l.index(max(l))
else:
    max_r = r.index(max(r))

for i in range(n):
    if i % 2 == 0 and v[i] != max_l:
        count += 1
    if i % 2 != 0 and v[i] != max_r:
        count += 1
print(count)

Solution (Python):
n = int(input())
u = list(map(int, input().split()))
u0 = u[0::2]
u1 = u[1::2]
s0 = [0] * 100001
s1 = [0] * 100001
for i in u0:
  s0[i] += 1
for i in u1:
  s1[i] += 1
maxi_0 = 0
maxi2_0 = 0
for i in range(100001):
  if s0[i] >= s0[maxi_0]:
    maxi2_0 = maxi_0
    maxi_0 = i
  elif s0[i] >= s0[maxi2_0]:
    maxi2_0 = i
maxi_1 = 0
maxi2_1 = 0
for i in range(100001):
  if s1[i] >= s1[maxi_1]:
    maxi2_1 = maxi_1
    maxi_1 = i
  elif s1[i] >= s1[maxi2_1]:
    maxi2_1 = i
if maxi_0 != maxi_1:
  print(n - s0[maxi_0] - s1[maxi_1])
else:
  print(n - max(s0[maxi_0] + s1[maxi2_1], s0[maxi2_0] + s1[maxi_1]))

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
dic1={}
dic2={}
for i in range(0,n):
  if i%2==0:
    at=v[i]
    if at in dic1:
      dic1[at]+=1
    else:
      dic1[at]=1
  else:
    at=v[i]
    if at in dic2:
      dic2[at]+=1
    else:
      dic2[at]=1 

count1=0
count2=0
kep1=0
kep2=0
for i in range(len(dic1)):
  at=dic1.popitem()
  moji=at[0]
  count=at[1]
  if count>count2:
    kep2=moji
    count2=count
  if count2>count1:
    moji_tamotu=kep1
    count_tamotu=count1
    kep1=kep2
    kep2=moji_tamotu
    count1=count2
    count2=count_tamotu

odd_1_moji=kep1
odd_1_count=count1
odd_2_moji=kep2
odd_2_count=count2
    
count1=0
count2=0
kep1=0
kep2=0
for i in range(len(dic2)):
  at=dic2.popitem()
  moji=at[0]
  count=at[1]
  if count>count2:
    kep2=moji
    count2=count
  if count2>count1:
    moji_tamotu=kep1
    count_tamotu=count1
    kep1=kep2
    kep2=moji_tamotu
    count1=count2
    count2=count_tamotu

even_1_moji=kep1
even_1_count=count1
even_2_moji=kep2
even_2_count=count2

if even_1_moji!=odd_1_moji:
  kouho=[odd_1_moji,even_1_moji]*(n//2)
else:
  if even_1_count+odd_2_count>=even_2_count+odd_1_count:
    kouho=[odd_2_moji,even_1_moji]*(n//2)
  else:
    kouho=[odd_1_moji,even_2_moji]*(n//2)
    
res=0
for i in range(0,n):
  if v[i]!=kouho[i]:
    res+=1
print(res)

Solution (Python):
from collections import Counter
N = int(input())
V = list(map(int, input().split()))
a1, a2, *_ = Counter(V[0::2]).most_common() + [(0, 0)]
b1, b2, *_ = Counter(V[1::2]).most_common() + [(0, 0)]
print(N - max(a1[1] + b2[1], a2[1] + b1[1]) if a1[0] == b1[0] else N - (a1[1] + b1[1]))

Solution (Python):
n = int(input())
V = list(map(int,input().split()))
import collections
co0 = collections.Counter()
co1 = collections.Counter()
for i in range(n):
    if i%2==0:
        co0[V[i]]+=1
    else:
        co1[V[i]]+=1
co0[-1] =0
co1[-1] =0
c0 = list(co0.items())
c0.sort(key=lambda x:x[1])
c1 = list(co1.items())
c1.sort(key=lambda x:x[1])
if c0[-1][0] == c1[-1][0]:
    b = max(c0[-1][1] + c1[-2][1],c0[-2][1] + c1[-1][1])
else:
    b = c0[-1][1] + c1[-1][1]
print(n-b)

Solution (Python):
from collections import defaultdict
from operator import itemgetter

n = int(input())
v_list = [int(x) for x in input().split()]

temp = [defaultdict(int, {"": 0}), defaultdict(int, {"": 0})]
for i in range(0, n, 2):
    temp[0][v_list[i]] += 1
for i in range(1, n, 2):
    temp[1][v_list[i]] += 1

even_list = sorted(temp[0].items(), reverse=True, key=itemgetter(1))
odd_list = sorted(temp[1].items(), reverse=True, key=itemgetter(1))

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

Solution (Python):
import math
import fractions
from functools import reduce


def main():
    n = int(input())
    a = input_list()
    if len(set(a)) == 1:
        print(n//2)
        exit(0)
    evens = {}
    odds = {}
    for i, v in enumerate(a):
        if i % 2 == 0:
            if v in evens:
                evens[v] += 1
            else:
                evens[v] = 1
        else:
            if v in odds:
                odds[v] += 1
            else:
                odds[v] = 1
    if len(evens) == 1 and len(odds) == 1:
        print(0)
        exit(0)

    e = sorted(evens.items(), key=lambda x: x[1], reverse=True)
    o = sorted(odds.items(), key=lambda x: x[1], reverse=True)
    if e[0][0] != o[0][0]:
        even_ans = (n // 2) - e[0][1]
        odd_ans = (n // 2) if len(o) == 1 else (n // 2) - o[0][1]
        a1 = even_ans+odd_ans

        even_ans = (n // 2) if len(e) == 1 else (n // 2) - e[0][1]
        odd_ans = (n // 2) - o[0][1]
        a2 = even_ans+odd_ans
        print(min(a1, a2))
    else:
        even_ans = (n // 2) - e[0][1]
        odd_ans = (n // 2) if len(o) == 1 else (n // 2) - o[1][1]
        a1 = even_ans + odd_ans

        even_ans = (n // 2) if len(e) == 1 else (n // 2) - e[1][1]
        odd_ans = (n // 2) - o[0][1]
        a2 = even_ans + odd_ans
        print(min(a1, a2))




def input_list():
    return list(map(int, 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)

if __name__ == "__main__":
    main()

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

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

c_even = [0]*(10**5+100)
c_odd = [0]*(10**5 + 100)

for i in even:
    c_even[i]+=1
for i in odd:
    c_odd[i]+=1

m_even = -1
m_odd = -1


for i,j in enumerate(c_even):
    if j > m_even:
        m_even = j 
        m_even_num = i

for i,j in enumerate(c_odd):
    if j > m_odd:
        m_odd = j 
        m_odd_num = i

if m_even_num == m_odd_num:
    print(min(n - m_odd - sorted(c_even,reverse=True)[1], n - m_even - sorted(c_odd,reverse=True)[1]))
else:
    print(n - m_even - m_odd)

Solution (Python):
from collections import Counter

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

v1c = Counter(v1).most_common()
v2c = Counter(v2).most_common()

ans2=float("inf")
ans3=float("inf")
ans4=float("inf")


if v1c[0][0]!=v2c[0][0]:
  ans=len(v1)-v1c[0][1]+len(v2)-v2c[0][1]
  print(ans)

else:
  if len(v1c) !=1:
    ans2=len(v1)-v1c[1][1]+len(v2)-v2c[0][1]
  if len(v2c) !=1:
    ans3=len(v1)-v1c[0][1]+len(v2)-v2c[1][1]
  else:
    ans4=min(len(v1),len(v2))
  print(min(ans2,ans3,ans4))

Solution (Python):
from collections import Counter


n = int(input())
m = list(map(int, input().split()))
a = Counter(m[0::2]).most_common()
b = Counter(m[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()))

a = [v[2*i] for i in range(int(n/2))]
b = [v[2*i+1] for i in range(int(n/2))]

from collections import Counter

x = Counter(a)
y = Counter(b)
x = list(x.items())
y = list(y.items())
x.sort(reverse=1,key=lambda p: p[1])
y.sort(reverse=1,key=lambda p: p[1])

if x[0][0] != y[0][0]:
    print(n-x[0][1]-y[0][1])
else:
    if x[0][0] == y[0][0]:
        if min(len(x),len(y))>=2:
            print(n-max(x[0][1]+y[1][1],y[0][1]+x[1][1]))
        elif len(x)==2:
            print(n-x[1][1]-y[0][1])
        elif len(y)==2:
            print(n-y[1][1]-x[0][1])
        else:
            print(int(n/2))

Solution (Python):
from collections import Counter

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

C0 = Counter(V[0::2]).most_common()
C0.append((0, 0))
C1 = Counter(V[1::2]).most_common()
C1.append((0, 0))
ans = N
for k0, v0 in C0:
    for k1, v1 in C1:
        if k0 != k1:
            ans = min(ans, N - v0 - v1)
            break
print(ans)

Solution (Python):
import numpy as np
ans = 0

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

odd = V[0::2]
even = V[1::2]

odd_count = np.bincount(odd)
odd_argmax = np.argmax(odd_count)
odd_count_num = odd_count[odd_argmax]
odd_count[odd_argmax] = -1
odd_argmax_second = np.argmax(odd_count)
odd_count_num_second = odd_count[odd_argmax_second]





even_count = np.bincount(even)
even_argmax = np.argmax(even_count)
even_count_num = even_count[even_argmax]

even_count[even_argmax] = 0
even_argmax_second = np.argmax(even_count)
even_count_num_second = even_count[even_argmax_second]






if odd_argmax == even_argmax:
    ans = min(half_n - odd_count_num + half_n - even_count_num_second, half_n - odd_count_num_second + half_n - even_count_num)
else:
    ans += half_n - odd_count_num
    ans += half_n - even_count_num
print(ans)

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

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

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

from collections import Counter

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

if odd_cnt.most_common()[0][0] != even_cnt.most_common()[0][0]:
    print(len(odd) - odd_cnt.most_common()[0][1] + len(even) - even_cnt.most_common()[0][1])
else:
    if odd_cnt.most_common()[1][1] >= even_cnt.most_common()[1][1]:
        print(len(odd) - odd_cnt.most_common()[1][1] + len(even) - even_cnt.most_common()[0][1])
    else:
        print(len(odd) - odd_cnt.most_common()[0][1] + len(even) - even_cnt.most_common()[1][1])

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

c1 = Counter(V[::2])
c2 = Counter(V[1::2])
c1_items = sorted(c1.items(), key=lambda x: -x[1])
c2_items = sorted(c2.items(), key=lambda x: -x[1])

if c1_items[0][0] == c2_items[0][0]:
    if len(c1_items) == 1 and len(c2_items) == 1:
        ans = n // 2
    elif len(c1_items) == 1:
        ans = n - c1_items[0][1] - c2_items[1][1]
    elif len(c2_items) == 1:
        ans = n - c1_items[0][1] - c2_items[1][1]
    else:
        v1 = n - c1_items[0][1] - c2_items[1][1]
        v2 = n - c1_items[1][1] - c2_items[0][1]
        ans = min(v1, v2)
else:
    ans = n - c1_items[0][1] - c2_items[0][1]
print(ans)

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

c1 = Counter(V[::2])
c2 = Counter(V[1::2])


c1_items = sorted(c1.items(), key=lambda x: -x[1])
c2_items = sorted(c2.items(), key=lambda x: -x[1])
c1_max = c1_items[0][1]
c2_max = c2_items[0][1]
c1_second = 0
c2_second = 0

c1_max_group = set()
for key, value in c1_items:
    if value == c1_max:
        c1_max_group.add(key)
    else:
        c1_second = value
        break
c2_max_group = set()
for key, value in c2_items:
    if value == c2_max:
        c2_max_group.add(key)
    else:
        c2_second = value
        break



if len(c1_max_group) == 1 and len(c2_max_group) == 1 and list(
        c1_max_group)[0] in c2_max_group:
    v1 = n - c1_max - c2_second
    v2 = n - c1_second - c2_max
    ans = min(v1, v2)
else:
    ans = n - c1_max - c2_max
print(ans)

Solution (Python):

import collections

def search_b(a_char, a_count, b_most_common, fixed_count):
  thres = fixed_count - a_count
  for (b_char, b_count) in [b for b in b_most_common if b[1] > thres]:
    if a_char != b_char:
      return a_count + b_count
  
  return fixed_count


def search(a_most_common, b_most_common):
  fixed_count = -1
  b_max = b_most_common[0][1]

  for (a_char, a_count) in a_most_common:
    if a_count <= fixed_count - b_max:
      break

    fixed_count = search_b(a_char, a_count, b_most_common, fixed_count)
  
  return fixed_count


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

  a = V[::2]
  b = V[1::2]
  
  a_counter = collections.Counter(a)
  b_counter = collections.Counter(b)

  a_most_common = a_counter.most_common()
  b_most_common = b_counter.most_common()

  if len(a_most_common) == 1 and len(b_most_common) == 1 and a_most_common[0][0] == b_most_common[0][0]:
    print(n // 2)
    return

  print(n - search(a_most_common, b_most_common))


if __name__ == '__main__':
  main()

Solution (Python):
import collections

n = int(input())
li = list(map(int,input().split()))
x = li[::2]
y = li[1::2]
c = collections.Counter(li)
c0 = collections.Counter(x)
c1 = collections.Counter(y)

if c.most_common()[0][1] == len(li): 
    print(n//2)

elif c0.most_common()[0][0] != c1.most_common()[0][0]: 
    print(n - c0.most_common()[0][1] - c1.most_common()[0][1])

else:
    if len(c0.keys())==1: 
        print(n//2 - c1.most_common()[1][1]) 
    elif len(c1.keys())==1: 
        print(n//2 - c0.most_common()[1][1]) 
    elif c0.most_common()[0][1] + c1.most_common()[1][1] < c0.most_common()[1][1] + c1.most_common()[0][1]:
        print(n - c0.most_common()[1][1] - c1.most_common()[0][1])
    else:
        print(n - c0.most_common()[0][1] - c1.most_common()[1][1])

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


odd_counter = collections.Counter(Vs[0::2])
odd_counter_tuple = odd_counter.most_common()

if len(odd_counter_tuple) == 1:
    odd1 = odd_counter_tuple[0][0]
    odd2 = None
else:
    odd1 = odd_counter_tuple[0][0]
    odd2 = odd_counter_tuple[1][0]


even_counter = collections.Counter(Vs[1::2])
even_counter_tuple = even_counter.most_common()

if len(even_counter_tuple) == 1:
    even1 = even_counter_tuple[0][0]
    even2 = None
else:
    even1 = even_counter_tuple[0][0]
    even2 = even_counter_tuple[1][0]

if odd1 != even1:
    ans = n - odd_counter[odd1] - even_counter[even1]
else:
    ans = min(n-odd_counter[odd2]-even_counter[even1], n-odd_counter[odd1]-even_counter[even2])

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()
arr=limii()
arra=[]
arrb=[]

for i in range(n):
    if i%2==0:
        arra.append(arr[i])
    else:
        arrb.append(arr[i])
    
r=list(Counter(arra).most_common(2))
s=list(Counter(arrb).most_common(2))

if len(r)==1 and len(s)==1:
    if r[0][0]==s[0][0]:
        print(len(arra))
        exit()
    else:
        print(0)
        exit()

if r[0][0]==s[0][0]:
    if r[0][1]==s[0][1]:
        print(len(arra)-max(r[0][1],s[0][1]) + len(arra)-max(r[1][1],s[1][1]))
        exit()
    else:
        print(len(arra)-max(r[0][1],s[0][1]) + len(arra)-max(r[1][1],s[1][1]))
        exit()
else:
    print(len(arra)-r[0][1]+len(arra)-s[0][1])
    exit()

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

lst1 = lst[::2]
lst2 = lst[1::2]

count1 = Counter(lst1)
count2 = Counter(lst2)
  
if count1.most_common()[0][0] != count2.most_common()[0][0]:
  ans = n - count1.most_common()[0][1] - count2.most_common()[0][1]

else:
  if len(count1) != 1 and len(count2) != 1:
    k = max(count1.most_common()[0][1] + count2.most_common()[1][1], count1.most_common()[1][1] + count2.most_common()[0][1])
    ans = n - k
  elif len(count1) == 1 and len(count2) == 1:
    ans = n//2
  else:
    if len(count1) < len(count2):
      ans = n//2 - count2.most_common()[0][1]
    else:
      ans = n//2 - count1.most_common()[0][1]
print(ans)