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())
a=list(map(int,input().split()))
x=Counter(a[0::2]).most_common()
y=Counter(a[1::2]).most_common()
x.append([0,0])
y.append([0,0])
if x[0][0]!=y[0][0]:
  print(n-x[0][1]-y[0][1])
else:
  print(min(n-x[1][1]-y[0][1], n-x[0][1]-y[1][1]))

Solution (Python):
import collections

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

ls1 = v[::2]
ls2 = v[1::2]

c1 = collections.Counter(ls1)
c2 = collections.Counter(ls2)

ch1, cnt1 = c1.most_common()[0][0], c1.most_common()[0][1]
ch2, cnt2 = c2.most_common()[0][0], c2.most_common()[0][1]

ret = 0
if ch1 != ch2:
    ret = n - cnt1 - cnt2
else:
    if cnt1 > cnt2:
        ret = n - cnt1 - c2.most_common()[1][1]
    elif cnt1 < cnt2:
        ret = n - cnt2 - c1.most_common()[1][1]
    else:
        if len(c1.most_common()) > 1 and len(c2.most_common()) > 1:
            cn1 = c1.most_common()[1][1]
            cn2 = c2.most_common()[1][1]
            ret = n - cnt1 - max(cn1, cn2)
        elif len(c1.most_common()) == 1 and len(c2.most_common()) > 1:
            ret = n - cnt1 - c2.most_common()[1][1]
        elif len(c1.most_common()) > 1 and len(c2.most_common()) == 1:
            ret = n - cnt2 - c1.most_common()[1][1]
        else:
            ret = n // 2

print(ret)

Solution (Python):
from collections import Counter
n = int(input())
vn = list(map(int, input().split()))
odd = []
even = []
for i in range(n):
    if i % 2 == 0:
        even.append(vn[i])
    else:
        odd.append(vn[i])
ans = len(even) + len(odd)
count_odd = Counter(odd).most_common()
count_even = Counter(even).most_common()
if count_odd[0][0] == count_even[0][0]:
    if len(set(even)) != 1 and len(set(odd)) != 1:
        even2 = count_even[1][1]
        odd2 = count_odd[1][1]
        ans -= max(even2 + count_odd[0][1], odd2 + count_even[0][1])
    elif len(set(even)) != 1 and len(set(odd)) == 1:
        ans -= count_odd[0][1] + count_even[1][1]
    elif len(set(even)) == 1 and len(set(odd)) != 1:
        ans -= count_even[0][1] + count_odd[1][1]
    else:
        ans -= max(count_even[0][1], count_odd[0][1])
else:
    ans -= count_odd[0][1] + count_even[0][1]
print(ans)

Solution (Python):
from collections import Counter

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

