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):
from collections import Counter
 
n = int(input())
v = list(map(int,input().split()))
vo = v[::2]
ve = v[1::2]
co = Counter(vo).most_common()
ce = Counter(ve).most_common()
co.append((-1, 0)) 
ce.append((-2, 0)) 
if co[0][0] != ce[0][0]: 
    print(n - co[0][1] - ce[0][1])
else:
    res1 = n - co[0][1] - ce[1][1] 
    res2 = n - co[1][1] - ce[0][1] 
    print(min(res1, res2))

Solution (Python):
from collections import defaultdict

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

li_ki = li_input[0::2]
d_ki = defaultdict(int)
for ki in li_ki:
    d_ki[ki] += 1


li_gu = li_input[1::2]
d_gu = defaultdict(int)
for gu in li_gu:
    d_gu[gu] += 1

ki_sort = sorted([(k, v) for k,v in d_ki.items()], key=lambda x : x[1], reverse=True)
gu_sort = sorted([(k, v) for k,v in d_gu.items()], key=lambda x : x[1], reverse=True)

ki_cnt = 0
gu_cnt = 0

if ki_sort[0][0] != gu_sort[0][0]:
    print(n - ki_sort[0][1] - gu_sort[0][1])
else:
    ki_1 = ki_sort[0][1]
    ki_2 = ki_sort[1][1] if len(ki_sort) > 1 else 0

    gu_1 = gu_sort[0][1]
    gu_2 = gu_sort[1][1] if len(gu_sort) > 1 else 0

    print(min(n - ki_1 - gu_2, n - ki_2 - gu_1))

Solution (Python):
import bisect

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

a = sorted(v[::2])
b = sorted(v[1::2])	

def get_frequent_num(a):
  a_max = 0
  a_max_num = 0
  i=0
  prev_i = 0
  max_value, sec_value = 0, 0
  max_num, sec_num = 0, 0
  while i < len(a):
      i = bisect.bisect(a, a[i])
      num = (i - prev_i)
      if num > max_num:
        sec_num = max_num
        max_num = num
        sev_value = max_value
        max_value = a[i-1]
      elif num > sec_num:
        sec_num = num
        sec_value = a[i-1]
      prev_i = i
  return max_num, max_value, sec_num, sec_value

amn, amv, asn, asv = get_frequent_num(a)
bmn, bmv, bsn, bsv = get_frequent_num(b)

if amv != bmv:
  print(n-amn-bmn)
elif amv == bmv:
  if amn == asn or bmn == bsn:
    print(n-amn-bmn)
  elif asn < bsn:
    print(n-bsn-amn)
  else:
    print(n-bmn-asn)

Solution (Python):
import collections
 
def counter_top(c, exclude):
  for a in c.most_common():
    if a[0] != exclude:
      return a
  return (object(), 0)
 
def conv_seq(seq, exclude=None):
  c = collections.Counter(seq)
  mc = counter_top(c, exclude)
  return sum(c.values()) - mc[1], mc[0]
 
input()
vals = list(map(int, input().split()))
s1, a = conv_seq(vals[::2])
s2, b = conv_seq(vals[1::2])
if a != b:
  print(s1 + s2)
else:
  s1_new, _ = conv_seq(vals[::2], exclude=b)
  s2_new, _ = conv_seq(vals[1::2], exclude=a)
  print(min(s1_new + s2, s1 + s2_new))

Solution (Python):
import collections
n = int(input())
v = list(map(int, input().split()))
o = [v[i] for i in range(n) if i % 2 == 0]
e = [v[i] for i in range(n) if i % 2 == 1]
odd = collections.Counter(o)
even = collections.Counter(e)
odd_num = odd.most_common(2)
even_num = even.most_common(2)
odd_num.append(('', 0))
even_num.append(('', 0))
if odd_num[0][0] == even_num[0][0]:
    print(n - max(odd_num[0][1] + even_num[1][1], odd_num[1][1] + even_num[0][1]))
else:
    print(n - odd_num[0][1] - even_num[0][1])

Solution (Python):
import collections

n = int(input())
v = list(map(int,input().split()))
a = [v[i] for i in range(n) if i%2==0]
b = [v[i] for i in range(n) if i%2==1]

