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
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
v = LI()
s,t = [],[]
for i in range(n):
    if i % 2:
        t.append(v[i])
    else:
        s.append(v[i])
s = list(Counter(s).items())
s.sort(key = itemgetter(1),reverse = True)
t = list(Counter(t).items())
t.sort(key = itemgetter(1),reverse = True)
m = min(len(s),len(t))
for i in range(m):
    a,b = s[i]
    c,d = t[i]
    if a != c:
        print((n//2 - b)+(n//2 - d))
        quit()
    elif a == c:
        if i + 1 < len(s) - 1:
            tmp1 = s[i+1][1]
        else:
            tmp1 = 0
        if i + 1 < len(t) - 1:
            tmp2 = t[i+1][1]
        else:
            tmp2 = 0
        print(min(((n//2 - b) + (n//2 - tmp2),((n//2 - d) + (n//2 - tmp1)))))
        quit()

Solution (Python):
import collections
n = int(input())
v = list(map(int,input().split()))
e = v[0::2]
o = v[1::2]
e_com = collections.Counter(e).most_common(2)
o_com = collections.Counter(o).most_common(2)
if e_com[0][0] != o_com[0][0]:
  print(n - e_com[0][1] - o_com[0][1])
elif e_com[0][0] == o_com[0][0]:
  if len(e_com) > 1 and len(o_com)>1:
    print(min(n - e_com[1][1] - o_com[0][1], n - e_com[0][1] - o_com[1][1]))
  elif len(e_com) > 1 and len(o_com) == 1:
    print(n - e_com[1][1])
  elif len(e_com) == 1 and len(o_com) > 1:
    print(n - o_com[1][1])
  else:
    print(n//2)

Solution (Python):
from collections import Counter
from statistics import mode


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

A = V[::2]
B = V[1::2]
countA = sorted(list(Counter(A).items()), key=lambda x: -x[1])
countB = sorted(list(Counter(B).items()), key=lambda x: -x[1])
if len(set(V)) == 1:
    print(n//2)
elif countA[0][0] != countB[0][0]:
    print(len(A)-countA[0][1] + len(B)-countB[0][1])
else:
    print(min(
        len(A)-countA[0][1] + len(B)-countB[1][1],
        len(A)-countA[1][1] + len(B)-countB[0][1]
        ))

Solution (Python):
from collections import Counter

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

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

cv1 = Counter(v1).most_common(2)
cv2 = Counter(v2).most_common(2)

if cv1[0][0] != cv2[0][0]:
    print(n - cv1[0][1] - cv2[0][1])
else:
    p1 = cv1[0][1] + cv2[1][1] if len(cv2) >= 2 else n - cv1[0][1]
    p2 = cv2[0][1] + cv1[1][1] if len(cv1) >= 2 else n - cv2[0][1]
    print(n - max(p1, p2))

Solution (Python):
from collections import Counter

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

if even[0][0] != odd[0][0]:
    print(n - even[0][1] - odd[0][1])
else:
    if even[0][1] == odd[0][1] == n // 2:
        print(even[0][1])
    else:
        print(min(n - even[1][1] - odd[0][1], n - even[0][1] - odd[1][1]))

Solution (Python):
import collections
n = int(input())
V = [int(i) for i in input().split()]
E,O = [],[]
E_cnt2,O_cnt2 = 0,0
for i in range(n):
    if i%2:
        E.append(V[i])
    else:
        O.append(V[i])
e = collections.Counter(E)
tmp = e.most_common()
E_mode,E_cnt = tmp[0][0],tmp[0][1]
if len(tmp)>=2:
    E_cnt2 = tmp[1][1]

o = collections.Counter(O)
tmp = o.most_common()
O_mode,O_cnt = tmp[0][0],tmp[0][1]
if len(tmp)>=2:
    O_cnt2 = tmp[1][1]
if E_mode!=O_mode:
    print(len(E)-E_cnt+len(O)-O_cnt)
else:
    print(min((len(E)-E_cnt+len(O)-O_cnt2),len(E)-E_cnt2+len(O)-O_cnt))

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

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

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

vvv_odd = vvv[::2]
vvv_even = vvv[1::2]

dp_odd = [0] * max(vvv_odd)
dp_even = [0] * max(vvv_even)

for v_odd, v_even in zip(vvv_odd, vvv_even):
    dp_odd[v_odd - 1] += 1
    dp_even[v_even - 1] += 1

max_appear_odd = max(dp_odd)
max_appear_even = max(dp_even)

max_odd_val = dp_odd.index(max_appear_odd) + 1
max_even_val = dp_even.index(max_appear_even) + 1

if max_odd_val == max_even_val:
    next_appear_odd = sorted(dp_odd, reverse=True)[1]
    next_appear_even = sorted(dp_even, reverse=True)[1]
    if next_appear_odd > next_appear_even:
        max_appear_odd = next_appear_odd
    else:
        max_appear_even = next_appear_even

n_replace = N // 2 - max_appear_odd
n_replace += N // 2 - max_appear_even

print(n_replace)

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

v1=v[::2]
v2=v[1::2]
dic1=Counter(v1)
dic2=Counter(v2)
dic1=sorted(dic1.items(),key=lambda x:x[1],reverse=True)
dic2=sorted(dic2.items(),key=lambda x:x[1],reverse=True)

if n==2:
    if v[0]==v[1]:
        ans=1
    else:
        ans=0

elif dic1[0][0]!=dic2[0][0]:
    ans=len(v1)-dic1[0][1]
    ans+=(len(v2)-dic2[0][1])

elif dic1[0][0]==dic2[0][0] and len(v1)==dic1[0][1] and len(v2)==dic2[0][1]:
    ans=len(v2)

elif dic1[0][0]==dic2[0][0] and len(v1)==dic1[0][1] and len(v2)!=dic2[0][1]:
    ans=len(v2)-dic2[1][1]
    
elif dic1[0][0]==dic2[0][0] and len(v1)!=dic1[0][1] and len(v2)==dic2[0][1]:
    ans=len(v1)-dic1[1][1]
    
elif dic1[0][0]==dic2[0][0]:
    ans = min(len(v1)-dic1[0][1]+len(v2)-dic2[1][1],len(v1)-dic1[1][1]+len(v2)-dic2[0][1])
print(ans)

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

even = {}
odd = {}

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

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

ans = 0
if even_sorted[0][0] != odd_sorted[0][0]:
    ans += n - even_sorted[0][1] - odd_sorted[0][1]
else:
    if len(even_sorted) == 1 or len(odd_sorted) == 1:
        even_sorted.append((-1, 0))
        odd_sorted.append((-1, 0))
    x = n - even_sorted[0][1] - odd_sorted[1][1]
    y = n - even_sorted[1][1] - odd_sorted[0][1]
    ans += min(x, y)

print(ans)

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

dl = {}
du = {}

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

if max(dl, key=dl.get) != max(du, key=du.get):
  ans = n - max(dl.values()) - max(du.values())
else:
  vsl = list(dl.values())
  vsl.sort(reverse=True)
  vsu = list(du.values())
  vsu.sort(reverse=True)
  if len(vsl) == 1 or len(vsu) == 1:
    ans = n//2
  else:
    ans = min(n-vsu[0]-vsl[1], n-vsl[0]-vsu[1])
  
print(ans)

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

dl = {}
du = {}

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

if max(dl, key=dl.get) != max(du, key=du.get):
  ans = n - max(dl.values()) - max(du.values())
else:
  vsl = list(dl.values())
  vsl.sort(reverse=True)
  vsu = list(du.values())
  vsu.sort(reverse=True)
  if len(vsl) == 1 or len(vsu) == 1:
    ans = n//2
  else:
    ans = min(n-vsu[0]-vsl[1], n-vsl[0]-vsu[1])
  
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
v_even = []
v_odd = []

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

even = Counter(v_even).most_common(2)+[(0,0)]
odd = Counter(v_odd).most_common(2)+[(0,0)]

if even[0][0] != odd[0][0]:
    ans = n - even[0][1] - odd[0][1]
else:
    temp1 = even[0][1] + odd[1][1]
    temp2 = even[1][1] + odd[0][1]
    temp = max(temp1, temp2)
    ans = n - temp

print(ans)

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

from collections import defaultdict

d_even = defaultdict(int)
d_odd = defaultdict(int)

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

d_even = sorted(d_even.items(), key=lambda x: x[1], reverse=True)
d_odd = sorted(d_odd.items(), key=lambda x: x[1], reverse=True)

if d_even[0][0] == d_odd[0][0]:
    d_even.append((0, 0))
    d_odd.append((0, 0))
    tmp = max(d_even[0][1] + d_odd[1][1], d_even[1][1] + d_odd[0][1])
    ans = n - tmp
else:
    ans = n - d_even[0][1] - d_odd[0][1]

print(ans)

Solution (Python):
from collections import Counter

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

A = Counter(V[0::2]).most_common(2)
B = Counter(V[1::2]).most_common(2)

A.append((0, 0))
B.append((0, 0))

a_value, a_count = A[0]
a2_value, a2_count = A[1]
b_value, b_count = B[0]
b2_value, b2_count = B[1]

if a_value != b_value:
    ans = n - a_count - b_count
else:
    ans = min(n-a_count-b2_count, n-a2_count-b_count)

print(ans)

Solution (Python):
import collections

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

counter_e = collections.Counter()
counter_o = collections.Counter()
for i, v in enumerate(vs):
    if i % 2 == 0:
        counter_e[v] += 1
    else:
        counter_o[v] += 1
key_e, max_e = sorted(counter_e.items(), key=lambda x: (x[1], -x[0]))[-1]
key_o, max_o = sorted(counter_o.items(), key=lambda x: (x[1], x[0]))[-1]
if key_e != key_o:
    print(n - max_e - max_o)
elif len(counter_e.keys()) == 1 and len(counter_o.keys()) == 1:
    print(n // 2)
elif len(counter_e.keys()) == 1:
    key_o2, max_o2 = sorted(counter_o.items(), key=lambda x: (x[1], x[0]))[-2]
    print(n - max_e - max_o2)
elif len(counter_e.keys()) == 2 and len(counter_o.keys()) == 1:
    key_e2, max_e2 = sorted(counter_e.items(), key=lambda x: (x[1], -x[0]))[-2]
    print(n - max_e2 - max_o)
else:
    key_e2, max_e2 = sorted(counter_e.items(), key=lambda x: (x[1], -x[0]))[-2]
    key_o2, max_o2 = sorted(counter_o.items(), key=lambda x: (x[1], x[0]))[-2]
    print(min(n - max_e - max_o2, n - max_e2 - max_o))

Solution (Python):
import collections

n = int(input())
v = list(map(int,input().split()))
v1 = v[::2]
v2 = v[1::2]
v1 = collections.Counter(v1)
v2 = collections.Counter(v2)
ans = 0
if v1.most_common()[0][0] == v2.most_common()[0][0]:
    if v1.most_common()[0][1] < v2.most_common()[0][1]:
        ans += n//2 - v2.most_common()[0][1]
        ans += n//2 - v1.most_common()[1][1]
        print(ans)
    elif v1.most_common()[0][1] > v2.most_common()[0][1]:
        ans += n//2 - v1.most_common()[0][1]
        ans += n//2 - v2.most_common()[0][1]
        print(ans)
    else:
        if v1.most_common()[0][1] == n//2:
            print(n//2)
        else:
            if v1.most_common()[1][1] > v2.most_common()[1][1]:
                ans += n//2 - v2.most_common()[0][1]
                ans += n//2 - v1.most_common()[1][1]
                print(ans)
            else:
                ans += n//2 - v1.most_common()[0][1]
                ans += n//2 - v2.most_common()[1][1]
                print(ans)
else:
    ans += n//2 - v1.most_common()[0][1]
    ans += n//2 - v2.most_common()[0][1]
    print(ans)

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_odd += [V[i]]
    else:
        V_even += [V[i]]
V_odd = list(Counter(V_odd).most_common()) + [(-1,0)]
V_even = list(Counter(V_even).most_common()) + [(-2,0)]
if V_odd[0][0] != V_even[0][0]:
    print(len(V)-V_odd[0][1]-V_even[0][1])
elif V_odd[1][1] >= V_even[1][1]:
    print(len(V)-V_odd[1][1]-V_even[0][1])
else:
    print(len(V)-V_odd[0][1]-V_even[1][1])

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

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

import heapq

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

A_even=[]
A_odd=[]
A_evenq = []
A_oddq = []
heapq.heapify(A_evenq)
heapq.heapify(A_oddq)

for i in range(N):
    if i%2==0:
        A_even.append(A[i])
    else:
        A_odd.append(A[i])

A_even.sort()
A_odd.sort()
i=0
max_even=0
i_even=0
while i < N//2:
    j = i
    count=0
    while j < N//2:
        if A_even[i] == A_even[j]:
            count+=1
            j+=1
        else:
            heapq.heappush(A_evenq,-count)
            if max_even < count:
                max_even=count
                i_even = A_even[i]
            break
    i=j
heapq.heappush(A_evenq,-count)
if max_even < count:
    max_even=count
    i_even = A_even[i-1]

i=0
max_odd=0
i_odd=0
while i < N//2:
    j = i
    count=0
    while j < N//2:
        if A_odd[i] == A_odd[j]:
            count+=1
            j+=1
        else:
            heapq.heappush(A_oddq,-count)
            if max_odd < count:
                max_odd=count
                i_odd = A_odd[i]
            break
    i=j
heapq.heappush(A_oddq,-count)
if max_odd < count:
    max_odd=count
    i_odd = A_odd[i-1]

ans=N-max_odd-max_even
if i_even == i_odd:
    if len(A_evenq) == 1 and len(A_oddq) == 1:
        ans = N//2
    elif len(A_evenq) == 1:
        heapq.heappop(A_oddq)
        odd2 = -heapq.heappop(A_oddq)
        ans = N-max_even-odd2
    elif len(A_oddq) == 1:
        heapq.heappop(A_evenq)
        even2 = -heapq.heappop(A_evenq)
        ans = N-max_odd-even2
    else:
        ans=0
        heapq.heappop(A_oddq)
        odd2 = -heapq.heappop(A_oddq)
        heapq.heappop(A_evenq)
        even2 = -heapq.heappop(A_evenq)
        ans = min(N-even2-max_odd,N-odd2-max_even)
print(ans)

Solution (Python):
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
E=Counter(V[::2]).most_common()
O=Counter(V[1::2]).most_common()
if E[0][0]!=O[0][0]:
    print(n-E[0][1]-O[0][1])
else:
    if E[0][1]==O[0][1]==n//2:
        print(E[0][1])
    else:
        print(min(n-E[1][1]-O[0][1],n-E[0][1]-O[1][1]))

Solution (Python):
N = int(input())
vs = list(map(int, input().split()))
vs0 = vs[0::2]
vs1 = vs[1::2]
M0 = {}
for v in vs0:
  if not(v in M0):
    M0[v] = 0
  M0[v] += 1
M1 = {}
for v in vs1:
  if not(v in M1):
    M1[v] = 0
  M1[v] += 1
L0 = []
for v in M0:
  n = M0[v]
  L0.append((n, v))
L0.sort(reverse=True)
L0.append((0, -1))
L1 = []
for v in M1:
  n = M1[v]
  L1.append((n, v))
L1.sort(reverse=True)
L1.append((0, -1))


if L0[0][1] == L1[0][1]:
  r = min(N-L0[1][0]-L1[0][0], N-L0[0][0]-L1[1][0])
else:
  r = N-L0[0][0]-L1[0][0]
print(r)

Solution (Python):
n = int(input())
nums = list(map(int, input().split()))
 
nums1 = nums[0::2]
nums2 = nums[1::2]
 
bug1 = [0] * 100001
bug2 = [0] * 100001
 
for num in nums1:
    bug1[num] += 1
 
for num in nums2:
    bug2[num] += 1
 
max_v_1 = max(bug1)
max_i_1 = bug1.index(max_v_1)
max_v_2 = max(bug2)
max_i_2 = bug2.index(max_v_2)
 
if max_i_1 == max_i_2:
    bug1[max_i_1] = 0
    bug2[max_i_2] = 0
    sec_max_v_1 = max(bug1)
    sec_max_v_2 = max(bug2)
    print(n - max(max_v_1, max_v_2) - max(sec_max_v_1, sec_max_v_2))
else:
    print(n - max_v_1 - max_v_2)

Solution (Python):
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
E=Counter(V[::2]).most_common()+[(0,0)]
O=Counter(V[1::2]).most_common()+[(0,0)]
print(n-E[0][1]-O[0][1] if E[0][0]!=O[0][0] else n-max(E[0][1]+O[1][1],O[0][1]+E[1][1]))

Solution (Python):
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
E=Counter(V[::2]).most_common()
O=Counter(V[1::2]).most_common()
if E[0][0]==O[0][0]:
	E2=Counter(V[1::2]).most_common()[1][1] if len(E)>1 else 0
	O2=Counter(V[::2]).most_common()[1][1] if len(O)>1 else 0 
print(n-E[0][1]-O[0][1] if E[0][0]!=O[0][0] else n-max(E[0][1]+E2,O[0][1]+O2))

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys



def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
num = LI()
even_cnt = Counter([num[i] for i in range(n) if i%2]).most_common()
odd_cnt = Counter([num[i] for i in range(n) if i%2==0]).most_common()

odd_cnt += [(0, 0)]
even_cnt += [(0, 0)]


if len(odd_cnt) == 1:
    print(n - odd_cnt[0][1] - even_cnt[1][1])
elif even_cnt[0][0] != odd_cnt[0][0]:
    print(n - even_cnt[0][1] - odd_cnt[0][1])
else:
    print(min(n - even_cnt[0][1] - odd_cnt[1][1], n - even_cnt[1][1] - odd_cnt[0][1]))

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

from collections import defaultdict

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

for i in range(N//2):
    j = 2*i
    k = 2*i + 1
    even[v[j]][0] += 1
    odd[v[k]][0] += 1

even_sorted = sorted(even, key=lambda x:x[0], reverse = True)
odd_sorted = sorted(odd, key=lambda x:x[0], reverse = True)

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

Solution (Python):
def main():
    n = int(input())
    v = [int(i) for i in input().split()]
    v_even = v[::2]
    v_odd = v[1::2]
    from collections import Counter
    v_even_cnt = sorted(list(Counter(v_even).items()),key=lambda x:x[1],reverse=True)
    v_odd_cnt = sorted(list(Counter(v_odd).items()),key=lambda x:x[1],reverse=True)
    ans = 0
    if v_even_cnt[0][0] != v_odd_cnt[0][0]:
        ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[0][1]
    else:
        if len(v_even_cnt) == 1:
            ans = len(v_even)
        else:
            ans1 = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[1][1]
            ans2 = len(v_even) - v_even_cnt[1][1] + len(v_odd) - v_odd_cnt[0][1]
            ans = min(ans1,ans2)
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
V = list(map(int, input().split()))
odd, even = {}, {}
for i in range(N):
    if i % 2 == 1:
        if V[i] not in even:
            even[V[i]] = 0
        even[V[i]] += 1
    else:
        if V[i] not in odd:
            odd[V[i]] = 0
        odd[V[i]] += 1

sorted_odd = sorted(odd.items(), key=lambda x: x[1], reverse=True)
sorted_even = sorted(even.items(), key=lambda x: x[1], reverse=True)
if sorted_odd[0][0] != sorted_even[0][0]:
    print(N - sorted_even[0][1] - sorted_odd[0][1])
else:
    if len(sorted_odd) == 1 or len(sorted_even) == 1:
        print(N // 2)
    else:
        print(N - max(sorted_even[0][1] + sorted_odd[1][1], sorted_even[1][1] + sorted_odd[0][1]))

Solution (Python):
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce



def getInputInt():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList



n, = map(int, input().split())
data = getInputListInt()

onedic = {0:0}
twodic = {0:0}

for i in range(n):
    if i % 2 ==0:
        onedic[data[i]]=0
    else:
        twodic[data[i]]=0

for i in range(n):
    if i % 2 ==0:
        onedic[data[i]]+=1
    else:
        twodic[data[i]]+=1

onemax = max(onedic, key=onedic.get)
twomax = max(twodic, key=twodic.get)

onemax = sorted(onedic.items(), key = lambda x:x[1], reverse=True)
twomax = sorted(twodic.items(), key = lambda x:x[1], reverse=True)

ans = 0
if onemax[0][0] != twomax[0][0]:
    ans = n - onemax[0][1] - twomax[0][1]
else:
    ans = min(n - onemax[0][1] - twomax[1][1], n - onemax[1][1] - twomax[0][1])

print(ans)

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

from collections import Counter

v1 = []
v2 = []
for i in range(0,n-1,2):
  v1.append(V[i])
for i in range(1,n,2):
  v2.append(V[i])
  
c1 = Counter(v1).most_common() + [(0,0)]
c2 = Counter(v2).most_common() + [(0,0)]

if c1[0][0] == c2[0][0]:
  a1 = n -c1[1][1]-c2[0][1]
  a2 = n -c1[0][1]-c2[1][1]
  ans = min(a1,a2)
  
else:
  ans = n-c1[0][1]-c2[0][1]

print(ans)

Solution (Python):
from collections import Counter

def abc(v):
  n = len(v)
  v_e = Counter(v[::2]).most_common(2)
  v_o = Counter(v[1::2]).most_common(2)
  if v_e[0][0] != v_o[0][0]:
    return n - v_e[0][1] - v_o[0][1]
  else:
    if len(v_o)==1 or len(v_e)==1:
      return n//2
    else:
      return n - max(v_e[0][1] + v_o[1][1], v_e[1][1] + v_o[0][1])
    
input()
print(abc(list(map(int, input().split()))))

Solution (Python):
n = int(input())
v = [int(x) for x in input().split()]
dic0 = {}
dic1 = {}
for i in range(n):
  if i % 2 == 0:
    if v[i] in dic0:
      dic0[v[i]] += 1
    else:
      dic0[v[i]] = 1
  else:
    if v[i] in dic1:
      dic1[v[i]] += 1
    else:
      dic1[v[i]] = 1
list0 = sorted(dic0.items(), key = lambda x : x[1])
list1 = sorted(dic1.items(), key = lambda x : x[1])
l0 = len(list0) - 1
l1 = len(list1) - 1

if list0[l0][0] != list1[l1][0]:
  print(n - list0[l0][1] - list1[l1][1])
else:
  if l0 == 0 and l1 == 0:
    print(n // 2)
  elif l0 == 0:
    print(n - max(list0[0][1] + list1[l1 - 1][1], list1[l1][1]))
  elif l1 == 0:
    print(n - max(list0[l0 - 1][1] + list1[0][1], list0[l0][1]))
  else:
    print(n - max(list0[l0 - 1][1] + list1[l1][1], list0[l0][1] + list1[l1 - 1][1]))

Solution (Python):
n = int(input())
v = [int(x) for x in input().split()]
v_1 = {}
v_2 = {}
k = 1
for i in v:
    if k == 1:
        if i in v_1:
            v_1[i] = v_1[i]+1
        else:
            v_1[i] = 1
    else:
        if i in v_2:
            v_2[i] = v_2[i]+1
        else:
            v_2[i] = 1
    k = -k

v_11 = sorted(v_1.items(), key=lambda x:x[1], reverse=True)
v_12 = sorted(v_2.items(), key=lambda x:x[1], reverse=True)

a1, b1 = v_11[0][1], v_12[0][1]
if len(v_11) == 1:
    a2 = -1
else:
    a2 = v_11[1][1]
if len(v_12) == 1:
    b2 = -1
else:
    b2 = v_12[1][1]
if v_11[0][0] != v_12[0][0]:
    ans = n-a1-b1
elif a2 == -1:
    if b2 == -1:
        ans = n-n//2
    else:
        ans = n-a1-b2
else:
    if b2 == -1:
        ans = n-a2-b1
    else:
        ans = min(n-a2-b1,n-a1-b2)
print(ans)

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

A = [[0] * (10**5+1) for i in range(2)]

for i in range(n):
    A[i%2][V[i]] += 1

C = [[0] * (10**5+1) for i in range(2)]  
for i in range(1, len(C[0])):
    C[0][i] = max(C[0][i-1], A[0][i])
    C[1][i] = max(C[1][i-1], A[1][i])





ans = 0
for i in range(1, len(C[0])):
    ans = max(ans, C[1][i-1] + A[0][i])
    ans = max(ans, C[0][i-1] + A[1][i])

print(n - ans)

Solution (Python):
from collections import Counter

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

f = Counter(v[::2]).most_common(2)
s = Counter(v[1::2]).most_common(2)

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

Solution (Python):
import sys
import math
from fractions import gcd

from collections import Counter



def lcm(a, b):
    return a * b // gcd(a, b)

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

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

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""









N =  int(sys.stdin.readline())
L =  list(map(int, sys.stdin.readline().split()))

E = L[::2]
O = L[1::2]

ce = Counter(E)
co = Counter(O)

cem = ce.most_common()
com = co.most_common()

if cem[0] != com[0]:
    print(N - cem[0][1] - com[0][1])
else:
    if len(cem) == 1 or len(com) == 1:
        print(N // 2)
    else:
        print(min(N - (cem[0][1] + com[1][1]), N - (cem[1][1] + com[0][1])))

Solution (Python):
from collections import Counter
n = int(input())
s = list(map(int, input().split()))
evenL = []
oddL = []
for i, v in enumerate(s):
  if i % 2 == 0:
    evenL.append(v)
  else:
    oddL.append(v)
    
evenLc = Counter(evenL)
oddLc = Counter(oddL)

evenLcs = sorted(evenLc.items(), key=lambda x: -x[1])
oddLcs = sorted(oddLc.items(), key=lambda x: -x[1])

if evenLcs[0][0] != oddLcs[0][0]:
  print(n - evenLcs[0][1] - oddLcs[0][1])
else:
  if len(evenLc) == 1 and len(oddLc) == 1:
    print(n - len(evenL))
    exit()
  if evenLcs[0][1] > oddLcs[0][1]:
    print(n - evenLcs[0][1] - oddLcs[1][1])
  elif evenLcs[0][1] < oddLcs[0][1]:
    print(n - evenLcs[1][1] - oddLcs[0][1])
  else:
    print(n - evenLcs[0][1] - max(evenLcs[1][1], oddLcs[1][1]))

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

    dic1 = {0:0}
    for i in range(0, n, 2):
        if v[i] in dic1:
            dic1[v[i]] += 1
        else:
            dic1[v[i]] = 1
    
    dic2 = {0:0}
    for i in range(1, n, 2):
        if v[i] in dic2:
            dic2[v[i]] += 1
        else:
            dic2[v[i]] = 1
    
    dic1 = sorted(list(dic1.items()), key=lambda x: -x[1])
    dic2 = sorted(list(dic2.items()), key=lambda x: -x[1])
    
    
    if dic1[0][0] != dic2[0][0]:
        print(n-dic1[0][1]-dic2[0][1])
    else:
        print(min(n-dic1[0][1]-dic2[1][1], n-dic1[1][1]-dic2[0][1]))

if __name__ == "__main__":
    main()

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()
vvv = na()
even = vvv[::2]
odd = vvv[1::2]
d_even = {}
d_odd = {}
for i in range(n//2):
    if even[i] not in d_even.keys():
        d_even[even[i]] = 1
    else:
        d_even[even[i]] += 1

    if odd[i] not in d_odd.keys():
        d_odd[odd[i]] = 1
    else:
        d_odd[odd[i]] += 1

e_max = max(d_even, key=d_even.get)
o_max = max(d_odd, key=d_odd.get)
e1 = d_even[e_max]
o1 = d_odd[o_max]

if e_max == o_max:
    d_even[e_max] = 0
    d_odd[o_max] = 0

    e2 = max(d_even.values())
    o2 = max(d_odd.values())

    ans = n - max(e1 + o2, e2 + o1)

else:
    ans = n - e1 - o1

print(ans)

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

b = a[1::2]
c = a[::2]

b_dic = {}
c_dic = {}

for i in range(n//2):
  if b[i] in b_dic.keys():
    b_dic[b[i]] += 1
  else:
    b_dic[b[i]] = 1
    
  if c[i] in c_dic.keys():
    c_dic[c[i]] += 1
  else:
    c_dic[c[i]] = 1
    
b_max = max(b_dic, key=b_dic.get)
c_max = max(c_dic, key=c_dic.get)

if b_max == c_max:
  m_b = b_dic[b_max]
  m_c = c_dic[c_max]
  
  b_dic[b_max] = 0
  c_dic[c_max] = 0
  
  b_max2 = max(b_dic, key=b_dic.get)
  c_max2 = max(c_dic, key=c_dic.get)

  ans = n - max(m_b + c_dic[c_max2], b_dic[b_max2] + m_c)
  
else:
  ans = n - b_dic[b_max] - c_dic[c_max]
  
print(ans)

Solution (Python):
import sys
import collections

n = int(input())

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

v_odd = v[1::2]
v_even = v[0::2]
c_odd = collections.Counter(v_odd)
c_even = collections.Counter(v_even)

if c_odd.most_common()[0][0] != c_even.most_common()[0][0]:
    print(n - c_odd.most_common()[0][1] - c_even.most_common()[0][1])
else:
    if len(c_even.most_common()) == 1:
        print(n - c_odd.most_common()[0][1])
    elif len(c_odd.most_common()) == 1:
        print(n - c_even.most_common()[0][1])
    else:
        print(min(n - c_odd.most_common()[0][1] - c_even.most_common()[1][1],
                  n - c_odd.most_common()[1][1] - c_even.most_common()[0][1]))

Solution (Python):

from collections import Counter

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


O = V[0::2]



E = V[1::2]


co = Counter(O)
ce = Counter(E)


co[0] = 0
ce[0] = 0

co1 = co.most_common(1)
ce1 = ce.most_common(1)

co2 = co.most_common(2)
ce2 = ce.most_common(2)

if co1[0][0] == ce1[0][0]:
    print(min(N - co1[0][1] - ce2[1][1], N - co2[1][1] - ce1[0][1]))
else:
    print(N - co1[0][1] - ce1[0][1])

Solution (Python):
from collections import Counter

n = int(input())
vs = list(map(int, input().split()))
a = vs[::2]
b = vs[1::2]

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

Solution (Python):
from collections import Counter


n = int(input())
vs = list(map(int, input().split()))
a = vs[::2]
b = vs[1::2]

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

Solution (Python):
from collections import Counter
 
N = int(input())
V = [i for i in input().split()]
 
odd = Counter(V[::2]).most_common(2)
even = Counter(V[1::2]).most_common(2)

if odd[0][0] != even[0][0]:
    print(N - odd[0][1] - even[0][1])
elif len(odd) == 1:
    print(N // 2)
else:
    o0e1 = N - odd[0][1] - even[1][1]
    o1e0 = N - odd[1][1] - even[0][1]
    print(min(o0e1, o1e0))