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

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

    c1 = Counter(v[::2])
    c2 = Counter(v[1::2])
    o = c1.most_common(2)
    e = c2.most_common(2)
    o.append((0,0))
    e.append((0,0))
    if o[0][0] == e[0][0]:
        print(min(n-o[1][1]-e[0][1],n-o[0][1]-e[1][1]))
    else:
        print(n-o[0][1]-e[0][1])

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

if len(set(v)) == 1:
    print(n // 2)
else:
    c1 = Counter(v[::2])
    c2 = Counter(v[1::2])
    c1m = c1.most_common()
    c2m = c2.most_common()

    if c1m[0][0] == c2m[0][0]:
        print(min(n - c1m[0][1] - c2m[1][1], n - c1m[1][1] - c2m[0][1]))
    else:
        print(n - c1m[0][1] - c2m[0][1])

Solution (Python):

from collections import Counter
N = int(input())
V = list(map(int, input().split()))
evens = Counter(V[0::2]).most_common()
odds = Counter(V[1::2]).most_common()
evens.append((0, 0))
odds.append((0, 0))

if evens[0][0] == odds[0][0]:
    print(min(N - evens[1][1] - odds[0][1], N - evens[0][1] - odds[1][1]))
else:
    print(N - evens[0][1] - odds[0][1])

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] not in even:
            even[a[i]] = 1
        else:
            even[a[i]] += 1
    else:
        if a[i] not in odd:
            odd[a[i]] = 1
        else:
            odd[a[i]] += 1

sorted_even = sorted(even.items(), reverse=True, key=lambda x:x[1])
sorted_odd = sorted(odd.items(), reverse=True, key=lambda x:x[1])

if sorted_even[0][0] != sorted_odd[0][0]:
    print(n - sorted_even[0][1] - sorted_odd[0][1])