a = collections.Counter(a)
b = collections.Counter(b)

A = a.most_common()[:2]
A.append(("x",0))
B = b.most_common()[:2]
B.append(("x",0))
if A[0][0]==B[0][0]:
    print(n-max(A[0][1]+B[1][1],A[1][1]+B[0][1]))
else:
    print(n-A[0][1]-B[0][1])

Solution (Python):



import collections
n=int(input())
e=[]
o=[]
a=input().split(" ")
for i in range(n):
    if(i%2==0):
        e.append(a[i])
    else:
        o.append(a[i])

e_c=collections.Counter(e)
e_m=e_c.most_common()
e1=e_m[0][1]

o_c=collections.Counter(o)
o_m=o_c.most_common()
o1=o_m[0][1]

ans=n-(e1+o1)
if(o_m[0][0]==e_m[0][0]):
    if(len(o_m)<2):
        o2=0
    if(len(e_m)<2):
        e2=0
    else:
        e2=e_m[1][1]
        o2=o_m[1][1]
    ans_list=[n-(o1+e2),n-(e1+o2)]
    ans=min(ans_list)
print(ans)

Solution (Python):
def get_second(a):
	if len(a) == 1:
		return 0
	else:
		return a[1][0]

n = int(input())
a = [int(v) for v in input().split()]
nums = [{}, {}]
for i, v in enumerate(a):
	if v in nums[i % 2]:
		nums[i % 2][v] += 1
	else:
		nums[i % 2][v] = 1
evens = sorted([(v, k) for k, v in nums[0].items()], reverse=True)
odds = sorted([(v, k) for k, v in nums[1].items()], reverse=True)
if evens[0][1] != odds[0][1]:
	print(n - evens[0][0] - odds[0][0])
else:
	print(n - max(evens[0][0] + get_second(odds), get_second(evens) + odds[0][0]))

Solution (Python):
import collections
n = int(input())
v = list(map(int, input().split()))
v_even = v[::2]
v_odd = v[1::2]
c_even = collections.Counter(v_even)
c_odd = collections.Counter(v_odd)
even_list = c_even.most_common()+[(-1, int(0))]
odd_list = c_odd.most_common()+[(-1, int(0))]

for test in even_list:
    if odd_list[0][0] != test[0]:
        even_cd = test
        cost1 = odd_list[0][1] + test[1]
        break
for  test in odd_list:
    if even_list[0][0] != test[0]:
        odd_cd = test
        cost2 = even_list[0][1] + test[1]
        break

if cost1>=cost2:
    print(n-cost1)
else:
    print(n-cost2)

Solution (Python):

from collections import Counter

n = int(input())
v = list(map(int, input().split()))
e = v[1::2] 
o = v[0::2] 
ans = 0

a = Counter(e) 
b = Counter(o)

c = a.most_common(2) 
d = b.most_common(2)

if c[0][0] != d[0][0]: 
    ans = n -c[0][1] -d[0][1]
else:                  
    if len(c) == 1:
        if len(d) == 1:
            ans = n//2
        else:
            ans = n -d[0][1]
    elif len(d) == 1 and len(c) != 1:
        ans = n -c[0][1]
    elif c[0][1] > d[0][1]:
        ans = n -c[0][1] -d[1][1]
    else:
        if c[0][1]==d[0][1]:
            ans = min(n-c[0][1]-d[1][1],n-c[1][1]-d[0][1])
        else:
            ans = n -c[1][1] -d[0][1]
    
print(ans)

Solution (Python):

N = int(input())
seq = list(map(int, input().rstrip().split(' ')))

odd = [[0, i] for i in range(int(1e5 + 1))]
even = [[0, i] for i in range(int(1e5 + 1))]

for i in range(0, N, 2):
    even[seq[i]][0] += 1
    
for i in range(1, N, 2):
    odd[seq[i]][0] += 1

sorted_even = sorted(even, key=lambda x: x[0])[::-1]
sorted_odd = sorted(odd, key=lambda x: x[0])[::-1]

