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 sys, re
from math import ceil, floor, sqrt, pi, factorial
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext

def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    num_list = i_list()

    zero_list = []
    one_list = []
    for i in range(n):
        if i % 2 == 0:
            zero_list.append(num_list[i])
        else:
            one_list.append(num_list[i])

    zero_c = Counter(zero_list)
    one_c = Counter(one_list)

    zero_saihin_key = zero_c.most_common()[0][0]
    zero_saihin_val = zero_c.most_common()[0][1]
    one_saihin_key = one_c.most_common()[0][0]
    one_saihin_val = one_c.most_common()[0][1]

    if zero_saihin_key != one_saihin_key:
        print(n - zero_saihin_val - one_saihin_val)
        exit()

    if num_list.count(zero_saihin_key) == n:
        print(n//2)
        exit()

    if len(zero_c) == 1:
        print(n//2 - one_c.most_common()[1][1])
    elif len(one_c) == 1:
        print(n//2 - zero_c.most_common()[1][1])
    else:
        count1 = n - zero_saihin_val - one_c.most_common()[1][1]
        count2 = n - zero_c.most_common()[1][1] - one_saihin_val
        print(min(count1, count2))

if __name__ == '__main__':
    main()

Solution (Python):
def resolve():
    import math
    from collections import Counter
    n = int(input())
    v = [int(i) for i in input().split()]
    c0 = Counter(v[0::2]).most_common(2)
    c1 = Counter(v[1::2]).most_common(2)
    l0 = math.ceil(n / 2)
    l1 = n // 2
    if c0[0][0] != c1[0][0]:
        print(l0 - c0[0][1] + l1 - c1[0][1])
    else:
        if len(c0) == 1 and len(c1) == 1:
            print(n // 2)
        else:
            if len(c0) == 2 and len(c1) == 2:
                print(min(l0 - c0[0][1] + l1 - c1[1][1],
                          l0 - c0[1][1] + l1 - c1[0][1]))
            elif len(c0) == 1:
                print(l1 - c1[1][1])
            else:
                print(l0 - c0[1][1])


resolve()

Solution (Python):
from collections import Counter
n=int(input())
vs=list(map(int,input().split()))
xs=vs[0::2]
ys=vs[1::2]
cx=Counter(xs).most_common()
cy=Counter(ys).most_common()
if len(cx)==1:
    cx.append((0,0))
if len(cy)==1:
    cy.append((-1,0))
if not cx[0][0]==cy[0][0]:
    print(len(xs)-cx[0][1]+len(ys)-cy[0][1])
else:
    mx=len(xs)-cx[1][1]+len(ys)-cy[0][1]
    my=len(xs)-cx[0][1]+len(ys)-cy[1][1]
    print(min(mx,my))

Solution (Python):
N = int(input())
N_2 = N//2

v = list(map(int, input().split()))
v_odd = [v[2*i+1] for i in range(N_2)]
v_evn = [v[2*i] for i in range(N_2)]

lst_odd = [0] * 100001
lst_evn = [0] * 100001

for vi in v_odd:
  lst_odd[vi] += 1
  
for vi in v_evn:
  lst_evn[vi] += 1
  
tpl_odd = [(lst_odd[i+1], i+1) for i in range(100000)]
tpl_evn = [(lst_evn[i+1], i+1) for i in range(100000)]

tpl_odd.sort(reverse=True)
tpl_evn.sort(reverse=True)
if tpl_odd[0][1] != tpl_evn[0][1]:
  print(N - tpl_odd[0][0] - tpl_evn[0][0])
else:
  print(N - max(tpl_odd[1][0]+tpl_evn[0][0], tpl_odd[0][0]+tpl_evn[1][0]))

Solution (Python):
from collections import defaultdict

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

d1 = defaultdict(int)
d2 = defaultdict(int)
for i, v in enumerate(V):
    if i % 2 == 0:
        d1[v] += 1
    else:
        d2[v] += 1
d1 = sorted(d1.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)
d2 = sorted(d2.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)

best = 10 ** 10
for d1, d2 in ((d1, d2), (d2, d1)):
    ans = N // 2 - d1[0][1]
    val = d1[0][0]
    if d2[0][0] != val:
        ans += N // 2 - d2[0][1]
    else:
        ans += d2[0][1]
        if 2 < len(d2):
            ans += N // 2 - d2[0][1] - d2[1][1]
    best = min(best, ans)
print(best)

Solution (Python):
from collections import defaultdict

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

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

d0, d1 = defaultdict(int), defaultdict(int)

for i, v in enumerate(V):
    if i % 2 == 0:
        d0[v] += 1
    else:
        d1[v] += 1

d0_ = sorted(d0.items(), key=lambda x: -x[1])
d1_ = sorted(d1.items(), key=lambda x: -x[1])

a0, n0 = d0_[0]
a1, n1 = d1_[0]

if a0 != a1:
    ans = n - n0 - n1
else:
    if n0 > n1:
        m1 = d1_[1][1]
        ans = n - n0 - m1
    elif n0 < n1:
        m0 = d0_[1][1]
        ans = n - m0 - n1
    else:
        m0 = d0_[1][1]
        m1 = d1_[1][1]
        ans = n - n0 - max(m0, m1)

print(ans)

Solution (Python):
import collections

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

    c1 = collections.Counter(v[0::2])
    c2 = collections.Counter(v[1::2])
    
    def most(c, x, y):
        return c.most_common()[x][y]
    
    if most(c1, 0, 1) == most(c2, 0, 1) == n//2 and most(c1, 0, 0) == most(c2, 0, 0):
        print(n // 2)
    elif most(c1, 0, 0) != most(c2, 0, 0):
        print(n - most(c1, 0, 1)- most(c2, 0, 1))
    else:
            a  = n - most(c1, 1, 1)- most(c2, 0, 1)
            b  = n - most(c1, 0, 1)- most(c2, 1, 1)
            print(min(a, b))
         
    
if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

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

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

if c1[0][0] != c2[0][0]:
    ans = n - c1[0][1] - c2[0][1]
else:
    ans = n - max(c1[0][1] + c2[1][1], c1[1][1] + c2[0][1])

print(ans)

Solution (Python):
from collections import Counter


n = int(input())
v = list(map(int, input().split()))
v_former = Counter(v[::2]).most_common() + [(0, 0)]
v_latter = Counter(v[1::2]).most_common() + [(0, 0)]
if v_former[0][0] != v_latter[0][0]:
    print(n - v_former[0][1] - v_latter[0][1])
else:
    print(n - max(v_former[0][1] + v_latter[1][1], v_former[1][1] + v_latter[0][1]))

Solution (Python):
from collections import Counter


n = int(input())
v = list(map(int, input().split()))
v_former = sorted([(v, k) for k, v in Counter(v[::2]).items()], reverse=True) + [(0, 0)]
v_latter = sorted([(v, k) for k, v in Counter(v[1::2]).items()], reverse=True) + [(0, 0)]
if v_former[0][1] != v_latter[0][1]:
    print(n - v_former[0][0] - v_latter[0][0])
else:
    print(n - max(v_former[0][0] + v_latter[1][0], v_former[1][0] + v_latter[0][0]))

Solution (Python):
from collections import Counter


n = int(input())
v = list(map(int, input().split()))
v_former = sorted([(v, k) for k, v in Counter(v[::2]).items()], reverse=True)
v_latter = sorted([(v, k) for k, v in Counter(v[1::2]).items()], reverse=True)
if len(v_former) == 1 and len(v_latter) == 1:
    if v_former[0][1] != v_latter[0][1]:
        print(0)
    else:
        print(n // 2)
elif v_former[0][1] != v_latter[0][1]:
    print(n - v_former[0][0] - v_latter[0][0])
elif len(v_former) == 1:
    print(n - v_former[0][0] - v_latter[1][0])
elif len(v_latter) == 1:
    print(n - v_former[1][0] - v_latter[0][0])
else:
    print(n - max(v_former[0][0] + v_latter[1][0], v_former[1][0] + v_latter[0][0]))

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v1 = Counter(v[::2])
v2 = Counter(v[1::2])
E = v1.most_common()
O = v2.most_common()
if E[0][0] == O[0][0]:
    tmp1 = E[1][1] if len(E) > 1 else 0
    tmp2 = O[1][1] if len(O) > 1 else 0
    ans = min(n-E[0][1]-tmp2, n-tmp1-O[0][1])
else:
    ans = n-E[0][1]-O[0][1]
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
o, e = v[0::2], v[1::2]
co, ce = Counter(o).most_common(), Counter(e).most_common()
if co[0][0] == ce[0][0]:
    if len(co) == len(ce) == 1:
        print(n // 2)
    elif len(co) == 1:
        print(n // 2 - ce[0][1])
    elif len(ce) == 1:
        print(n // 2 - co[0][1])
    else:
        print(min(n - (co[1][1] + ce[0][1]),n - (co[0][1] + ce[1][1])))
else:
    if len(co) == len(ce) == 1:
        print(0)
    elif len(co) == 1:
        print(n // 2 - ce[0][1])
    elif len(ce) == 1:
        print(n // 2 - co[0][1])
    else:
        print(n - (co[0][1] + ce[0][1]))

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

first = {}
second = {}

for x in range(N):
    if x % 2 == 0:
        first.setdefault(v[x], 0)
        first[v[x]] += 1
    else:
        second.setdefault(v[x], 0)
        second[v[x]] += 1

first_sorted = sorted(first.items(), key=lambda x: x[1], reverse=True)
second_sorted = sorted(second.items(), key=lambda x: x[1], reverse=True)
sum_change_1 = 0

first_value = 0
for y in range(len(first_sorted)):
    if y == 0:
        first_value = first_sorted[y][0]
    if y != 0:
        sum_change_1 += first_sorted[y][1]

for z in range(len(second_sorted)):
    if first_value != second_sorted[0][0]:
        if z != 0:
            sum_change_1 += second_sorted[z][1]
    else:
        if z != 1:
            sum_change_1 += second_sorted[z][1]

sum_change_2 = 0

first_value = 0
for v in range(len(second_sorted)):
    if v == 0:
        first_value = second_sorted[v][0]
    if v != 0:
        sum_change_2 += second_sorted[v][1]

for w in range(len(first_sorted)):
    if first_value != first_sorted[0][0]:
        if w != 0:
            sum_change_2 += first_sorted[w][1]
    else:
        if w != 1:
            sum_change_2 += first_sorted[w][1]

print(min(sum_change_1, sum_change_2))

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
e = v[::2]
o = v[1::2]
ce = sorted([(v, k) for k, v in Counter(e).items()], reverse=True)
co = sorted([(v, k) for k, v in Counter(o).items()], reverse=True)
if ce[0][1] == co[0][1]:
    if len(ce) == 1 and len(co) == 1:
        print(len(o))
    elif len(ce) == 1:
        print(len(o) + len(e) - ce[0][0] - co[1][0])
    elif len(co) == 1:
        print(len(o) + len(e) - ce[1][0] - co[0][0])
    else:
        print(len(e) + len(o) - max(ce[1][0] + co[0][0], ce[0][0] + co[1][0]))
else:
    print(len(e) + len(o) - ce[0][0] - co[0][0])

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
 
n = INT()
v = LIST()

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

def cnt(v1, v2):
	ans1 = len(v1) - Counter(v1).most_common()[0][1]

	if Counter(v1).most_common()[0][0] != Counter(v2).most_common()[0][0]:
		ans2 = len(v2) - Counter(v2).most_common()[0][1]
	else:
		if len(Counter(v2).most_common()) == 1:
			ans2 = Counter(v2).most_common()[0][1]
		else:
			ans2 = len(v2) - Counter(v2).most_common()[1][1]

	return ans1 + ans2

print(min(cnt(v1, v2), cnt(v2, v1)))

Solution (Python):
from collections import Counter

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

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

if v1[0][0] != v2[0][0]:
    res = n - v1[0][1] - v2[0][1]
else:
    res = min(n - v1[0][1] - v2[1][1], n - v1[1][1] - v2[0][1])

print(res)

Solution (Python):
from collections import Counter

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

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

if v1[0] != v2[0]:
    res = n - v1[0][1] - v2[0][1]
else:
    res = min(n - v1[0][1] - v2[1][1], n - v1[1][1] - v2[0][1])

print(res)

Solution (Python):

"""
Created on Sun May 31 18:36:13 2020

@author: NEC-PCuser
"""
n = int(input())
l = list(map(int, input().split()))
dic_gusu = {}
dic_kisu = {}

for i in range(0, n):
    if (i % 2 == 0):
        if (l[i] in dic_gusu):
            dic_gusu[l[i]] += 1
        else:
            dic_gusu[l[i]] = 1
    if (i % 2 == 1):
        if (l[i] in dic_kisu):
            dic_kisu[l[i]] += 1
        else:
            dic_kisu[l[i]] = 1
dic_kisu = sorted(dic_kisu.items(), key = lambda x : x[1])
dic_gusu = sorted(dic_gusu.items(), key = lambda x : x[1])

count = 0
if (len(dic_kisu) == 1 and len(dic_gusu) == 1 and dic_kisu[len(dic_kisu) - 1][0] == dic_gusu[len(dic_gusu) - 1][0]):
    count = n // 2
elif (dic_kisu[len(dic_kisu) - 1][0] != dic_gusu[len(dic_gusu) - 1][0]):
    for i in range(0, len(dic_kisu) - 1):
        count += dic_kisu[i][1]
    for i in range(0, len(dic_gusu) - 1):
        count += dic_gusu[i][1]
else:
    for i in range(0, len(dic_kisu)):
        count += dic_kisu[i][1]
    for i in range(0, len(dic_gusu)):
        count += dic_gusu[i][1]
    count_tmp = count
    count_ans = count_tmp - dic_kisu[len(dic_kisu) - 1][1] - dic_gusu[len(dic_gusu) - 2][1] 
    count_ans2 = count_tmp  - dic_kisu[len(dic_kisu) - 2][1] - dic_gusu[len(dic_gusu) - 1][1]
    count = min([count_ans, count_ans2])    
        
print(count)

Solution (Python):
import sys
from collections import Counter

N = int(input())
V = list(map(int, sys.stdin.readline().rsplit()))

Ceven = Counter(V[::2])
Codd = Counter(V[1::2])

res = 0
even, odd = Ceven.most_common(2), Codd.most_common(2)
if even[0][0] != odd[0][0]:
    res = N - even[0][1] - odd[0][1]
else:
    if len(Ceven) == len(Codd) == 1:
        res = N // 2
    else:
        res = min(
            N - even[1][1] - odd[0][1],
            N - even[0][1] - odd[1][1]
        )
print(res)

Solution (Python):
from collections import Counter
n = int(input())
l = list(map(int, input().split()))
E = [i for i in l[::2]]
O = [i for i in l[1::2]]
e=Counter(E).most_common() 
o=Counter(O).most_common() 

if e[0][0] != o[0][0]: 
    print(n-e[0][1]-o[0][1])
else:
    if len(e)==1 or len(o)==1: 
        print(n//2)
    else: 
        a=n-e[1][1]-o[0][1]
        b=n-e[0][1]-o[1][1]
        print(min(a,b))

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

odd = []
even = []
for i, v in enumerate(V):
    if i % 2 == 0:
        odd.append(v)
    else:
        even.append(v)
num_odd = {}
for v in odd:
    if v in num_odd:
        num_odd[v] += 1
    else:
        num_odd[v] = 1
num_even = {}
for v in even:
    if v in num_even:
        num_even[v] += 1
    else:
        num_even[v] = 1
val_odd = sorted(num_odd.items(), key=lambda x:x[1])
val_even = sorted(num_even.items(), key=lambda x:x[1])
if len(val_odd) == 1 and len(val_even) == 1:
    if val_odd[0][0] == val_even[0][0]:
        
        print(n // 2)
    else:
        
        print(0)
else:
    
    if val_odd[-1][0] != val_even[-1][0]:
        
        count_odd = n // 2 - val_even[-1][1]
        count_even = n // 2 - val_odd[-1][1]
        print(count_odd + count_even)
    else:
        
        c1 = n - val_odd[-1][1] - val_even[-2][1]
        c2 = n - val_odd[-2][1] - val_even[-1][1]
        print(min(c1, c2))

Solution (Python):


from collections import deque,Counter


















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

kv1 = Counter(lisA[0:N:2]).most_common()
kv2 = Counter(lisA[1:N:2]).most_common()

if len(kv1)==len(kv2)==1 and kv1[0]==kv2[0]:
    print(N//2)
    exit()

ans1 = N
ans2 = N
for i in range(0,N//2-1):
    try:
        if kv1[0][0]!=kv2[i][0]:
            ans1 = min(ans1,N-(kv1[0][1]+kv2[i][1]))
        if kv1[i][0]!=kv2[0][0]:
            ans2 = min(ans2,N-(kv1[i][1]+kv2[0][1]))
    except:
        pass

print(min(ans1,ans2))

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

from collections import Counter, defaultdict
e, o = Counter(), Counter()
for i in range(n):
    if i % 2 == 0:
        e[v[i]] += 1
    else:
        o[v[i]] += 1

e_inv = defaultdict(list)
for key in e:
    e_inv[n // 2 - e[key]].append(key)
e_inv[n // 2].append(0)

o_inv = defaultdict(list)
for key in o:
    o_inv[n // 2 - o[key]].append(key)
o_inv[n // 2].append(0)

e_inv_keys = sorted(list(e_inv.keys()))
o_inv_keys = sorted(list(o_inv.keys()))

l1, l2 = e_inv[e_inv_keys[0]], o_inv[o_inv_keys[0]]
if len(l1) == 1 and len(l2) == 1 and l1 == l2:
    ans = min(e_inv_keys[0] + o_inv_keys[1], e_inv_keys[1] + o_inv_keys[0])
else:
    ans = e_inv_keys[0] + o_inv_keys[0]

print(ans)

Solution (Python):
import collections
N=int(input())
V=list(map(int,input().split()))
l=N//2
V_odd=[]
V_eve=[]
for i in range(N):
  if i%2==0:
    V_odd.append(V[i])
  else:
    V_eve.append(V[i])

p_odd = list(collections.Counter(V_odd).most_common())
p_eve = list(collections.Counter(V_eve).most_common())
p_odd.append([0,0])
p_eve.append([0,0])

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

Solution (Python):
import collections
N=int(input())
V=list(map(int,input().split()))
l=N//2
V_odd=[]
V_eve=[]
for i in range(N):
  if i%2==0:
    V_odd.append(V[i])
  else:
    V_eve.append(V[i])

p_odd = list(collections.Counter(V_odd).most_common())
p_eve = list(collections.Counter(V_eve).most_common())
p_odd.append([0,0])
p_eve.append([0,0])

if p_odd[0][0]!=p_eve[0][0]:
  print(N-p_odd[0][1]-p_eve[0][1])
  exit()
else:
  print(min(N-p_odd[0][1]-p_eve[1][1],N-p_odd[1][1]-p_eve[0][1]))

Solution (Python):
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])
c1 = Counter(a).most_common()
c2 = Counter(b).most_common()
if len(set(a)) == len(set(b)) == 1:
    if a == b:
        print(len(a))
    else:
        print(0)
else:
    if c1[0][0] != c2[0][0]:
        print(n - c1[0][1] - c2[0][1])
    else:
        print(min(n-c1[0][1] -c2[1][1],n - c1[1][1] - c2[0][1]))

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right


from functools import reduce
from pprint import pprint


INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n = I()
v = RI()

ans1 = 0
ans2 = 0

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

ac = Counter(a)
bc = Counter(b)

ma = 0
mb = 0

for i in ac:
    if ma<ac[i]:
        ma = ac[i]
        no1 = i
    else:
        pass

for i in bc:
    if mb<bc[i] and i!=no1:
        mb = bc[i]
        no2 = i
    else:
        pass

ans1 += len(a) - ma
ans1 += len(b) - mb

ma = 0
mb = 0

for i in bc:
    if mb<bc[i]:
        mb = bc[i]
        no2 = i
    else:
        pass

for i in ac:
    if ma<ac[i] and i!=no2:
        ma = ac[i]
        no1 = i
    else:
        pass

ans2 += len(a) - ma
ans2 += len(b) - mb

print(min(ans1,ans2))

Solution (Python):
n = int(input())
v_list = list(map(int,input().split()))
v_list_odd = v_list[::2]
v_list_ev = v_list[1::2]
import collections
c_odd = collections.Counter(v_list_odd)
c_even = collections.Counter(v_list_ev)

c_odd = sorted(c_odd.items(),key=lambda x:x[1],reverse = True)
c_even = sorted(c_even.items(),key=lambda x:x[1],reverse = True)
if c_odd[0][0] != c_even[0][0]:
  print(n - c_odd[0][1] - c_even[0][1])
else:
  if len(c_odd) == 1 and len(c_even) == 1:
    print(n - c_odd[0][1])
  elif len(c_odd) == 1:
    print(n - c_odd[0][1] - c_even[1][1])
  elif len(c_even) == 1:
    print(n - c_odd[1][1] - c_even[0][1])
  else:
    print(n - max(c_odd[1][1] + c_even[0][1],c_odd[0][1] + c_even[1][1]))

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
v1 = sorted(v[0::2])
v2 = sorted(v[1::2])
s1 = set(v1)
s2 = set(v2)

eve = [[0,0]]
odd = [[0,0]]
cnt_eve = 1
cnt_odd = 1

for i in range(1,n//2):
    
    if v1[i] == v1[i-1]:
        cnt_eve += 1
    else:
        eve.append([cnt_eve, v1[i-1]])
        cnt_eve = 1
    
    if v2[i] == v2[i-1]:
        cnt_odd += 1
    else:
        odd.append([cnt_odd, v2[i-1]])
        cnt_odd = 1
    if i == n//2 - 1:
        eve.append([cnt_eve, v1[i]])
        odd.append([cnt_odd, v2[i]])


eve.sort(key=lambda x: x[0], reverse=True)
odd.sort(key=lambda x: x[0], reverse=True)

if eve[0][1] != odd[0][1]:
    ans = n - eve[0][0] - odd[0][0]
    print(ans)
else:
    ans = n - max(eve[0][0] + odd[1][0], eve[1][0] + odd[0][0])
    print(ans)

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
v1 = sorted(v[0::2])
v2 = sorted(v[1::2])
s1 = set(v1)
s2 = set(v2)


eve = [[0,0]]
odd = [[0,0]]
cnt_eve = 1
cnt_odd = 1

for i in range(1,n//2):
    
    if v1[i] == v1[i-1]:
        cnt_eve += 1
    else:
        eve.append([cnt_eve, v1[i-1]])
        cnt_eve = 1
    if v2[i] == v2[i-1]:
        cnt_odd += 1
    else:
        odd.append([cnt_odd, v2[i-1]])
        cnt_odd = 1
    if i == n//2 - 1:
        eve.append([cnt_eve, v1[i]])
        odd.append([cnt_odd, v2[i]])


eve.sort(key=lambda x: x[0], reverse=True)
odd.sort(key=lambda x: x[0], reverse=True)

if eve[0][1] != odd[0][1]:
    ans = n - eve[0][0] - odd[0][0]
    print(ans)
else:
    ans = n - max(eve[0][0] + odd[1][0], eve[1][0] + odd[0][0])
    print(ans)

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

import sys
input = sys.stdin.readline









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



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



from collections import Counter
c1 = Counter(v1).most_common()
c2 = Counter(v2).most_common()


c1.append((0,0))
c2.append((0,0))


if c1[0][0]==c2[0][0]:
    print(min(N-(c1[0][1]+c2[1][1]), N-(c1[1][1]+c2[0][1])))
else:
    print(N- (c1[0][1]+c2[0][1]))

Solution (Python):
from collections import Counter

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

V_even = V[: : 2]
V_odd = V[1: : 2]

D_even = Counter(V_even)
D_odd = Counter(V_odd)

ans = 0
even, odd = D_even.most_common(2), D_odd.most_common(2)
if even[0][0] != odd[0][0]:
    ans = n - even[0][1] - odd[0][1]
else:
    if len(D_even) == len(D_odd) == 1:
        ans = n // 2
    else:
        ans = min(
            n - even[1][1] - odd[0][1],
            n - even[0][1] - odd[1][1]
        )

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
odd_common = Counter(a[::2]).most_common()
even_common = Counter(a[1::2]).most_common()
odd_common.append(('', 0))
even_common.append(('', 0))
if odd_common[0][0] != even_common[0][0]:
    print(n - odd_common[0][1] - even_common[0][1])
else:
    b = max(odd_common[0][1] + even_common[1][1], odd_common[1][1] + even_common[0][1])
    print(n - b)

Solution (Python):
def count(l):
    odd = {}
    even = {}
    for idx, d in enumerate(l):
        if idx%2 == 0:
            res = even
        else:
            res = odd
        if d in res:
            res[d] += 1
        else:
            res[d] = 1
    return odd, even
n = int(input())
data = list(map(int, input().split()))
odd, even = count(data)
odd = sorted(odd.items(), key=lambda x:-x[1])
even = sorted(even.items(), key=lambda x:-x[1])
if len(odd) == 1 and len(even) == 1:
    if odd[0][0] != even[0][0]:
        print(0)
    else:
        print(min(odd[0][1], even[0][1]))
else:
    size = n//2
    if odd[0][0] != even[0][0]:
        ans = 2*size - odd[0][1] - even[0][1]
        print(ans)
    else:
        ans1 = 2*size - odd[0][1] - even[1][1]
        ans2 = 2*size - odd[1][1] - even[0][1]
        print(min(ans1, ans2))

Solution (Python):
import collections

N = int(input())
A = list(map(int,input().split()))
odd = []
even = []
for i in range(N):
    if i % 2 == 1:
        odd.append(A[i])
    else:
        even.append(A[i])
Dic_odd = collections.Counter(odd)
Dic_eve = collections.Counter(even)
M_odd = Dic_odd.most_common()
M_eve = Dic_eve.most_common()

if M_odd[0][0] != M_eve[0][0]:
    ans = len(odd) - M_odd[0][1] + len(even) - M_eve[0][1]
else:
    if len(M_odd) == 1 and len(M_eve) == 1:
        ans = min(len(odd), len(even))
    elif len(M_odd) == 1:
        ans = min(len(even) - M_eve[1][1], len(even) - M_eve[0][1] + len(odd))
    elif len(M_eve) == 1:
        ans = min(len(odd) - M_odd[1][1], len(odd) - M_odd[0][1] + len(even))
    else:
        ans = len(odd) + len(even) - max(M_odd[0][1] + M_eve[1][1], M_odd[1][1] + M_eve[0][1])
print(ans)

Solution (Python):
import itertools
from collections import Counter
N  = int(input())
V = [int(x) for x in input().split()]
ev_cnt = Counter(V[::2])
od_cnt = Counter(V[1::2])

ev_cnt[-1] = 0
od_cnt[-2] = 0

ev = ev_cnt.most_common(2)
od = od_cnt.most_common(2)
ans = N
for (k1,v1), (k2,v2) in itertools.product(ev,od):
    if k1==k2:
        continue
    x = N - v1 - v2
    if ans > x:
        ans = x
print(ans)

Solution (Python):
import collections
n=int(input())
v=list(map(int,input().split()))
v1=v[0::2]
v2=v[1::2]
c1=collections.Counter(v1).most_common()
c2=collections.Counter(v2).most_common()
if c1[0][0] != c2[0][0]:
	if len(c1) == 1 and len(c2) == 1:
		print(0)
		exit()
	elif len(c1) == 1:
		print(n//2-c2[0][1])
		exit()
	elif len(c2) == 1:
		print(n//2-c1[0][1])
		exit()
	else:
		print(n-c1[0][1]-c2[0][1])
		exit()
else:
	
	if len(c1) == 1 and len(c2) == 1:
		print(n//2)
		exit()
	elif len(c1) == 1:
		print(n//2-c2[1][1])
		exit()
	elif len(c2) == 1:
		print(n//2-c1[1][1])
		exit()
	else:
		print(min(n-c1[1][1]-c2[0][1],n-c1[0][1]-c2[1][1]))
		exit()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
even = {}
odd = {}

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


emode = max(even, key=even.get)
omode = max(odd, key=odd.get)
emax = max(even.values())
omax = max(odd.values())

if emode != omode:
  print(n-emax-omax)
else:
  even[emode]=0
  odd[omode]=0
  emax2 = max(even.values())
  omax2 = max(odd.values())
  print(min(n-emax-omax2, n-emax2-omax))

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

d1 = [0]*(10**5+1)
d2 = [0]*(10**5+1)
for i in range(n):
    if i%2: d2[v[i]] += 1
    else: d1[v[i]] += 1
        
max_d1 = [0, 0]
max_d2 = [0, 0]
submax_d1 = [0, 0]
submax_d2 = [0, 0]
for i in range(10**5+1):
    if max_d1[1] < d1[i]:
        submax_d1 = deepcopy(max_d1)
        max_d1[0] = i
        max_d1[1] = d1[i]
    elif submax_d1[1] < d1[i]:
        submax_d1[0] = i
        submax_d1[1] = d1[i]
    if max_d2[1] < d2[i]:
        submax_d2 = deepcopy(max_d2)
        max_d2[0] = i
        max_d2[1] = d2[i]
    elif submax_d2[1] < d2[i]:
        submax_d2[0] = i
        submax_d2[1] = d2[i]
if max_d1[0] == max_d2[0]:
    if max_d1[1] + submax_d2[1] > max_d2[1]+submax_d1[1]:
        print(n-max_d1[1]-submax_d2[1])
    else:
        print(n-max_d2[1]-submax_d1[1])
else:
    print(n-max_d1[1]-max_d2[1])

Solution (Python):


from collections import defaultdict
import sys
readline = sys.stdin.readline

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

d0 = defaultdict(int)
d1 = defaultdict(int)
d0[0] = 0
d1[0] = 0
for i in range(n):
    if i%2:
        d1[v[i]] += 1
    else:
        d0[v[i]] += 1

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

if d0[0][0] != d1[0][0]:
    ans = n - d0[0][1] - d1[0][1]
else:
    ans = n - max(d0[0][1] + d1[1][1], d0[1][1] + d1[0][1])
print(ans)