elif sorted_even[0][1] == sorted_odd[0][1]:
    if len(sorted_even) == 1 and len(sorted_odd) == 1:
        print(n//2)
    elif len(sorted_even) == 1:
        print(n - sorted_even[0][1] - sorted_odd[1][1])
    elif len(sorted_odd) == 1:
        print(n - sorted_even[1][1] - sorted_odd[0][1])
    elif sorted_even[1][1] > sorted_odd[1][1]:
        print(n - sorted_even[1][1] - sorted_odd[0][1])
    elif sorted_even[1][1] < sorted_odd[1][1]:
        print(n - sorted_even[0][1] - sorted_odd[1][1])
    else:
        print(n - sorted_even[0][1] - sorted_odd[1][1])
elif sorted_even[0][1] > sorted_odd[0][1]:
    print(n - sorted_even[0][1] - sorted_odd[1][1])
else:
    print(n - sorted_even[1][1] - sorted_odd[0][1])

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):
from collections import Counter
def main():
    n=int(input())
    v=list(map(int,input().split()))
    v0=sorted(Counter(v[::2]).items(), key=lambda x: x[1])
    v1=sorted(Counter(v[1::2]).items(), key=lambda x: x[1])
    
    if v0[-1][0] != v1[-1][0]:
        print(n-v0[-1][1]-v1[-1][1])
    else:
        if len(v0) == 1 and len(v1) == 1:
            print(n//2)
        else:
            a = (v0[-1][1] + v1[-2][1]) if len(v1) > 1 else 0
            b = (v0[-2][1] + v1[-1][1]) if len(v0) > 1 else 0
            print(n - max(a, b))
    
if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
def main():
    n=int(input())
    v=list(map(int,input().split()))
    v0=sorted(Counter(v[::2]).items(), key=lambda x: x[1])
    v1=sorted(Counter(v[1::2]).items(), key=lambda x: x[1])
    
    
    if v0[-1][0] != v1[-1][0]:
        print(n-v0[-1][1]-v1[-1][1])
    else:
        if len(v0) == 1 and len(v1) == 1:
            print(n//2)
        else:
            try:
                a = v0[-1][1] + v1[-2][1]
            except:
                a = 0
            try:
                b = v0[-2][1] + v1[-1][1]
            except:
                b = 0
            print(n - max(a, b))
    
if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
def main():
    n=int(input())
    v=list(map(int,input().split()))
    v0=Counter(v[0::2]).most_common(2)
    v1=Counter(v[1::2]).most_common(2)
    
    if v0[0][0] != v1[0][0]:
        print(n - v0[0][1] - v1[0][1])
    else:
        if len(v0) == 1 and len(v1) == 1:
            print(n//2)
        else:
            print(n-max(v0[0][1]+v1[1][1], v0[1][1]+v1[0][1]))
    
if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
 
dico = {}
dice = {}
for i in range(N):
  if i % 2 == 0:
    if As[i] not in dice:
      dice[As[i]] = 1
    else:
      dice[As[i]] += 1
  else:
    if As[i] not in dico:
      dico[As[i]] = 1
    else:
      dico[As[i]] += 1
    
cnto = [0,0]
cnte = [0,0]
 
o = -1
e = -1
for k in dico:
  if dico[k] > cnto[0]:
    cnto[1] = cnto[0]
    cnto[0] = dico[k]
    o = k
  elif dico[k] > cnto[1]:
    cnto[1] = dico[k]
    
for k in dice:
  if dice[k] > cnte[0]:
    cnte[1] = cnte[0]
    cnte[0] = dice[k]
    e = k
  elif dice[k] > cnte[1]:
    cnte[1] = dice[k]
  
if o == e:
  print(N-max(cnto[0]+cnte[1],cnte[0]+cnto[1]))
else:  
  print(N-cnto[0]-cnte[0])

Solution (Python):
from collections import Counter


def solve(V):
    n = len(V)
    ac = Counter(V[::2]).most_common(2)
    bc = Counter(V[1::2]).most_common(2)

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


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))

Solution (Python):
from collections import Counter

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

d1 = Counter(l[::2]).most_common()
d2 = Counter(l[1::2]).most_common()
d1.append([0,0])
d2.append([0,0])

if d1[0][0] != d2[0][0]:
    print(n//2-d1[0][1] + n//2-d2[0][1])
else:
    ans1 = n//2 - d1[0][1] + n//2 - d2[1][1]
    ans2 = n//2 - d1[1][1] + n//2 - d2[0][1]
    print(min(ans1, ans2))

Solution (Python):
n=int(input())
lst=list(map(int,input().split()))
if len(set(lst))==1:
    print(n//2)
    exit()
a=sorted(lst[::2])
b=sorted(lst[1::2])

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

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):
from collections import Counter
n = int(input())
lst = list(map(int, input().split()))
counter = Counter(lst)

if len(counter.values()) == 1:
    print(n // 2)
    exit()

num_cnt = list(counter.items())
num_cnt.sort(key=lambda x: x[1], reverse=True)
max_num = num_cnt[0][0]
second_max_num = num_cnt[1][0]
tmp_ans = 0
for i in range(n):
    if i % 2 == 0 and max_num == lst[i] or \
            i % 2 == 1 and second_max_num == lst[i]:
        continue
    tmp_ans += 1
ans = 0
for i in range(n):
    if i % 2 == 1 and max_num == lst[i] or \
            i % 2 == 0 and second_max_num == lst[i]:
        continue
    ans += 1
print(min(ans, tmp_ans))

Solution (Python):
import sys
from collections import defaultdict
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
tmp = list(map(int, input().split()))

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


odd = sorted(odd.items(), key=lambda x: -x[1])
even = sorted(even.items(), key=lambda x: -x[1])

o1 = odd[0]
e1 = even[0]

if len(odd) != 1:
    o2 = odd[1]
else:
    o2 = (0, 0)
if len(even) != 1:
    e2 = even[1]
else:
    e2 = (0, 0)


if o1[0] != e1[0]:
    print(n - (o1[1] + e1[1]))

else:
    ans = min((n - (o2[1] + e1[1])), (n - (o1[1] + e2[1])))
    print(ans)

Solution (Python):
import collections

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

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

count_even = collections.Counter(even).most_common()
count_sort_even = sorted(count_even, key = lambda x: x[1])[::-1]

count_odd = collections.Counter(odd).most_common()
count_sort_odd = sorted(count_odd, key = lambda x: x[1])[::-1]

if count_sort_even[0][0] != count_sort_odd[0][0]:  ans = N - count_sort_even[0][1] - count_sort_odd[0][1]
    
else:
    if len(count_sort_even) == 1:
        if len(count_sort_odd) == 1:  ans = N // 2
        else:  ans = N - count_sort_even[0][1] - count_sort_odd[1][1]
    elif len(count_sort_odd) == 1:  ans = N - count_sort_even[1][1] - count_sort_odd[0][1]
    else:
        ans1 = N - count_sort_even[1][1] - count_sort_odd[0][1]
        ans2 = N - count_sort_even[0][1] - count_sort_odd[1][1] 
        ans = min(ans1, ans2)    
    
print(ans)

Solution (Python):
from collections import Counter
def main():
    N = int(input())
    V = list(map(int, input().split()))
    c0 = Counter(V[::2])
    c1 = Counter(V[1::2])
    cc0 = sorted([(0, 0)] + [(v, k) for k, v in c0.items()], reverse=True)
    cc1 = sorted([(0, 0)] + [(v, k) for k, v in c1.items()], reverse=True)
    m0, v0 = cc0[0]
    m1, v1 = cc1[0]
    if v0 != v1:
        return N - m0 - m1
    return min(N - m0 - cc1[1][0], N - m1 - cc0[1][0])
print(main())

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
odd = Counter(v[0::2])
even = Counter(v[1::2])
odd["$"] = 0
even["
ans = 0
if odd.most_common()[0][0] == even.most_common()[0][0]:
    if odd.most_common()[1][1] > even.most_common()[1][1]:
        ans = n - odd.most_common()[1][1] - even.most_common()[0][1]
    else:
        ans = n - odd.most_common()[0][1] - even.most_common()[1][1]
else:
    ans = n - odd.most_common()[0][1] - even.most_common()[0][1]
print(ans)

Solution (Python):
import sys
from collections import Counter

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() 
ni = lambda: int(readline().rstrip()) 
nm = lambda: map(int, readline().split()) 
nl = lambda: list(map(int, readline().split())) 

n = ni()
v = nl()
odd = Counter(v[0::2])
even = Counter(v[1::2])
odd["$"] = 0
even["
ans = 0
if odd.most_common()[0][0] == even.most_common()[0][0]:
    if odd.most_common()[1][1] > even.most_common()[1][1]:
        ans = n - odd.most_common()[1][1] - even.most_common()[0][1]
    else:
        ans = n - odd.most_common()[0][1] - even.most_common()[1][1]
else:
    ans = n - odd.most_common()[0][1] - even.most_common()[0][1]
"""if len(odd) == 1:
    pass
else:
    for v in odd.values():
        max_odd = max(max_odd, v)
    ans += len(odd) - max_odd

if len(even) == 1:
    pass
else:
    for v in even.values():
        max_even = max(max_even, v)
    ans += len(even) - max_even"""

print(ans)

Solution (Python):
import collections

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

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

even_c = collections.Counter(even)
odd_c = collections.Counter(odd)

even_max1_num = 0
even_max1_cnt = 0
even_max2_num = 0
even_max2_cnt = 0
for k, v in even_c.items():
    if v > even_max1_cnt:
        even_max2_cnt = even_max1_cnt
        even_max2_num = even_max1_num
        even_max1_cnt = v
        even_max1_num = k
    elif v > even_max2_cnt:
        even_max2_cnt = v
        even_max2_num = k

odd_max1_num = 0
odd_max1_cnt = 0
odd_max2_num = 0
odd_max2_cnt = 0
for k, v in odd_c.items():
    if v > odd_max1_cnt:
        odd_max2_cnt = odd_max1_cnt
        odd_max2_num = odd_max1_num
        odd_max1_cnt = v
        odd_max1_num = k
    elif v > odd_max2_cnt:
        odd_max2_cnt = v
        odd_max2_num = k

ans = 0
if even_max1_num == odd_max1_num:
    if even_max1_cnt == odd_max1_cnt:
        if even_max2_cnt > odd_max2_cnt:
            ans = N-(even_max2_cnt+odd_max1_cnt)
        else:
            ans = N-(even_max1_cnt+odd_max2_cnt)
    elif even_max1_cnt > odd_max1_cnt:
        ans = N-(even_max1_cnt+odd_max2_cnt)
    else:
        ans = N-(even_max2_cnt+odd_max1_cnt)
else:
    ans = N-(even_max1_cnt+odd_max1_cnt)
print(ans)

Solution (Python):
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
v = LIST()

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

if e.most_common()[0][0] != o.most_common()[0][0]:
    ans = n - e.most_common()[0][1] - o.most_common()[0][1]
else:
    try:
        tmp0 = n - e.most_common()[0][1] - o.most_common()[1][1]
    except:
        tmp0 = n - e.most_common()[0][1]
    try:
        tmp1 = n - e.most_common()[1][1] - o.most_common()[0][1]
    except:
        tmp1 = n - o.most_common()[0][1]
    ans = min( tmp0, tmp1 )

print( ans )

Solution (Python):
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
E = []
O = []
for i,v in enumerate(V):
    if i%2==0:
        O.append(v)
    else:
        E.append(v)

cO = Counter(O).most_common(); cO.append((-1,0))
cE = Counter(E).most_common(); cE.append((-1,0))
if cO[0][0]==cE[0][0]: 
    ans = min(n-cO[0][1]-cE[1][1], n-cO[1][1]-cE[0][1])
else:
    ans = n-cO[0][1]-cE[0][1]
print(ans)

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
from collections import Counter
cnt = Counter(v)
ocnt = sorted(Counter(v[::2]).items(), key=lambda x: x[1], reverse=True)
ecnt = sorted(Counter(v[1::2]).items(), key=lambda x: x[1], reverse=True)
if len(cnt) == 1:
    print(n//2)
elif len(ocnt) == 1 and len(ecnt) == 1:
    print(0)
else:
    onum = ocnt[0][1]
    enum = ecnt[0][1]
    if ocnt[0][0] != ecnt[0][0]:
        print(n - onum - enum)
    else:
        if len(ocnt) > 1 and len(ecnt) > 1 and ocnt[1][0] != ecnt[1][0]:
            print(min(n - onum - ecnt[1][1], n - enum - ocnt[1][1], n - ecnt[1][1] - ocnt[1][1]))
        else:
            print(min(n - onum - ecnt[1][1], n - enum - ocnt[1][1]))

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

c1 = collections.Counter(a1)
c2 = collections.Counter(a2)
if c1.most_common()[0][0]!=c2.most_common()[0][0]:
    print(len(a1) - c1.most_common()[0][1] + len(a2) - c2.most_common()[0][1])
else:
    c12bannte = c1.most_common()[1][1] if len(c1)>1 else 0
    c22bannte = c2.most_common()[1][1] if len(c2)>1 else 0
    ans = min(len(a1) - c1.most_common()[0][1] + len(a2) - c22bannte,len(a1) - c12bannte + len(a2) - c2.most_common()[0][1])
    print(ans)

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

from collections import Counter
V_1=V[::2]
V_2=V[1::2]

V_1_counter=Counter(V_1).most_common()
V_2_counter=Counter(V_2).most_common()


V_1_max_1 = V_1_counter[0]
V_1_max_2=(0,0)
if len(V_1_counter)>1:
    V_1_max_2 = V_1_counter[1]
    
V_2_max_1=V_2_counter[0]
V_2_max_2=(0,0)
if len(V_2_counter)>1:
    V_2_max_2 = V_2_counter[1]
    
if V_1_max_1[0] != V_2_max_1[0]:
    ans = N-V_1_max_1[1]-V_2_max_1[1]
    
else:
    ans=N-max(V_1_max_1[1]+V_2_max_2[1],V_1_max_2[1]+V_2_max_1[1])
    
print(ans)

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

from collections import Counter
V_1=V[::2]
V_2=V[1::2]

V_1_counter=Counter(V_1).most_common()
V_2_counter=Counter(V_2).most_common()
c1 = V_1_counter
c2 = V_2_counter

if c1[0][0]!=c2[0][0]:
    print(n-c1[0][1]-c2[0][1])
if c1[0][0]==c2[0][0]:
    if len(c1)==len(c2)==1:
        print(n//2)
    if len(c1)==1 and len(c2)!=1:
        print(n-c1[0][1]-c2[1][1])
    if len(c2)==1 and len(c1)!=1:
        print(n-c1[1][1]-c2[0][1])    
    if len(c1)>1 and len(c2)>1:    
        print(n-max(c1[1][1]+c2[0][1],c1[0][1]+c2[1][1]))

Solution (Python):
from collections import Counter
n,*v = map(int,open(0).read().split())
v1 = Counter(v[::2])
v2 = Counter(v[1::2])
v1 = sorted([(i,v1[i]) for i in v1.keys()],key =lambda x:x[1],reverse=True)
v2 = sorted([(i,v2[i]) for i in v2.keys()],key =lambda x:x[1],reverse=True)
if v1[0][0] != v2[0][0]:
  print(n-v1[0][1]-v2[0][1])
else:
  e1 = n-v2[0][1] if len(v1) == 1 else n-v1[1][1]-v2[0][1]
  e2 = n-v1[0][1] if len(v2) == 1 else n-v1[0][1]-v2[1][1]
  print(min(e1,e2))

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

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

odd_mx=0
odd_sec=0
even_mx=0
even_sec=0
for i in range(len(odd)):
    if odd[i]>odd_mx:
        odd_sec=odd_mx
        odd_mx=odd[i]
        odd_idx=i
    elif odd[i]>odd_sec:
        odd_sec=odd[i]
for i in range(len(even)):
    if even[i]>even_mx:
        even_sec=even_mx
        even_mx=even[i]
        even_idx=i
    elif even[i]>even_sec:
        even_sec=even[i]

if odd_idx!=even_idx:
    ans=n-(odd_mx+even_mx)
elif odd_mx==even_mx and odd_sec==0 and even_sec==0:
    ans=n//2
else:
    a=max(even_mx+odd_sec,odd_mx+even_sec)
    ans=n-a

print(ans)

Solution (Python):
import sys
import collections

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    n = ini()
    v = inl()
    ev = collections.Counter()
    od = collections.Counter()
    for i in range(n):
        if i % 2 == 0:
            ev[v[i]] += 1
        else:
            od[v[i]] += 1
    ex = ev.most_common(2)
    ox = od.most_common(2)
    if ex[0][0] != ox[0][0]:
        ans = n - ex[0][1] - ox[0][1]
    elif len(ex) == 1 and len(ox) == 1:
        ans = n - ex[0][1]
    elif len(ex) == 1:
        ans = n - ex[0][1] - ox[1][1]
    elif len(ox) == 1:
        ans = n - ex[1][1] - ox[0][1]
    else:
        ans = min(n - ex[0][1] - ox[1][1], n - ex[1][1] - ox[0][1])
    return ans


print(solve())

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=v[0:n:2]
v2=v[1:n:2]
cc1=Counter(v1)
c1=cc1.most_common()
cc2=Counter(v2)
c2=cc2.most_common()
if c1[0][0]!=c2[0][0]:
    print(n-c1[0][1]-c2[0][1])
if c1[0][0]==c2[0][0]:
    if len(c1)==len(c2)==1:
        print(n//2)
    if len(c1)==1 and len(c2)!=1:
        print(n-c1[0][1]-c2[1][1])
    if len(c2)==1 and len(c1)!=1:
        print(n-c1[1][1]-c2[0][1])    
    if len(c1)>1 and len(c2)>1:    
        print(n-max(c1[1][1]+c2[0][1],c1[0][1]+c2[1][1]))

Solution (Python):
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==0:
        d1[v[i]]+=1
    else:
        d2[v[i]]+=1
if d1.index(max(d1))==d2.index(max(d2)):
    d1n=sorted(d1,reverse=True)
    d2n=sorted(d2,reverse=True)
    if d1n[1]>d2n[1]:
        print(n-d1n[1]-d2n[0])
    else:
        print(n-d1n[0]-d2n[1])
else:
    print(n-max(d1)-max(d2))

Solution (Python):
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
l_o = l[::2]
l_g = l[1::2]
a = list(Counter(l_o).most_common())+[(0,0)]
c = list(Counter(l_g).most_common())+[(0,0)]

if a[0][0]==c[0][0]:
  s = a[0][1]+c[1][1]
  t = a[1][1]+c[0][1]
  x = max(s,t)
  print(n-x)
  
  
else:
  print(n-a[0][1]-c[0][1])

Solution (Python):


from collections import Counter

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


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

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




if c_even[0][0] == c_odd[0][0]:
    if len(c_even) == 1:
        c_odd = c_odd[1:]
    elif len(c_odd) == 1:
        c_even = c_even[1:]
    else:
        if c_even[1][1] >= c_odd[1][1]:
            c_even = c_even[1:]
        else:
            c_odd = c_odd[1:]

if len(c_even) == 0:
    c_even.append((-1, 0))
if len(c_odd) == 0:
    c_odd.append((-1, 0))

diff_even = n//2-c_even[0][1]
diff_odd = n//2-c_odd[0][1]

print(diff_even+diff_odd)

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

odd = {}
even = {}
for d, i in enumerate(v):
    if d % 2 == 1:
        if i in even:
            even[i] += 1
        else:
            even[i] = 1
    else:
        if i in odd:
            odd[i] += 1
        else:
            odd[i] = 1
even_sorted = sorted(even.items(), key=lambda x:x[1])
odd_sorted = sorted(odd.items(), key=lambda x:x[1])
if even_sorted[-1][0] == odd_sorted[-1][0]:
    try:
        second_o = odd_sorted[-2][1]
    except:
        second_o = 0
    try:
        second_e = even_sorted[-2][1]
    except:
        second_e = 0
    print(min(n- even_sorted[-1][1] -second_o, n- second_e -odd_sorted[-1][1] ))
else:
    print(n - max(even.values()) - max(odd.values()))

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
d1={}
d2={}
l1=[]
l2=[]
for i in range(n):
    num=v[i]
    if i%2==0:
        try:
            d1[num]+=1
        except:
            d1[num]=1
    else:
        try:
            d2[num]+=1
        except:
            d2[num]=1
for i in d1:
    l1.append([d1[i],i])
for i in d2:
    l2.append([d2[i],i])
l1.sort(reverse=True)
l2.sort(reverse=True)
ans=n
if l1[0][1]!=l2[0][1]:
    ans-=(l1[0][0]+l2[0][0])
elif len(l1)==1 and len(l2)==1:
    ans//=2
elif len(l1)==1:
    ans-=l2[1][0]
elif len(l2)==1:
    ans-=l1[1][0]
else:
    a=ans-l1[0][0]-l2[1][0]
    b=ans-l1[1][0]-l2[0][0]
    ans=min(a,b)
print(ans)

Solution (Python):
import collections

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

v_odd = []
v_even = []

for i, v in enumerate(v):
    if i % 2:
        v_even.append(v)
    else:
        v_odd.append(v)


v_odd_c = collections.Counter(v_odd)
v_odd_c = sorted(v_odd_c.items(), key=lambda x: x[1], reverse=True)
v_even_c = collections.Counter(v_even)
v_even_c = sorted(v_even_c.items(), key=lambda x: x[1], reverse=True)



v_odd_c.append([0, 0])
v_even_c.append([0, 0])

if n != 2:
    o1 = v_odd_c[0]
    o2 = v_odd_c[1]
    e1 = v_even_c[0]
    e2 = v_even_c[1]

    
    if o1[0] != e1[0]:
        ans = n - o1[1] - e1[1]
    
    elif o1[0] == e1[0]:
        
        temp1 = n - o1[1] - e2[1]
        
        temp2 = n - o2[1] - e1[1]
        ans = min(temp1, temp2)

print(ans)

Solution (Python):
import collections

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

v_odd = []
v_even = []

for i, v in enumerate(v):
    if i % 2:
        v_even.append(v)
    else:
        v_odd.append(v)


v_odd_c = collections.Counter(v_odd)
v_odd_c = sorted(v_odd_c.items(), key=lambda x: x[1], reverse=True)
v_even_c = collections.Counter(v_even)
v_even_c = sorted(v_even_c.items(), key=lambda x: x[1], reverse=True)



v_odd_c.append([0, 0])
v_even_c.append([0, 0])




if n != 2:
    o1 = v_odd_c[0]
    o2 = v_odd_c[1]
    e1 = v_even_c[0]
    e2 = v_even_c[1]

    
    if o1[0] != e1[0]:
        ans = n - o1[1] - e1[1]
    
    elif o1[0] == e1[0]:
        
        temp1 = n - o1[1] - e2[1]
        
        temp2 = n - o2[1] - e1[1]
        ans = min(temp1, temp2)

elif n == 2:
    if v_odd_c[0][1] != v_even_c[0][1]:
        ans = 0
    else:
        ans = 1

print(ans)

Solution (Python):
from collections import Counter

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

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

cnt_even = Counter(even).most_common()
cnt_odd = Counter(odd).most_common()

even_num = cnt_even[0][0]
odd_num = cnt_odd[0][0]

if even_num == odd_num:
    if len(cnt_even) == 1 and len(cnt_odd) == 1:
        ans = min(len(even),len(odd))
    elif len(cnt_even) == 1:
        ans = (len(even)-cnt_even[0][1]) + (len(odd)-cnt_odd[1][1])
    elif len(cnt_odd) == 1:
        ans = (len(even)-cnt_even[1][1]) + (len(odd)-cnt_odd[0][1])
    else:
        ans = min((len(even)-cnt_even[0][1]) + (len(odd)-cnt_odd[1][1]), (len(even)-cnt_even[1][1]) + (len(odd)-cnt_odd[0][1]))
else:
    ans_e = len(even) - cnt_even[0][1]
    ans_o = len(odd) - cnt_odd[0][1]
    ans = ans_e + ans_o

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
v = tuple(map(int, input().split()))
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
if len(set(v)) == 1:
    print(n // 2)
else:
    c1m = c1.most_common(2)
    c2m = c2.most_common(2)
    if c1m[0][0] == c2m[0][0]:
        print(min(n - c1m[0][1] - c2m[1][1], n - c1m[1][1] - c2m[0][1]))
    else:
        print(n - c1m[0][1] - c2m[0][1])

Solution (Python):
import collections
N =int(input())
V =list(map(int,input().split()))
ev_col = collections.Counter(V[::2]).most_common()
od_col = collections.Counter(V[1::2]).most_common()
 
if ev_col[0][0] != od_col[0][0]:
    ans = N - od_col[0][1] - ev_col[0][1]
else:
    if len(ev_col) >= 2 and len(od_col)  >= 2:
        if ev_col[1][1] >= od_col[1][1]:
            ans = N - ev_col[1][1] - od_col[0][1]
        else:
            ans = N - od_col[1][1] - ev_col[0][1]
    else:
        ans = N - ev_col[0][1]
print(ans)

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
from collections import defaultdict
a=defaultdict(int)
b=defaultdict(int)
for i in range(n):
  if i%2==0:
    a[v[i]]+=1
  else:
    b[v[i]]+=1

am=max(a.values())
bm=max(b.values())
if max(a,key=a.get) !=max(b,key=b.get):
  print(n-am-bm)
else:
  b[max(b, key=b.get)]=0
  a[max(a, key=a.get)]=0
  a2=n-am-max(b.values())
  b2=n-bm-max(a.values())
         
  print(min(a2,b2))

Solution (Python):
from collections import Counter
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

odd_c = Counter(v[0::2])
even_c = Counter(v[1::2])

odd_c = odd_c.most_common()
if len(odd_c) == 1:
    odd_c.append((0, 0))
even_c = even_c.most_common()
if len(even_c) == 1:
    even_c.append((0, 0))

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

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

dic_odd = {}
dic_even = {}

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


odd_lst = [(k, v) for k, v in dic_odd.items()]
even_lst = [(k, v) for k, v in dic_even.items()]
odd_lst.sort(key=lambda x: x[1], reverse=True)
even_lst.sort(key=lambda x: x[1], reverse=True)

if (len(odd_lst) == len(even_lst) == 1) and (odd_lst[0][0] == even_lst[0][0]):
    print(int(N / 2))
    exit()

max_ = 0
for a, b in odd_lst:
    for x, y in even_lst:
        if a == x:
            continue
        else:
            max_ = max(b + y, max_)
            break


print(N - max_)

Solution (Python):
import collections
n = int(input())
v = list(map(int,input().split()))
v_odd = []
v_even = []
for i,v in enumerate(v):
    if i % 2:
        v_even.append(v)
    else:
        v_odd.append(v)
odd_n = len(v_odd)
even_n = len(v_even)
v_odd = collections.Counter(v_odd)
v_odd = sorted(v_odd.items(), key=lambda x:x[1],reverse=True)
v_even = collections.Counter(v_even)
v_even = sorted(v_even.items(), key=lambda x:x[1],reverse=True)

if v_odd[0] == v_even[0] and 2 <= len(v_odd) and 2 <= len(v_even):
    if v_odd[1][1] < v_even[1][1]:
        v_even.pop(0)
    elif v_odd[1][1] > v_even[1][1]:
        v_odd.pop(0)

num = v_odd[0][0]

ans = odd_n-v_odd[0][1]
st = 0
for i,v in v_even:
    if num == i:
        continue
    else:
        st = v
        break
print(ans+(even_n-st))

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

def main(n,v):

    hist=[0]*(10**5+1)
    maxhist=0
    maxvalue=0
    for i in range(n):
        hist[v[i]]+=1
        if (maxhist<hist[v[i]]):
            maxhist=hist[v[i]]
            maxvalue=v[i]
    print('maxvalue: {}, maxhist: {}'.format(maxvalue, maxhist))

    secondhist=0
    for i in range(1,10**5+1):
        if i == maxvalue:
            continue
        secondhist=max(secondhist,hist[i])
    print('secondhist: {}'.format(secondhist))

    nsame=n//2
    nchange=0
    if maxhist>nsame:
        nchange+=maxhist-nsame
    elif maxhist<nsame:
        nchange+=nsame-maxhist
    nchange+=nsame-secondhist
    return nchange

def main2(n,v):
    eList=[]
    oList=[]
    for i in range(n):
        if i%2==0:
            eList.append(v[i])
        else:
            oList.append(v[i])

    
    

    ehist=[0]*(10**5+1)
    for i in eList:
        ehist[i]+=1
    emaxh=0
    emaxv=0
    for i in range(1,10**5+1):
        if emaxh<ehist[i]:
            emaxh=ehist[i]
            emaxv=i
    esech=0
    esecv=0
    for i in range(1,10**5+1):
        if i==emaxv:
            continue
        if esech<ehist[i]:
            esech=ehist[i]
            esecv=i
    
    ohist=[0]*(10**5+1)
    for i in oList:
        ohist[i]+=1
    omaxh=0
    omaxv=0
    for i in range(1,10**5+1):
        if omaxh<ohist[i]:
            omaxh=ohist[i]
            omaxv=i
    osech=0
    osecv=0
    for i in range(1,10**5+1):
        if i == omaxv:
            continue
        if osech<ohist[i]:
            osech=ohist[i]
            osecv=i

    if omaxv==emaxv:
        if omaxh==emaxh:
            if osech>esech:
                omaxv=osecv
            else:
                emaxv=esecv
        elif omaxh>emaxh:
            emaxv=esecv
        else:
            omaxv=osecv
    
    

    nchange=0
    for i in range(n//2):
        if eList[i]!=emaxv:
            nchange+=1
        if oList[i]!=omaxv:
            nchange+=1
    return nchange


if __name__=='__main__':
    n,v=readinput()
    ans=main2(n,v)
    print(ans)