if len(set(v)) == 1:
    print(n//2)
else:
    c1 = Counter(v[0::2])
    c2 = Counter(v[1::2])
    
    c1m = c1.most_common(2)
    c2m = c2.most_common(2)
    
    if c1m[0][0] != c2m[0][0]:
        print(n-c1m[0][1]-c2m[0][1])
    else:
        mn = n
        if len(set(c1)) > 1:
            mn = min(mn, n-c1m[1][1]-c2m[0][1])
        if len(set(c2)) > 1:
            mn = min(mn, n-c1m[0][1]-c2m[1][1])
            
        print(mn)

Solution (Python):
import itertools
import math
import fractions
import functools
import copy

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

kisu = [0]*(10**6)
gusu = [0]*(10**6)
for i in range(n):
    if i % 2 == 0:
        gusu[v[i]] += 1
    else:
        kisu[v[i]] += 1

count = 0
gusu_m = gusu.index(max(gusu))
kisu_m = kisu.index(max(kisu))

if gusu_m == kisu_m:

    gusu[gusu_m] = 0
    kisu[kisu_m] = 0
    if max(gusu) > max(kisu):
        gusu_m = gusu.index(max(gusu))
    else:
        kisu_m = kisu.index(max(kisu))

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

print(count)

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
odd=[[0,0] for i in range(10**5+1)]
even=[[0,0] for i in range(10**5+1)]
for i in range(1,10**5+1):
    odd[i][1]=i
    even[i][1]=i
for i in range(n):
    if (i+1)%2==1:
        odd[v[i]][0]+=1
    else:
        even[v[i]][0]+=1
odd=sorted(odd,reverse=True)
even=sorted(even,reverse=True)
ans=0
if(odd[0][0]+even[0][0]==n): 
    if(odd[0][1]==even[0][1]):
        ans=n//2
    else:
        ans=0

else:
    
    if(odd[0][1]==even[0][1]):
        if(odd[0][0]+even[1][0]<=odd[1][0]+even[0][0]):
            ans=(n//2-odd[1][0])+(n//2-even[0][0])
        else:
            ans=(n//2-odd[0][0])+(n//2-even[1][0])

    else:
        ans=(n//2-odd[0][0])+(n//2-even[0][0])
print(ans)

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
odd=[[0,0] for i in range(10**5+1)]
even=[[0,0] for i in range(10**5+1)]
for i in range(1,10**5+1):
    odd[i][1]=i
    even[i][1]=i
for i in range(n):
    if (i+1)%2==1:
        odd[v[i]][0]+=1
    else:
        even[v[i]][0]+=1
odd=sorted(odd,reverse=True)
even=sorted(even,reverse=True)
ans=0
if(odd[0][0]+even[0][0]==n): 
    if(odd[0][1]==even[0][1]):
        ans=n//2
    else:
        ans=0

else:
    
    if(odd[0][1]==even[0][1]):
        if(odd[0][0]+even[1][0]<=odd[1][0]+even[0][0]):
            ans=(n//2-odd[1][0])+(n//2-even[0][0])
        else:
            ans=(n//2-odd[0][0])+(n//2-even[1][0])

    else:
        ans=(n//2-odd[0][0])+(n//2-even[0][0])
print(ans)

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


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

Solution (Python):
from collections import Counter

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

v_odd = v_list[0::2]
v_even = v_list[1::2]

c_odd = Counter(v_odd).most_common(2)
c_even = Counter(v_even).most_common(2)

if c_odd[0][0] == c_even[0][0]:
    if len(c_odd) > 1 and len(c_even) > 1:
        if c_odd[1][1] > c_even[1][1]:
            print(len(v_odd) - c_odd[1][1] + len(v_even) - c_even[0][1])
            exit()
        else:
            print(len(v_odd) - c_odd[0][1] + len(v_even) - c_even[1][1])
            exit()
    elif len(c_odd) >= 2:
        print(len(v_odd) - c_odd[1][1] + len(v_even) - c_even[0][1])
        exit()
    elif len(c_even) >= 2:
        print(len(v_odd) - c_odd[0][1] + len(v_even) - c_even[1][1])
        exit()
    else:
        print(len(v_even))
        exit()

print(len(v_odd) - c_odd[0][1] + len(v_even) - c_even[0][1])

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
ac = Counter(v[::2]).most_common(2)
bc = Counter(v[1::2]).most_common(2)



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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
V = getList()


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

topeven = even.index(max(even))
topodd = odd.index(max(odd))
even.sort()
odd.sort()

ans = 0
if topeven == topodd:
    
    opt1 = N - even[-1] - odd[-2]
    
    opt2 = N - even[-2] - odd[-1]
    
    ans = min(opt1, opt2)
else:
    ans = N - even[-1] - odd[-1]
print(ans)

Solution (Python):



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

n=I()
lis=LI()
ev,od=[],[]
for i in range(n):
    if i%2==0:
        ev.append(lis[i])
    else:
        od.append(lis[i])
c=Counter(ev)
d=Counter(od)


if c.most_common()[0][0]==d.most_common()[0][0]:
    if c.most_common()[0][1]==n//2:
        ans=n//2
    elif c.most_common()[1][1]>=d.most_common()[1][1]:
        ans=len(od)-d.most_common()[0][1]+len(ev)-c.most_common()[1][1]
    elif c.most_common()[1][1]<d.most_common()[1][1]:
        ans=len(od)-c.most_common()[0][1]+len(ev)-d.most_common()[1][1]
else:
    ans=len(ev)+len(od)-c.most_common()[0][1]-d.most_common()[0][1]
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
ac = Counter(v[::2]).most_common(2)
bc = Counter(v[1::2]).most_common(2)



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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18


n = I()
V = LI()
odd = [V[i] for i in range(n) if i % 2 != 0]
even = [V[i] for i in range(n) if i % 2 == 0]
A = Counter(odd).most_common(2) + [(0, 0)]
B = Counter(even).most_common(2) + [(0, 0)]
ans = INF
for a in A:
    for b in B:
        if a[0] == b[0]:
            continue
        else:
            ans = min(ans, n-a[1]-b[1])
print(ans)

Solution (Python):
import collections
n = int(input())
v = list(map(int, input().split()))
odd = []
even = []
for i in range(n):
    if i % 2 == 0:
        even.append(v[i])
    else:
        odd.append(v[i])
o = collections.Counter(odd)
o_list = list(o.items())
o_sorted = sorted(o_list, key=lambda x: x[1], reverse=True)
e = collections.Counter(even)
e_list = list(e.items())
e_sorted = sorted(e_list, key=lambda x: x[1], reverse=True)

if len(o_sorted) == 1 and len(e_sorted) == 1:
    if o_sorted[0][0] != e_sorted[0][0]:
        print(0)
    else:
        print(o_sorted[0][1])
else:
    if o_sorted[0][0] != e_sorted[0][0]:
        a = n//2-o_sorted[0][1]
        b = n//2-e_sorted[0][1]
        print(int(a+b))
    else:
        a = n//2-o_sorted[1][1]
        b = n//2-e_sorted[0][1]
        c = n//2-o_sorted[0][1]
        d = n//2-e_sorted[1][1]
        ans = min(a+b, c+d)
        print(int(ans))

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

odd_li = []
even_li = []
for i in range(n):
    if i%2==0:
        odd_li.append(v_input[i])
    else:
        even_li.append(v_input[i])

odd_count = sorted(Counter(odd_li).items(),key=lambda x:x[1],reverse=True)
even_count = sorted(Counter(even_li).items(),key=lambda x:x[1],reverse=True)

odd_max = odd_count[0][0]
even_max = even_count[0][0]

if odd_max==even_max and len(odd_count)==1:
    ans = n//2

elif odd_max==even_max:
    odd_next = odd_count[1][1]
    even_next = even_count[1][1]
    ans = n//2-odd_count[0][1] + n//2 - max(odd_next,even_next)
else:
    ans = n//2-odd_count[0][1] + n//2 - even_count[0][1]

print(ans)

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


def readstr():
    return input().strip()


def readint():
    return int(input())


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


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


def main():
    n = readint()
    v = list(readnums())
    ve = [x for i, x in enumerate(v) if not i % 2]
    vo = [x for i, x in enumerate(v) if i % 2]
    cve = Counter(ve)
    cvo = Counter(vo)
    if cve.most_common()[0][0] == cvo.most_common()[0][0]:
        if len(cve) == 1:
            print(n // 2)
        else:
            print(min(len(ve) - cve.most_common()[1][1] + len(vo) - cvo.most_common()[0][1], len(ve) - cve.most_common()[0][1] + len(vo) - cvo.most_common()[1][1]))
    else:
        print(len(ve) - cve.most_common()[0][1] + len(vo) - cvo.most_common()[0][1])


if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
count1 = defaultdict(int)
count2 = defaultdict(int)
for i in range(0, n, 2):
    count1[v[i]] += 1
for i in range(1, n, 2):
    count2[v[i]] += 1
res = 0
max_count1 = max(count1.values())
max_count2 = max(count2.values())
max_key1 = 0
max_key2 = 0
for key, value in count1.items():
    res += value
    if value == max_count1:
        max_key1 = key
for key, value in count2.items():
    res += value
    if value == max_count2:
        max_key2 = key
res = res - max_count1 - max_count2
ans1 = 0
ans2 = 0
ans = 0
if max_key1 == max_key2:
    ans1 = res + max_count1
    count1[max_key1] = 0
    next_max_count1 = max(count1.values())
    ans1 -= next_max_count1

    ans2 = res + max_count2
    count2[max_key2] = 0
    next_max_count2 = max(count2.values())
    ans2 -= next_max_count2
    ans = min(ans1, ans2)
else:
    ans = res
print(ans)

Solution (Python):
def main():
    from collections import Counter

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

    ctr_odd = Counter(V[::2])
    ctr_odd[-1] = 0  

    ctr_even = Counter(V[1::2])
    ctr_even[-1] = 0  

    ans = N
    for odd_n, odd_c in ctr_odd.most_common(2):
        for even_n, even_c in ctr_even.most_common(2):
            if odd_n == even_n: continue
            ans = min(ans, N - odd_c - even_c)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import math
import string
import collections
from collections import Counter


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())
v = readints()
cnt = 0
tmp = [0]*(10**5+1)
tmp2 = [0]*(10**5+1)
for i in range(n):
    if i % 2 == 0:
        tmp[v[i]] += 1
    else:
        tmp2[v[i]] += 1
tmp_max = 0
tmp2_max = 0
for i in range(len(tmp)):
    if tmp[tmp_max] < tmp[i]:
        tmp_max = i
for i in range(len(tmp2)):
    if tmp2[tmp2_max] < tmp2[i]:
        tmp2_max = i
if tmp_max != tmp2_max:
    cnt += (n//2)-tmp[tmp_max]
    cnt += (n//2)-tmp2[tmp2_max]
    print(cnt)
    exit()
tmp_max2 = 0
tmp2_max2 = 0
cnt2 = 0
cnt3 = 0
for i in range(len(tmp)):
    if i != tmp_max:
        if tmp[tmp_max2] < tmp[i]:
            tmp_max2 = i
for i in range(len(tmp2)):
    if i != tmp2_max:
        if tmp2[tmp2_max2] < tmp2[i]:
            tmp2_max2 = i
cnt2 = (n//2)-tmp[tmp_max]+(n//2)-tmp2[tmp2_max2]
cnt3 = (n//2)-tmp2[tmp2_max]+(n//2)-tmp[tmp_max2]
print(min(cnt2, cnt3))

Solution (Python):
from collections import Counter


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

    
    

    
    ac = Counter(v[::2]).most_common(2)
    bc = Counter(v[1::2]).most_common(2)

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

    

    
    
    
    

    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


if __name__ == '__main__':
    main()

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

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

t = collections.defaultdict(int)
t2 = collections.defaultdict(int)
for x in odd:
    t[x] += 1
for x in even:
    t2[x] += 1

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

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


t.append([0, 0])
t2.append([0, 0])
ans = t[0][1] + t2[0][1]
if t[0][0] == t2[0][0]:
    ans = max(t[0][1] + t2[1][1], t[1][1]+t2[0][1])
print(n - ans)

Solution (Python):
import collections

n = int(input())

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

v1 = v[::2]

v2 = v[1::2]
        
if len(set(v))==1:
    print(n//2)
else:
    maxv1 = collections.Counter(v1).most_common()

    maxv2 = collections.Counter(v2).most_common()


    if maxv1[0][0] == maxv2[0][0]:    
        ans1 = (len(v1) - maxv1[0][1]) + (len(v2) - maxv2[1][1])
        ans2 = (len(v1) - maxv1[1][1]) + (len(v2) - maxv2[0][1])
        print(min(ans1, ans2))
    else:
        ans = (len(v1) - maxv1[0][1]) + (len(v2) - maxv2[0][1])
        print(ans)

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

odd = collections.Counter(odd).most_common()
even = collections.Counter(even).most_common()

odd.append([0, 0])
even.append([0, 0])
ans = odd[0][1] + even[0][1]
if odd[0][0] == even[0][0]:
    ans = max(odd[0][1] + even[1][1], odd[1][1]+even[0][1])
print(n - ans)

Solution (Python):
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    v = list(map(int, input().split()))
    ev, od = [], []
    for i in range(n):
        if i % 2 == 0:
            ev.append(v[i])
        else:
            od.append(v[i])

    cnt_ev = sorted(Counter(ev).items(), key=lambda x: x[1], reverse=True)
    cnt_od = sorted(Counter(od).items(), key=lambda x: x[1], reverse=True)

    if len(cnt_ev) == 1 and len(cnt_od) == 1:
        if cnt_ev[0][0] == cnt_od[0][0]:
            res = n // 2
            print(res)
        else:
            res = 0
            print(res)
    elif len(cnt_ev) == 1:
        if cnt_ev[0][0] == cnt_od[0][0]:
            res = n // 2 - cnt_od[1][1]
            print(res)
        else:
            res = n // 2 - cnt_od[0][1]
            print(res)
    elif len(cnt_od) == 1:
        if cnt_ev[0][0] == cnt_od[0][0]:
            res = n // 2 - cnt_ev[1][1]
            print(res)
        else:
            res = n // 2 - cnt_ev[0][1]
            print(res)
    else:
        if cnt_ev[0][0] == cnt_od[0][0]:
            res1 = n - cnt_ev[0][1] - cnt_od[1][1]
            res2 = n - cnt_ev[1][1] - cnt_od[0][1]
            res = min(res1, res2)
            print(res)
        else:
            res = n - cnt_ev[0][1] - cnt_od[0][1]
            print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
freq_odd = [0] * (10 ** 5 + 1)
freq_even = [0] * (10 ** 5 + 1)
for i in range(n // 2):
    freq_odd[v[2 * i]] += 1
    freq_even[v[2 * i + 1]] += 1

freq_even, id_even = zip(*sorted(zip(freq_even, range(10 ** 5 + 1))))
freq_odd, id_odd = zip(*sorted(zip(freq_odd, range(10 ** 5 + 1))))


if id_even[-1] != id_odd[-1]:
    print(n - freq_even[-1] - freq_odd[-1])
else:
    print(min(n - freq_even[-2] - freq_odd[-1], n - freq_even[-1] - freq_odd[-2]))

Solution (Python):
from collections import Counter

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

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

c1 = dict(list(c1))
c2 = dict(list(c2))
c1[-1] = 0
c2[-2] = 0

MAX = 0
for k,v in c1.items():
    for k2,v2 in c2.items():
        if k != k2:
            MAX = max(v+v2,MAX)

print(N - MAX)

Solution (Python):
from collections import Counter

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

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

v_even = v[0::2]
v_odd = v[1::2]

cve = Counter(v_even)
cvo = Counter(v_odd)

if cve.most_common()[0][0] != cvo.most_common()[0][0]:
    ans = (n//2 - cve.most_common()[0][1]) + (n//2 - cvo.most_common()[0][1])
else:
    ans = min((n//2 - cve.most_common()[1][1]) + (n//2 - cvo.most_common()[0][1]), (n//2 - cve.most_common()[0][1]) + (n//2 - cvo.most_common()[1][1]))

print(ans)

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

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

t = collections.Counter(odd).most_common()
t2 = collections.Counter(even).most_common()


t.append([0, 0])
t2.append([0, 0])
ans = t[0][1] + t2[0][1]
if t[0][0] == t2[0][0]:
    ans = max(t[0][1] + t2[1][1], t[1][1]+t2[0][1])
print(n - ans)

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

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

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

if cv1[0][0] == cv2[0][0]:
    ans = n - max(cv1[0][1] + cv2[1][1], cv1[1][1] + cv2[0][1])
else:
    ans = n - cv1[0][1] - cv2[0][1]
print(ans)

Solution (Python):
def resolve():
    n = int(input())
    v = list(map(int, input().split()))
    ol = {}
    el = {}
    for i in range(len(v)):
        if i % 2 == 0:
            if v[i] in ol:
                ol[v[i]] += 1
            else:
                ol[v[i]] = 1
        else:
            if v[i] in el:
                el[v[i]] += 1
            else:
                el[v[i]] = 1
    ol = sorted(ol.items(), key=lambda x: x[1], reverse=True)
    el = sorted(el.items(), key=lambda x: x[1], reverse=True)

    
    if ol[0][0] != el[0][0]:
        print(len(v)-ol[0][1]-el[0][1])
    else:
        ofix = ol[0][0]
        if len(el) == 1:
            ans1 = len(v)-ol[0][1]
        else:
            ans1 = len(v)-ol[0][1]-el[1][1]
        efix = el[0][0]
        if len(ol) == 1:
            ans2 = len(v)-el[0][1]
        else:
            ans2 = len(v)-el[0][1]-ol[1][1]
        print(min(ans1, ans2))
resolve()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[0]*100009
c=[0]*100009
for i in range(n//2):
  b[a[i*2]]+=1
  c[a[i*2+1]]+=1
t=max(b)
r=max(c)
s=b.index(t)
p=c.index(r)
if s==p:
  b[s]=0
  k=max(b)
  c[p]=0
  j=max(c)
  f=max(k+r,t+j)
else:
  f=t+r
print(n-f)

Solution (Python):
import collections
n = int(input())
v = list(map(int,input().split()))
even = [] 
odd = []
for i in range(n//2):
  even.append(v[2*i])
  odd.append(v[2*i+1])
e = collections.Counter(even).most_common()
o = collections.Counter(odd).most_common()

ans = float("inf")
for i in range(2):
  for j in range(2):
    if i < len(e) and j < len(o):
      if e[i][0] == o[j][0]:
        continue
      else:
        ans = min(ans,n-(e[i][1]+o[j][1]))
if ans ==  float("inf"):
  ans = n//2       
print(ans)

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

from collections import Counter
c1 = Counter(V[::2])
c2 = Counter(V[1::2])
m1 = c1.most_common()
m2 = c2.most_common()

if m1[0][0] != m2[0][0]:
    ans = N - m1[0][1] - m2[0][1]
    print(ans)
    exit()
if len(m1) == len(m2) == 1:
    print(N//2)
    exit()

ans = N
if len(m1) > 1 and m1[1][0] != m2[0][0]:
    ans = min(ans, N - m1[1][1] - m2[0][1])
if len(m2) > 1 and m1[0][0] != m2[1][0]:
    ans = min(ans, N - m1[0][1] - m2[1][1])
if len(m1) > 1 and len(m2) > 1 and m1[1][0] != m2[1][0]:
    ans = min(ans, N - m1[1][1] - m2[1][1])
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  






n = read_a_int()
V = read_ints()

cnt0 = [(0, 0)] + list(Counter(V[::2]).items())
cnt1 = [(0, 0)] + list(Counter(V[1::2]).items())
cnt0.sort(key=itemgetter(1))
cnt1.sort(key=itemgetter(1))

if cnt0[-1][0] == cnt1[-1][0]:
    second = max(cnt0[-2][1], cnt1[-2][1])
    first = max(cnt0[-1][1], cnt1[-1][1])
    print(n - (second + first))
else:
    print(n - (cnt0[-1][1] + cnt1[-1][1]))

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from collections import defaultdict

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

dic1 = defaultdict(int)
dic2 = defaultdict(int)

for v in V[::2]:
    dic1[v] += 1
for v in V[1::2]:
    dic2[v] += 1

lst1 = [[dic1[i], i] for i in dic1]
lst2 = [[dic2[i], i] for i in dic2]

lst1.sort(key = lambda x: x[0], reverse = True)
lst2.sort(key = lambda x: x[0], reverse = True)

ans = N
if lst1[0][1] != lst2[0][1]:
    ans = N - lst1[0][0] - lst2[0][0]
else:
    if len(lst1) == 1:
        if len(lst2) == 1:
            ans = N // 2
        else:
            ans = N - lst1[0][0] - lst2[1][0]
    elif len(lst2) == 0:
        ans = N - lst1[1][0] - lst2[0][0]
    else:
        ans = N - max(lst1[0][0] + lst2[1][0], lst1[1][0] + lst2[0][0])

print (ans)

Solution (Python):
from collections import Counter
 
n, *v = map(int, open(0).read().split())
c1 = Counter(v[::2]).most_common()
c2 = Counter(v[1::2]).most_common()
 
c1.append([0, 0])
c2.append([0, 0])
 

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):
n = int(input())
v = list(map(int, input().split()))
odds = {}
evens = {}
for i in v[0::2]:
    if i in odds:
        odds[i] += 1
    else:
        odds[i] = 1
for i in v[1::2]:
    if i in evens:
        evens[i] += 1
    else:
        evens[i] = 1
odds = list(odds.items())
evens = list(evens.items())
odds.sort(key=lambda x:-x[1])
evens.sort(key=lambda x:-x[1])
odds.append((None, 0))
evens.append((None, 0))
if odds[0][0]!=evens[0][0]:
    print(n-odds[0][1]-evens[0][1])
else:
    print(n-max(odds[0][1]+evens[1][1], odds[1][1]+evens[0][1]))

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

kisu = v[::2]
gusu = v[1::2]

kisu_cnt = collections.Counter(kisu)
gusu_cnt = collections.Counter(gusu)

kisu_cnt = kisu_cnt.most_common(2)
gusu_cnt = gusu_cnt.most_common(2)
kisu_most  = 0
gusu_most = 0
if kisu_cnt[0][0]!=gusu_cnt[0][0]:
    print(n-kisu_cnt[0][1]-gusu_cnt[0][1])
    exit()
else:
    if len(kisu_cnt)==1 or len(gusu_cnt)==1:
        print(n//2)
        exit()
    else:
        print(n-max(kisu_cnt[0][1]+gusu_cnt[1][1],kisu_cnt[1][1]+gusu_cnt[0][1]))

Solution (Python):
from collections import Counter

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


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

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

        res = min(N-e1-o2, N-e2-o1)
        print(res)
else:
    print(N - o[0][1] - e[0][1])

Solution (Python):

import collections
def main():
    n=int(input())
    v=list(map(int,input().split()))
    ve=[]
    vo=[]
    for i in range(n//2):
        ve.append(v[2*i])
        vo.append(v[2*i+1])
    ce=collections.Counter(ve)
    co=collections.Counter(vo)
    ans=n
    if ce.most_common()[0][0]!=co.most_common()[0][0]:
        ans=n-ce.most_common()[0][1]-co.most_common()[0][1]
    elif len(ce)==1 and len(co)==1:
        ans=n-ce.most_common()[0][1]
    elif len(ce)==1:
        ans=n-ce.most_common()[0][1]-co.most_common()[1][1]
    elif len(co)==1:
        ans=n-ce.most_common()[1][1]-co.most_common()[0][1]
    else:
        ans=min(n-ce.most_common()[0][1]-co.most_common()[1][1],n-ce.most_common()[1][1]-co.most_common()[0][1])
    print(ans)
if __name__=="__main__":
    main()