if sorted_even[0][1] == sorted_odd[0][1]:
    if sorted_even[0][0] + sorted_odd[1][0] > sorted_even[1][0] + sorted_odd[0][0]:
        max_even = sorted_even[0][0]
        max_odd = sorted_odd[1][0]
    else:
        max_even = sorted_even[1][0]
        max_odd = sorted_odd[0][0]
else:
    max_even = sorted_even[0][0]
    max_odd = sorted_odd[0][0]
 
count = 0
count += N // 2 - max_even
count += N // 2 - max_odd

print(count)

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
e=[0]*(n//2)
o=[0]*(n//2)
ans=0
for i in range(n):
    if i%2==0:
        e[i//2]=v[i]
    else:
        o[(i-1)//2]=v[i]
a=Counter(e)
b=Counter(o)
c=a.most_common(2)
d=b.most_common(2)
if c[0][0]!=d[0][0]:
    ans=n-c[0][1]-d[0][1]
else:
    if len(c)==1:
        if len(d)==1:
            ans=n//2
        else:
            ans=len(d)-d[1][1]
    elif len(d)==1:
        if len(c)==1:
            ans=n//2
        else:
            ans=len(c)-c[1][1]
    else:
        if c[0][1]>d[0][1]:
            ans=n-c[0][1]-d[1][1]
        elif c[0][1]==d[0][1]:
            ans=min(n-c[0][1]-d[1][1],n-c[1][1]-d[0][1])
        else:
            ans=n-c[1][1]-d[0][1]
print(ans)

Solution (Python):
import sys
from collections import Counter
 
def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    ans = -1
    
    
    
    
    
    
    if even_c[0][0] != odd_c[0][0]:
        ans = len(m) - (even_c[0][1] + odd_c[0][1])
    
    
    elif even_c[0][0] == odd_c[0][0] and len(even_c) > 1:
        ans1 = len(m) - (even_c[0][1] + odd_c[1][1])
        ans2 = len(m) - (even_c[1][1] + odd_c[0][1])
        ans = ans1 if ans1 <= ans2 else ans2
    
    
    else:
        ans = even_c[0][1]
        
    
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
from collections import*;n,*v=map(int,open(0).read().split());a,b=[Counter(v[i::2]).most_common()+[(0,0)]for i in(0,1)];i,x=a[0];j,y=b[0];print(n-[x+y,max(x+b[1][1],y+a[1][1])][i==j])

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

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

def change(list):
    counter = Counter(list)
    m_ap1 = '0'
    m_ap2 = '0'
    if len(counter.most_common()) > 1:
        m_ap1, m_ap2 = counter.most_common()[0][0], counter.most_common()[1][0]
    else:
        m_ap1 = counter.most_common()[0][0]
    l = len(list)
    cnt1 = 0
    cnt2 = 0
    for i in range(l):
        if list[i] != m_ap1:
            cnt1 += 1
        if list[i] != m_ap2:
            cnt2 += 1
    return cnt1, cnt2, m_ap1, m_ap2
ca1, ca2, ma1, ma2 = change(a)
cb1, cb2, mb1, mb2 = change(b)


if ca1+cb1:
    if ma1 != mb1:
        print(ca1+cb1)
    else:
        print(min(ca1+cb2,cb1+ca2))
else:
    if ma1 != mb1:
        print(ca1+cb1)
    else:
        print(n//2)

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

from collections import Counter

v_0 = v[0::2]
v_1 = v[1::2]
v_0_ = Counter(v_0)
v_1_ = Counter(v_1)
v_0_[-1] = 0
v_1_[-1] = 0
v_0_ = v_0_.most_common()
v_1_ = v_1_.most_common()

if v_0_[0][0] != v_1_[0][0]:
    print(n-v_0_[0][1]-v_1_[0][1])
else:
    if v_0_[0][1] + v_1_[1][1] > v_0_[1][1] + v_1_[0][1]:
        print(n - v_0_[0][1] - v_1_[1][1])
    else:
        print(n - v_0_[1][1] - v_1_[0][1])

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

v = [v[::2], v[1::2]]

from collections import Counter
from operator import itemgetter
from itertools import product
c = list(map(Counter, v))
s = [sorted(d.items(), key=itemgetter(1), reverse=True) for d in c]
s = [(d + [(0, 0)])[:2] for d in s]
keep = 0
for e, o in product(*s):
    if e[0] == o[0]:
        continue
    tmp = e[1] + o[1]
    if tmp > keep:
        keep = tmp
ans = n - keep
print(ans)

Solution (Python):
n = int(input())
lst = str(input()).split(' ')
 
p1 = [0]*(max([int(i) for i in lst])+1)
p2 = [0]*(max([int(i) for i in lst])+1)
for idx in range(n):
	if idx%2 == 0:
		p1[int(lst[idx])] += 1
	else:
		p2[int(lst[idx])] += 1

if p1.index(max(p1)) == p2.index(max(p2)):
	print(min(n-max(p1)-sorted(p2)[-2], n-sorted(p1)[-2]-max(p2)))
else:
	print(n-max(p1)-max(p2))

'''
pp1 = p1.index(max(p1))
pp2 = p2.index(max(p2))
if pp1 == pp2:
	if max(p1)+sorted(p2)[-2] >= sorted(p1)[-2]+max(p2):
		pp2 = p2.index(sorted(p2)[-2])
		print(n-max(p1)-sorted(p2)[-2])
	else:
		pp1 = p1.index(sorted(p1)[-2])
		print(n-sorted(p1)[-2]-max(p2))
else:
	print(n-max(p1)-max(p2))

cnt1 = 0
cnt2 = 0
for idx in range(n):
	if idx%2 == 0:
		if not lst[idx] == str(pp1):
			cnt1 += 1
	else:
		if not lst[idx] == str(pp2):
			cnt2 += 1
'''

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

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

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

o.append((0,0))
e.append((0,0))

if o[0][0]==e[0][0]:
    ans=min(N-o[0][1]-e[1][1],N-e[0][1]-o[1][1])
else:
    ans=N-o[0][1]-e[0][1]
print(ans)



"""
ans=N
for o_l in o:
    for e_l in e:
        if o_l[0]!=e_l[0]:
            ans=min(ans,N-o_l[1]-e_l[1])
print(ans)
"""

Solution (Python):
from collections import Counter

N = int(input())
V = list(map(int,input().split()))
even = Counter(V[1::2]).most_common()+([[0, 0]])
odd = Counter(V[::2]).most_common()+([[0, 0]])
if(even[0][0] != odd[0][0]):
  print(N-even[0][1]-odd[0][1])
else:
  print(min(N-even[1][1]-odd[0][1], N-even[0][1]-odd[1][1]))

Solution (Python):
n = int(input())
lst = str(input()).split(' ')

p1 = [0]*(max([int(i) for i in lst])+1)
p2 = [0]*(max([int(i) for i in lst])+1)
for idx in range(n):
	if idx%2 == 0:
		p1[int(lst[idx])] += 1
	else:
		p2[int(lst[idx])] += 1

pp1 = p1.index(max(p1))
pp2 = p2.index(max(p2))
if pp1 == pp2:
	if max(p1)+sorted(p2)[-2] >= sorted(p1)[-2]+max(p2):
		pp2 = p2.index(sorted(p2)[-2])
	else:
		pp1 = p1.index(sorted(p1)[-2])

cnt1 = 0
cnt2 = 0
for idx in range(n):
	if idx%2 == 0:
		if not lst[idx] == str(pp1):
			cnt1 += 1
	else:
		if not lst[idx] == str(pp2):
			cnt2 += 1

print(cnt1 + cnt2)

Solution (Python):
from collections import Counter


def main():
    n = int(input())
    v_n = input().split(' ')
    
    gu = Counter(v_n[::2])
    ki = Counter(v_n[1::2])

    guusuu = gu.most_common()
    kisuu = ki.most_common()

    
    
    
    if guusuu[0][0]==kisuu[0][0]:
        if len(guusuu)==1 and len(kisuu)==1:
            
            
            print(guusuu[0][1])
        else:
            print(min(n - guusuu[0][1] - kisuu[1][1], n - guusuu[1][1] - kisuu[0][1]))
    else:
        print(n - guusuu[0][1] - kisuu[0][1])

main()

Solution (Python):

import sys


def solve(n: int, v: "List[int]"):
    a = {-1: 0}
    b = {-1: 0}
    for vv in v[::2]:
        if vv in a:
            a[vv] += 1
        else:
            a[vv] = 1
    for vv in v[1::2]:
        if vv in b:
            b[vv] += 1
        else:
            b[vv] = 1
    ai = sorted(list(a.keys()), key=lambda x: a[x], reverse=True)
    bi = sorted(list(b.keys()), key=lambda x: b[x], reverse=True)
    if ai[0] == bi[0]:
        ans1 = sum([a[x] for x in ai[1:]]) + sum([b[x] for x in bi])-b[bi[1]]
        ans2 = sum([a[x] for x in ai]) + sum([b[x] for x in bi[1:]])-a[ai[1]]
        print(min(ans1, ans2))

    else:
        ans = sum([a[x] for x in ai[1:]]) + sum([b[x] for x in bi[1:]])
        print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    v = [int(next(tokens)) for _ in range(n)]  
    solve(n, v)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]

if len(set(a)) == 1:
    p = int(n/2)
else:
    b0 = set(a[::2])
    if len(b0)==1:
        q0 = 0
        mark00 = a[0]
        count00, count01 = int(n/2), 0
    else:
        c = Counter(a[::2])
        q0 =  int(n/2) - c.most_common(1)[0][1]
        mark00, mark01 = c.most_common(2)[0][0], c.most_common(2)[1][0]
        count00, count01 = c.most_common(2)[0][1], c.most_common(2)[1][1]

    b1 = set(a[1::2])
    if len(b1)==1:
        q1 = 0
        mark10 = a[1]
        count10, count11 = int(n/2), 0
    else:
        c = Counter(a[1::2])
        q1 =  int(n/2) - c.most_common(1)[0][1]
        mark10, mark11 = c.most_common(2)[0][0], c.most_common(2)[1][0]
        count10, count11 = c.most_common(2)[0][1], c.most_common(2)[1][1]
    if mark00==mark10:
        if count00+count01>count10+count11:
            p = n - (count00+count01)
        else:
            p = n - (count10+count11)
    else:
        p = n - (count00 + count10)

print(p)

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 collections

N = int(input())
lst = input().split()
lst1 = []
lst2 = []
for i in range(N//2):
    lst1.append(lst[2 * i])
    lst2.append(lst[2 * i + 1])
dict1 = collections.Counter(lst1)
dict2 = collections.Counter(lst2)

count1  = 0 
count2  = 0

if (dict1.most_common()[0][0] == dict2.most_common()[0][0] ):
	
	if dict1.most_common()[0][1] > dict2.most_common()[0][1]:
		count1 =  len(lst1) - dict1.most_common()[0][1]
		if len(lst2) == dict2.most_common()[0][1]:
			count2 = len(lst2)
		else:
		    count2 =  len(lst2) - dict2.most_common()[1][1]
	elif dict1.most_common()[0][1] < dict2.most_common()[0][1]:
		if len(lst1) == dict1.most_common()[0][1]:
			count1 = len(lst1)
		else:
		    count1 =  len(lst1) - dict1.most_common()[1][1]
		count2 =  len(lst2) - dict2.most_common()[0][1]
	
	else :
		if len(lst1) == dict1.most_common()[0][1]:
			count1 = len(lst1) 
		elif (dict1.most_common()[1][1] >= dict2.most_common()[1][1]):
			count1 =  len(lst1) - dict1.most_common()[1][1]
			count2 =  len(lst2) - dict2.most_common()[0][1]
		else:
			count1 =  len(lst1) - dict1.most_common()[0][1]
			count2 =  len(lst2) - dict2.most_common()[1][1]

else:
		count1 =  len(lst1) - dict1.most_common()[0][1]
		count2 =  len(lst2) - dict2.most_common()[0][1]

print(count1 + count2)

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
even = Counter(v[1::2]).most_common(2)
odd = Counter(v[0::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

input = open(0).read

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


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

    em = e.most_common(2)
    om = o.most_common(2)

    
    em.append((0, 0))
    om.append((0, 0))

    if em[0][0] == om[0][0]:
        print(min(n - em[0][1] - om[1][1], n - em[1][1] - om[0][1]))
    else:
        print(n - em[0][1] - om[0][1])

    return


main()

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

def calc(start): 
    di = dict()
    for i in range(start, N, 2):
        if Ai[i] in di:
            n = di[Ai[i]]
            di[Ai[i]] = n + 1
        else:
            di[Ai[i]] = 1
    l = []
    for k in di.keys():
        l.append([k, di[k]])
    l.sort(key=lambda x: x[1], reverse=True)
    return l

l1 = calc(0)
l2 = calc(1)

if l1[0][0] != l2[0][0]:
    print(N - l1[0][1] - l2[0][1])
elif len(l1) == 1 and len(l2) == 1:
    print(N // 2)
else:
    v1 = 100000000000000
    v2 = 100000000000000

    if len(l1) > 1:
        v1 = N - l1[1][1] - l2[0][1]
    if len(l2) > 1:
        v2 = N - l1[0][1] - l2[1][1]
    print(min(v1, v2))

Solution (Python):
import numpy as np
from collections import Counter
n = int(input())
As = input().split()
As = [int(A) for A in As]

A_odd = As[::2]         
A_even = As[1:][::2]    


odd_pair = Counter(A_odd).most_common(2)
even_pair = Counter(A_even).most_common(2)

if odd_pair[0][0] != even_pair[0][0]:               
    N = n-odd_pair[0][1]-even_pair[0][1]
else:                                               
    if len(odd_pair) == 1 and len(even_pair) == 1:  
        N = n/2
    elif len(odd_pair) == 1:                        
        N = n-even_pair[1][1]
    elif len(even_pair) == 1:                       
        N = n-odd_pair[1][1] 
    elif odd_pair[1][1] > even_pair[1][1]:          
        N = n-even_pair[0][1]-odd_pair[1][1]
    else:
        N = n-odd_pair[0][1]-even_pair[1][1]        
print(int(N))

Solution (Python):
import collections as c
N = int(input())
a = list(map(int,input().split()))
ue = a[0::2]
sita = a[1::2]
dictue = c.defaultdict(int)
dictsita = c.defaultdict(int)
for i in ue:
    dictue[i] += 1
for i in sita:
    dictsita[i] += 1
ue = list(dictue.items())
ue.sort(key=lambda x:x[1])
sita = list(dictsita.items())
sita.sort(key=lambda x:x[1])
m = ue[len(ue)-1]
n = sita[len(sita)-1]
if m[0] == n[0]:
    if len(ue) == 1:
        if len(sita) == 1:
            print(N//2)
        else:
            print(N-m[1]-sita[len(sita)-2][1])
    else:
        if len(sita) == 1:
            print(N-n[1]-ue[len(ue)-2][1])
        else:
            print(min(N-n[1]-ue[len(ue)-2][1],N-m[1]-sita[len(sita)-2][1]))
else:
    print(N-m[1]-n[1])

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    v = LI()

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

    
    
    
    

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

    
    odd_count = collections.Counter(odd)
    even_count = collections.Counter(even)

    
    if len(odd_count) == len(even_count) == 1:
        
        print(0)
        exit()

    if odd_count.most_common(1)[0][0] != even_count.most_common(1)[0][0]:
        
        if len(odd_count) == 1:
            even_result = sum([i[1] for i in even_count.most_common()[1:]])
            print(even_result)
        elif len(even_count) == 1:
            odd_result = sum([i[1] for i in odd_count.most_common()[1:]])
            print(odd_result)
        else:
            odd_result = sum([i[1] for i in odd_count.most_common()[1:]])
            even_result = sum([i[1] for i in even_count.most_common()[1:]])
            print(odd_result + even_result)
    else:
        
        
        if len(odd_count) == 1:
            even_result = even_count.most_common(1)[0][1]
            even_result += sum([i[1] for i in even_count.most_common()[2:]])
            print(even_result)
        elif len(even_count) == 1:
            odd_result = odd_count.most_common(1)[0][1]
            odd_result += sum([i[1] for i in odd_count.most_common()[2:]])
            print(odd_result)
        elif odd_count.most_common(2)[1][1] > even_count.most_common(2)[1][1]:
            
            
            odd_result = odd_count.most_common(1)[0][1]
            odd_result += sum([i[1] for i in odd_count.most_common()[2:]])
            even_result = sum([i[1] for i in even_count.most_common()[1:]])
            print(odd_result + even_result)
        else:
            odd_result = sum([i[1] for i in odd_count.most_common(len(odd_count))[1:]])
            even_result = even_count.most_common(1)[0][1]
            even_result += sum([i[1] for i in even_count.most_common()[2:]])
            print(odd_result + even_result)

main()

Solution (Python):
def ans():
  N = int(input())
  V = list(map(int,input().split()))
  even = [0]*100001
  odd = [0]*100001
  for v in V[1::2]:
    even[v] += 1
  for v in V[::2]:
    odd[v] += 1
  me = max(even)
  mo = max(odd)
  if(even.index(me) != odd.index(mo)):
    print(N - me - mo)
  else:
    even.sort()
    odd.sort()
    print(min(N-even[-1]-odd[-2], N-even[-2]-odd[-1]))
ans()

Solution (Python):
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

n = ri()
v=rl()
a = []
b = []
for i in range(0,n,2):
    a.append(v[i])
for i in range(1,n,2):
    b.append(v[i])

import collections
ca = collections.Counter(a)
ca = ca.most_common()
cb = collections.Counter(b)
cb = cb.most_common()
la = len(a)
lb = len(b)

if ca[0][0] != cb[0][0]:
    ans = (la - ca[0][1]) + (lb - cb[0][1])
else:
    ans = []
    if len(ca) >= 2:
        ans.append(la-ca[1][1] + lb-cb[0][1])
    if len(cb) >= 2:
        ans.append(la-ca[0][1] + lb-cb[1][1])
    if len(ca)==1 and len(cb)==1:
        ans.append(ca[0][1])
        ans.append(cb[0][1])
    ans = min(ans)

print(ans)

Solution (Python):
def dekoboko(n: int, v: list) -> int:
    o, e = {}, {}
    for i, vv in enumerate(v):
        if i % 2 == 0:
            if vv not in e:
                e[vv] = 1
            else:
                e[vv] += 1
        else:
            if vv not in o:
                o[vv] = 1
            else:
                o[vv] += 1

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

    
    
    
    
    
    
    if ol[0][0] == el[0][0]:
        if len(ol) > 1:
            
            if ol[1][1] > el[1][1]:
                ol[0], ol[1] = ol[1], ol[0]
            else:
                el[0], el[1] = el[1], el[0]
        else:  
            
            el.append((0, 0))
            el[0], el[1] = el[1], el[0]

    return sum(v for _, v in ol[1:]) + sum(v for _, v in el[1:])


if __name__ == "__main__":
    n = int(input())
    v = map(int, input().split())
    ans = dekoboko(n, v)
    print(ans)

Solution (Python):
import collections
 
n=int(input())
v=list(map(int,input().split()))
 
even=v[0::2]
odd=v[1::2]
 
even_count=collections.Counter(even).most_common()
odd_count=collections.Counter(odd).most_common()
 

if even_count[0][0]!=odd_count[0][0]:
    print(n-even_count[0][1]-odd_count[0][1])
    

else:
    if len(even_count)==1:
        a=0
    else:
        a=even_count[1][1]
 
    if len(odd_count)==1:
        b=0
    else:
        b=odd_count[1][1]    
    
    ans1=n-a-odd_count[0][1]
    ans2=n-even_count[0][1]-b
    print(min(ans1,ans2))

Solution (Python):
from collections import Counter

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

even = v[0::2]
odd = v[1::2]
count_even = Counter(even).most_common()
count_odd = Counter(odd).most_common()

if count_even[0][0] == count_odd[0][0]:
    a = 0 if len(count_odd) == 1 else count_odd[1][1]
    b = 0 if len(count_even) == 1 else count_even[1][1]
    print(n - max(count_even[0][1] + a, count_odd[0][1] + b))
else:
    print(n - count_even[0][1] - count_odd[0][1])

Solution (Python):
import sys
input = sys.stdin.readline
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
a = []
b = []
for i in range(n):
    if i % 2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])

a = Counter(a)
amc = a.most_common()
b = Counter(b)
bmc = b.most_common()
amc.append((0,0))
bmc.append((0,0))
rewrite = 0

if amc[0][0] == bmc[0][0]:
    rewrite = max(amc[0][1]+bmc[1][1],amc[1][1]+bmc[0][1])
else:
    rewrite = amc[0][1]+bmc[0][1]
print(n-rewrite)

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

Solution (Python):
import collections
n=int(input())
arr=input().split(" ")
arr_s=set(arr)
a=0
arr_e=[0 for i in range(int(n/2))]
arr_o=[0 for i in range(int(n/2))]
for i in range(int(n/2)):
    arr_e[i]=arr[a]
    arr_o[i]=arr[a+1]
    a+=2
ce=collections.Counter(arr_e).most_common()
co=collections.Counter(arr_o).most_common()
if len(arr_s)==1:
    print(int(n/2))
else:
    if ce[0][0]!=co[0][0]:
        print(n-ce[0][1]-co[0][1])
    else:
        print(n-max(ce[0][1]+co[1][1],ce[1][1]+co[0][1]))

Solution (Python):
from collections import Counter

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

ve = Counter(V[0::2]).most_common(2)
vo = Counter(V[1::2]).most_common(2)


if ve[0][0] != vo[0][0]:
    print(n - ve[0][1] - vo[0][1])
else:
    
    if len(ve) == 1 or len(vo) == 1:
        print(n // 2)
    else:
        
        
        print(n - max(ve[0][1] + vo[1][1], ve[1][1] + vo[0][1]))

Solution (Python):
from sys import stdin
import collections
N=int(stdin.readline().rstrip())
data=[(x) for x in stdin.readline().rstrip().split()]
ans=0
if len(set(data)) == 1:
    ans=len((data[1::2]))
else:
    evenc = collections.Counter(data[0::2])
    even_num = evenc.most_common()[0][1]
    alle_num=len(data[0::2])
    
    oddc = collections.Counter(data[1::2])
    odd_num = oddc.most_common()[0][1]
    allo_num=len(data[1::2])
    
    if evenc.most_common()[0][0] == oddc.most_common()[0][0]:
        ans=min((N-(evenc.most_common()[1][1]+odd_num)),(N-(oddc.most_common()[1][1]+even_num)))
    
    else:
        ans=N-(even_num+odd_num)
            
    
print(ans)

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

Solution (Python):
import collections

n = int(input())
v = list(map(int, input().split()))
odd = []
even = []
for i in range(0, n - 1, 2):
	odd.append(v[i])
	even.append(v[i + 1])
N = n // 2
co = collections.Counter(odd)
ce = collections.Counter(even)
omost = co.most_common(2)
emost = ce.most_common(2)
if len(omost) == 1 and len(emost) == 1:
	if omost[0][0] != emost[0][0]:
		print(0)
	else:
		print(N)
elif len(omost) == 1:
	print(N - emost[0][1])
elif len(emost) == 1:
	print(N - omost[0][1])
else:
	if omost[0][0] != emost[0][0]:
		print(n - omost[0][1] - emost[0][1])
	else:
		print(min(n - omost[0][1] - emost[1][1], n - omost[1][1] - emost[0][1]))

Solution (Python):
import collections
v_odd,v_even=[],[]
ans=0
n=int(input())
all_v=input().split()
for i in range(1,n+1):
    if i % 2 == 0:
        v_even.append(all_v[i-1])
    else:
        v_odd.append(all_v[i-1])

v_odd_count = collections.Counter(v_odd)
v_even_count = collections.Counter(v_even)
v1=v_odd_count.most_common(2)
v11=v_even_count.most_common(2)
if v1[0][0] != v11[0][0]:
    ans = n-v1[0][1]-v11[0][1]
else:
    if len(v1)==len(v11)==1:
        ans = n//2
    elif len(v1)==1:
        ans = n//2 - v11[1][1]
    elif len(v11)==1:
        ans = n//2 - v1[1][1]
    else:
        ans = min((n - v1[0][1] - v11[1][1]),(n - v1[1][1] - v11[0][1]))
print(ans)