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):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    A_odd = A[1::2]
    A_even = A[0::2]
    dict_odd = {-1:0}
    dict_even = {-1:0}
    for i in A_odd :
        if i not in dict_odd :
            dict_odd[i] = 1
        else:
            dict_odd[i] += 1
    for i in A_even :
        if i not in dict_even :
            dict_even[i] = 1
        else:
            dict_even[i] += 1
    dict_odd  = sorted(dict_odd.items(), key = lambda x : x[1],reverse=True)
    dict_even = sorted(dict_even.items(), key=lambda x: x[1], reverse=True)

    if dict_even[0][0] != dict_odd[0][0] :
        max_odd = dict_odd[0][1]
        max_even = dict_even[0][1]
        print(N - max_even - max_odd)
    else:
        if dict_odd[0][1] > dict_even[0][1]:
            max_odd = dict_odd[0][1]
            max_even = dict_even[1][1]
            print(N - max_even - max_odd)
        elif dict_even[0][1] > dict_odd[0][1] :
            max_odd = dict_odd[1][1]
            max_even = dict_even[0][1]
            print(N - max_even - max_odd)
        else:
            max_odd = max(dict_even[1][1],dict_odd[1][1])
            print(N - dict_even[0][1] - max_odd)
            
            


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

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

cnt1 = Counter(v[::2]).most_common()
cnt2 = Counter(v[1::2]).most_common()
cnt1 += [(-1,0)]
cnt2 += [(-1,0)]
if cnt1[0][0] != cnt2[0][0]:
    print(n - (cnt1[0][1] + cnt2[0][1]))
else:
    print(n - max(cnt1[1][1] + cnt2[0][1], cnt1[0][1] + cnt2[1][1]))

Solution (Python):
from collections import Counter

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

X = Counter(V[::2]).most_common(2)
Y = Counter(V[1::2]).most_common(2)

if X[0][0] != Y[0][0]:
    print(n - X[0][1] - Y[0][1])
else:
    x = 0 if len(X) < 2 else X[1][1]
    y = 0 if len(Y) < 2 else Y[1][1]
    if X[0][1] + y > x + Y[0][1]:
        print(n - X[0][1] - y)
    else:
        print(n - x - Y[0][1])

Solution (Python):
import collections

n = int(input())
v = list(map(int, input().split()))
v1 = v[0::2]
v2 = v[1::2]
c1 = collections.Counter(v1)
c2 = collections.Counter(v2)
best_v1_val = c1.most_common()[0][0]
best_v2_val = c2.most_common()[0][0]
best_v1_cnt = c1.most_common()[0][1]
best_v2_cnt = c2.most_common()[0][1]

if best_v1_val != best_v2_val:
  cnt = n//2 - best_v1_cnt + n//2 - best_v2_cnt
else:
  if len(c1) != 1:
    sec_best_v1_cnt = c1.most_common()[1][1]
  else:
    sec_best_v1_cnt = 0
  if len(c2) != 1:
    sec_best_v2_cnt = c2.most_common()[1][1]
  else:
    sec_best_v2_cnt = 0
  cnt = min(n//2 - best_v1_cnt + n//2 - sec_best_v2_cnt, n//2 - sec_best_v1_cnt + n//2 - best_v2_cnt,)
print(cnt)

Solution (Python):
from collections import Counter as C
n = int(input())
a = list(map(int,input().split()))
c1 = C(a[::2])
c2 = C(a[1::2])
mc1 = c1.most_common(2)
mc2 = c2.most_common(2)
if mc1[0][0] != mc2[0][0]:
  ans = n - mc1[0][1] - mc2[0][1]
else:
  if len(mc1) + len(mc2) == 2:
    ans = n // 2
  elif len(mc1) == 1:
    ans = n - mc1[0][1] - mc2[1][1]
  elif len(mc2) == 1:
    ans = n - mc1[1][1] - mc2[0][1]
  else:
    if mc1[1][1] >= mc2[1][1]:
      ans = n - mc1[1][1] - mc2[0][1]
    else:
      ans = n - mc1[0][1] - mc2[1][1]
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
a1,a0 = [] , []

for i in range(n):
    if i%2 == 0:
        a0.append(v[i])
    else:
        a1.append(v[i])
        
b0 = Counter(a0)
b1 = Counter(a1)
b0[0] = 0
b1[0] = 0

if max(b0,key=b0.get) != max(b1,key=b1.get):
    ans = n - max(b0.values()) - max(b1.values())
else:
    q = max(b0.values())
    r = max(b1.values())
    b0.pop(max(b0,key=b0.get))
    b1.pop(max(b1,key=b1.get))
    ans = min(n - max(b0.values()) - r , n - q - max(b1.values()))
    
print(ans)

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

Solution (Python):
import collections
n = int(input())
v = list(input().split())
v0 = []
v1 = []
for i in range(n):
  if i%2 == 0:
    v0.append(v[i])
  else:
    v1.append(v[i])
V0 = collections.Counter(v0)
V1 = collections.Counter(v1)
if V0.most_common()[0][0]==V1.most_common()[0][0]:
  a,b = n,n
  if len(V0)==1:
    a = len(v0)+len(v1)-V1.most_common()[0][1]
  else:
    a = len(v0)+len(v1)-V0.most_common()[1][1]-V1.most_common()[0][1]
  if len(V1)==1:
    b = len(v0)+len(v1)-V0.most_common()[0][1]
  else:
    b = len(v0)+len(v1)-V0.most_common()[0][1]-V1.most_common()[1][1]
  print(min(a,b))
else:
  print(len(v0)+len(v1)-V0.most_common()[0][1]-V1.most_common()[0][1])

Solution (Python):
n  = int(input())
s = list(map(int,input().split()))
dic1 = {}
dic2 = {}
for i in range(n):
    if i % 2 == 0:
        if s[i] in dic1:
            dic1[s[i]] += 1
        else:
            dic1[s[i]] = 1
    else:
        if s[i] in dic2:
            dic2[s[i]] += 1
        else:
            dic2[s[i]] = 1
max1 = max(dic1.values())
max2 = max(dic2.values())
maxkey1 = [i for i,j in dic1.items() if j == max1]
maxkey2 = [i for i,j in dic2.items() if j == max2]
if len(maxkey1) > 1 or len(maxkey2) > 1 or maxkey1[0] != maxkey2[0]:
    print(n-max1-max2)
    exit()
dic1.pop(maxkey1[0])
dic2.pop(maxkey2[0])
if dic1:
    second1 = max(dic1.values())
else:
    second1 = 0
if dic2:
    second2 = max(dic2.values())
else:
    second2 = 0
if max1-second1 <= max2-second2:
    print(n-second1-max2)
else:
    print(n-max1-second2)

Solution (Python):
from collections import Counter

N = int(input())
V = tuple(map(int, input().split()))
X, Y = Counter(), Counter()
for i in range(0, N):
    if i & 1:
        Y[V[i]] += 1
    else:
        X[V[i]] += 1
if len(X) != 1:
    x = sorted(X.items(), reverse=True, key=lambda x: x[1])[:2]
else:
    x = sorted(X.items(), reverse=True, key=lambda x: x[1])[:1]
if len(Y) != 1:
    y = sorted(Y.items(), reverse=True, key=lambda x: x[1])[:2]
else:
    y = sorted(Y.items(), reverse=True, key=lambda x: x[1])[:1]
if x[0][0] == y[0][0]:
    ans = N
    tmp = 0
    if len(y) == 1:
        for i in range(0, N):
            if i & 1:
                if V[i] != y[0][0]+1:
                    tmp += 1
            else:
                if V[i] != x[0][0]:
                    tmp += 1
    else:
        for i in range(0, N):
            if i & 1:
                if V[i] != y[1][0]:
                    tmp += 1
            else:
                if V[i] != x[0][0]:
                    tmp += 1
    ans = min(ans, tmp)
    tmp = 0
    if len(x) == 1:
        for i in range(0, N):
            if i & 1:
                if V[i] != y[0][0]:
                    tmp += 1
            else:
                if V[i] != x[0][0]+1:
                    tmp += 1
    else:
        for i in range(0, N):
            if i & 1:
                if V[i] != y[0][0]:
                    tmp += 1
            else:
                if V[i] != x[1][0]:
                    tmp += 1
    ans = min(ans, tmp)
else:
    ans = 0
    for i in range(0, N):
        if i & 1:
            if V[i] != y[0][0]:
                ans += 1
        else:
            if V[i] != x[0][0]:
                ans += 1
print(ans)

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

u, v = [], []
for i in range(0, n, 2):
    u.append(a[i])
for i in range(1, n, 2):
    v.append(a[i])
cu = dict()
for i in u:
    if i in cu:
        cu[i] += 1
    else:
        cu[i] = 1
cv = dict()
for i in v:
    if i in cv:
        cv[i] += 1
    else:
        cv[i] = 1
ua, ub = (sorted(cu.items(), key=lambda x: x[1], reverse=True) + [(-1, 0)])[:2]
va, vb = (sorted(cv.items(), key=lambda x: x[1], reverse=True) + [(-2, 0)])[:2]
if ua[0] == va[0]:
    print(min(len(u) - ua[1] + len(v) - vb[1], len(u) - ub[1] + len(v) - va[1]))
else:
    print(len(u) - ua[1] + len(v) - va[1])

Solution (Python):
from itertools import groupby

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

odd=[v[i] for i in range(0,n) if i%2==1]
even=[v[i] for i in range(0,n) if i%2==0]
odd.sort()
even.sort()
odd=groupby(odd)
even=groupby(even)
odd=[[len(list(group)),key] for key,group in odd]
even=[[len(list(group)),key] for key,group in even]
odd.append([0,0])
even.append([0,0])
odd.sort(reverse=True)
even.sort(reverse=True)
if odd[0][1]!=even[0][1]:
    print(n-odd[0][0]-even[0][0])
else:
    print(min(n-odd[0][0]-even[1][0],n-odd[1][0]-even[0][0]))

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

O = [0] * 10 ** 6
E = [0] * 10 ** 6

for v in range(len(V)):
  if v % 2 == 0:
    E[V[v]] += 1
  else:
    O[V[v]] += 1
    
o_max = max(O)
e_max = max(E)

o = [i for i,x in enumerate(O) if x == o_max]
e = [i for i,x in enumerate(E) if x == e_max]

ans = 0
if len(o) == 1 and len(e) == 1 and e[0] == o[0]:
  a=max(sorted(O)[-2],sorted(E)[-2])
  if a == 0:
    print(int(N/2))
  else:
    print(int(int(N/2 - o_max) + int(N/2 - a)))
else:
  print(int(int(N/2 - o_max) + int(N/2 - e_max)))

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

evens = Counter(A[::2])
odds = Counter(A[1::2])
evens[0] = 0 
odds[0] = 0

e1, e2 = evens.most_common(2)
o1, o2 = odds.most_common(2)

if e1[0] != o1[0]:
  print(N - (e1[1] + o1[1]))
else:
  print(N - max(e1[1] + o2[1], e2[1] + o1[1]))

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def calc(N):
    return sum(int(x) for x in str(N))


def main():
    
    N = Scanner.int()
    V = Scanner.map_int()
    V_MAX = int(1e05) + 1
    mode1, mode2 = [0] * V_MAX, [0] * V_MAX
    for i in range(N):
        if i % 2 == 0:
            mode1[V[i]] += 1
        else:
            mode2[V[i]] += 1

    m1, m2 = mode1.index(max(mode1)), mode2.index(max(mode2))
    if not m1 == m2:
        ans = 0
        for i in range(N):
            if i % 2 == 0:
                if V[i] != m1:
                    ans += 1
            else:
                if V[i] != m2:
                    ans += 1
        print(ans)
        return
    m3 = mode1.index(sorted(mode1)[-2]) if len(mode1) != 1 else -1
    m4 = mode2.index(sorted(mode2)[-2]) if len(mode2) != 1 else -1
    c1, c2, c3, c4 = 0, 0, 0, 0
    for i in range(N):
        if i % 2 == 0:
            if V[i] != m1:
                c1 += 1
            if V[i] != m3:
                c3 += 1
        else:
            if V[i] != m2:
                c2 += 1
            if V[i] != m4:
                c4 += 1
    print(min(c1+c4, c2+c3))
    return


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
c1 = sorted(list(dict(Counter(v[::2])).items()), key=lambda x: x[1])
c2 = sorted(list(dict(Counter(v[1::2])).items()), key=lambda x: x[1])
if c1[-1][0] != c2[-1][0]:
    print(n-c1[-1][1]-c2[-1][1])
elif len(c1) == len(c2) == 1:
    print(n//2)
elif len(c1) == 1:
    print(n//2-c2[-2][1])
elif len(c2) == 1:
    print(n//2-c1[-2][1])
else:
    print(min(n-c1[-1][1]-c2[-2][1], n-c1[-2][1]-c2[-1][1]))

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

v1 = [0] * (10**5)
v2 = [0] * (10**5)
v1_max_1 = 0
v1_max_2 = 0
v2_max_1 = 0
v2_max_2 = 0

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

for i in range(1,n,2):
	v2[v[i]-1] += 1

v1_max_index = v1.index(max(v1))
v2_max_index = v2.index(max(v2))

v1.sort(reverse=True)
v2.sort(reverse=True)
v1_max_1 = v1[0]
v2_max_1 = v2[0]
v1_max_2 = v1[1]
v2_max_2 = v2[1]

ans = n - ( v1_max_1 + v2_max_1 )

if ans == 0:
	if v[0] == v[1]:
		print(n//2)
		exit()

if v1_max_index == v2_max_index:
	print(min( n - ( v1_max_2 + v2_max_1 ),n  - ( v1_max_1 + v2_max_2 ) ))
else:
	print(ans)

Solution (Python):
def examC():
    N = I()
    A = LI()
    d0 = defaultdict(int); d0[0] = 0
    d1 = defaultdict(int); d1[0] = 0
    for i in range(N):
        if i%2==0:
            d0[A[i]] +=1
        else:
            d1[A[i]] +=1
    n0 = sorted(d0.items(),key=lambda x:x[1])
    n1 = sorted(d1.items(),key=lambda x:x[1])

    if n0[-1][0]!=n1[-1][0]:
        ans = N - n0[-1][1] - n1[-1][1]
    else:
        ans = N - max(n0[-1][1]+n1[-2][1],n0[-2][1]+n1[-1][1])
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,ALPHABET
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]
ALPHABET = [chr(ord('A') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

Solution (Python):
import collections

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

L1 = []
L2 = []

for i in range(N):
  if i % 2 == 0:
    L1.append(V[i])
  else:
    L2.append(V[i])
    
con1 = collections.Counter(L1).most_common()
con2 = collections.Counter(L2).most_common()

nums = 0


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


elif len(set(L1)) == 1 and len(set(L2)) == 1:
  print(0)

else:
  ans = 0
  total = 0
  if con1[0][0] == con2[0][0]:
  
    for i in range(1,len(con1)):
      total += con1[i][1]
    for i in range(2,len(con2)):
      total += con2[i][1]
    total += con2[0][1]
    
    for i in range(1,len(con2)):
      ans += con2[i][1]
    for i in range(2,len(con1)):
      ans += con1[i][1]
    ans += con1[0][1]
    
    ans = min(ans,total)
    
  else:
    for i in range(1,len(con1)):
      ans += con1[i][1]
    for i in range(1,len(con2)):
      ans += con2[i][1]
    
  print(ans)

Solution (Python):
from collections import defaultdict


def solve():
    n, *v = map(int, open(0).read().split())
    
    dict1 = defaultdict(int)
    for i in range(0, n, 2):
        dict1[v[i]] += 1
    
    dict2 = defaultdict(int)
    for i in range(1, n, 2):
        dict2[v[i]] += 1
    
    sorted1 = sorted(dict1.items(), key=lambda x: x[1], reverse=True) + [(-1, 0)]
    sorted2 = sorted(dict2.items(), key=lambda x: x[1], reverse=True) + [(-2, 0)]
    
    ans = n
    for i in range(2):
        for j in range(2):
            if sorted1[i][0] == sorted2[j][0]:
                continue
            ans = min(ans, n - sorted1[i][1] - sorted2[j][1])
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import numpy as np
N = int(input())
v = list(map(int,input().split()))

countT = np.bincount(v[0::2])
top = countT.argsort()[::-1]
countU = np.bincount(v[1::2])
under = countU.argsort()[::-1]

if top[0]==under[0]:
    print(N-max(countT[top[0]]+countU[under[1]], countT[top[1]]+countU[under[0]]))
else:
    print(N-countT[top[0]]-countU[under[0]])

Solution (Python):
import numpy as np
import collections

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

if N == len(np.where(V == V[0])[0]):
    print(N // 2)
else:
    v0 = [V[i] for i in range(0, N - 1, 2)]
    v1 = [V[i] for i in range(1, N, 2)]
    v0_items = dict(collections.Counter(v0).items())
    v1_items = dict(collections.Counter(v1).items())
    v0_max_key = max(v0_items, key=v0_items.get)
    v1_max_key = max(v1_items, key=v1_items.get)
    
    if v0_max_key == v1_max_key:
        count = v0_items.pop(v0_max_key)
        count = (N // 2) - v1_items.pop(v1_max_key)
        tmp1 = v0_items.pop(max(v0_items, key=v0_items.get))
        tmp2 = v1_items.pop(max(v1_items, key=v1_items.get))
        count += (N // 2) - max(tmp1, tmp2)
        print(count)
    else:
        count = (N // 2) - max(collections.Counter(v0).values())
        count += (N // 2) - max(collections.Counter(v1).values())
        print(count)

Solution (Python):
from collections import Counter
 
N = int(input())
V = [int(i) for i in input().split()]
V1 = V[1::2]
V2 = V[0::2]
 
v1 = Counter(V1).most_common(2)
v2 = Counter(V2).most_common(2)
 
v1.append((0,0))
v2.append((0,0))
 
 
if v1[0][0] != v2[0][0]:
  print(N - v1[0][1] - v2[0][1])
  
else:
  print(min(N - v1[1][1] - v2[0][1], N - v1[0][1] - v2[1][1]))

Solution (Python):
import sys
N = int(input())
arr = list(map(int, input().split()))
if N == 2:
    print(0)
    sys.exit(0)


def update(start):
    dic = dict()
    for i in range(start, N, 2):
        if arr[i] in dic:
            dic[arr[i]] += 1
        else:
            dic[arr[i]] = 1
    return sorted(dic.items(), key=lambda ele: ele[1], reverse=True)


tuple_1 = update(0)
tuple_2 = update(1)

what_1, mx_1 = tuple_1[0]
what_2, mx_2 = tuple_2[0]

if what_1 == what_2:
    if len(tuple_1) == 1 and len(tuple_2) == 1:
        print(N//2)
    elif len(tuple_1) == 1:
        print(N//2 - tuple_2[1][1])
    elif len(tuple_2) == 1:
        print(N//2 - tuple_1[1][1])
    else:
        ans1 = N - tuple_1[0][1] - tuple_2[1][1]
        ans2 = N - tuple_1[1][1] - tuple_2[0][1]
        print(min(ans1, ans2))
else:
    print(N - mx_1 - mx_2)

Solution (Python):
from collections import Counter

n=int(input())
s=list(map(int,input().split()))
e=Counter(s[0::2])
o=Counter(s[1::2])
e[0]=0
o[0]=0
e1,e2=e.most_common(2)
o1,o2=o.most_common(2)
if e1[0]!=o1[0]:
    print(n-(e1[1]+o1[1]))
else:
    print(n-max(e1[1]+o2[1],e2[1]+o1[1]))

Solution (Python):
import collections

num_of_nums = int(input())
numbers = list(map(int, input().split(" ")))
numbers_odd = [numbers[i] for i in range(1, num_of_nums, 2)]
numbers_even = [numbers[j] for j in range(0, num_of_nums, 2)]
c_odd = collections.Counter(numbers_odd)
c_even = collections.Counter(numbers_even)

counter_odd = 0
counter_even = 0

if sum(numbers) / int(len(numbers)) != numbers[0]:
    if c_odd.most_common()[0][0] != c_even.most_common()[0][0]:
        counter_odd += int(len(numbers_odd)) - c_odd.most_common()[0][1]
        counter_even += int(len(numbers_even)) - c_even.most_common()[0][1]
        print(counter_even + counter_odd)
    else:
        if c_odd.most_common()[1][1] <= c_even.most_common()[1][1]:
            counter_odd += int(len(numbers_odd)) - c_odd.most_common()[0][1]
            counter_even += int(len(numbers_even)) - c_even.most_common()[1][1]
            print(counter_even + counter_odd)
        else:
            counter_odd += int(len(numbers_odd)) - c_odd.most_common()[1][1]
            counter_even += int(len(numbers_even)) - c_even.most_common()[0][1]
            print(counter_odd + counter_even)
else:
    print(int(int(len(numbers)) / 2))

Solution (Python):
import collections

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

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

if odd[0][0] == even[0][0]:
    if len(odd) == 1:
        print(n-even[0][1])
    elif len(even) == 1:
        print(n-odd[0][1])
    elif odd[0][1]+even[1][1] < even[0][1]+odd[1][1]:
        print(n-odd[1][1]-even[0][1])
    else:
        print(n-odd[0][1]-even[1][1])
else:
    print(n-odd[0][1]-even[0][1])

Solution (Python):
n=int(input())  
v=list(map(int, input().split()))
odd = []
even = []
for i in range(n):
  if i % 2 ==0:
    odd.append(v[i])
  else:
    even.append(v[i])

from collections import Counter
oddc=Counter(odd)
evenc=Counter(even)
od = oddc.most_common(2)
ev = evenc.most_common(2)
if od[0][0] != ev[0][0]:
  m = od[0][1] + ev[0][1]
elif len(od)==1 and len(ev)==1:
  m = od[0][1]
elif len(od)==1:
  m = od[0][1] + ev[1][1]
elif len(ev)==1:
  m = ev[0][1] + od[1][1]
else:
  m = max( ev[0][1] + od[1][1],od[0][1] + ev[1][1])

if odd == even and len(od)==1:
  print(n//2)
else:
  print(n-m)

Solution (Python):

from collections import Counter

n    = int(raw_input())
nums = list(map(int, raw_input().split()))

nums_odd  =   nums[0:n:2]
nums_even =   nums[1:n:2]

N_odd     =   sorted(Counter(nums_odd ).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]
N_even    =   sorted(Counter(nums_even).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]

if N_odd[0][0] == N_even[0][0]:
    if N_odd[0][1] + N_even[1][1] > N_odd[1][1] + N_even[0][1]:
        print n - N_odd[0][1] - N_even[1][1]
    else:
        print n - N_odd[1][1] - N_even[0][1]
else:
    print n - N_odd[0][1] - N_even[0][1]

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]
c1=[(0,0)]+sorted(Counter(v1).items(), key=lambda x:x[1])
c2=[(0,0)]+sorted(Counter(v2).items(), key=lambda x:x[1])

if c1[-1][0]!=c2[-1][0]:
    print(len(v1)-c1[-1][1] + len(v2)-c2[-1][1])
else:
    if c1[-2][1]<=c2[-2][1]:
        print(len(v1)-c1[-1][1] + len(v2)-c2[-2][1])
    else:
        print(len(v1)-c1[-2][1] + len(v2)-c2[-1][1])

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
e=Counter(v[::2])
e[0]=0
o=Counter(v[1::2])
o[0]=0
e1,e2=e.most_common(2)
o1,o2=o.most_common(2)
if e1[0]!=o1[0]:
    print(n-(e1[1]+o1[1]))
else:
    print(n-max(e1[1]+o2[1],e2[1]+o1[1]))

Solution (Python):
import sys
from collections import Counter

N = int(sys.stdin.readline())
X = input().split()

odd = Counter(X[0::2])
even = Counter(X[1::2])

a = odd.most_common()
b = even.most_common()

oddNum = a[0][1]
evenNum = b[0][1]


if a[0][0] == b[0][0]:
  if len(a) == 1 and len(b) == 1:
    oddNum = 0
    evenNum = N//2
  
  elif a[0][1] - a[1][1] > b[0][1] - b[1][1]:
    oddNum = a[0][1]
    evenNum = b[1][1]
    
  else:
    oddNum = a[1][1]
    evenNum = b[0][1]

print(N - oddNum - evenNum)

Solution (Python):
N = int(input())
v = list(map(int,input().split()))
vo = dict({})
ve = dict({})
for i,e in zip(v[0::2],v[1::2]):
    if i in ve :
        ve[i] += 1
    else:
        ve[i] = 1
    if e in vo :
        vo[e] += 1
    else:
        vo[e] = 1
if len(vo)==1 and len(ve)==1:
    if v[0]!=v[1]:
        print(0)
    else:
        print(N//2)
else:
    vo = sorted([(i,vo[i]) for i in vo.keys()], key = lambda x:x[1], reverse = True)
    ve = sorted([(i,ve[i]) for i in ve.keys()], key = lambda x:x[1], reverse = True)
    if vo[0][0]!=ve[0][0]:
        print(N-vo[0][1]-ve[0][1])
    else:
        print(N-max(vo[0][1]+ve[1][1],vo[1][1]+ve[0][1]))

Solution (Python):
import collections

n = int(input())
v = input().split()
odd = collections.Counter(v[0::2])
even = collections.Counter(v[1::2])
a = odd.most_common()
b = even.most_common()
c = a[1][1] if len(a)>1 else 0
d = b[1][1] if len(b)>1 else 0
if a[0][0] == b[0][0]:
  if a[0][1]+d > b[0][1]+c:
    e, f = a[0][1], d
  else:
    e, f = c, b[0][1]
else:
  e, f = a[0][1], b[0][1]
  
print((n+1)//2-e + n//2-f)

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

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


def f(odd):
    l = Counter([x for i, x in enumerate(v) if i % 2 == odd]).most_common(2)
    l.append((0, 0))
    return l


a = f(0)
b = f(1)

if a[0][0] != b[0][0]:
    print(n - a[0][1] - b[0][1])
else:
    print(min(n - a[0][1] - b[1][1], n - a[1][1] - b[0][1]))

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

v1 = []
v2 = []

j=0
for i in range(int(n/2)):
    v1.append(v[j])
    j+=2
    
j=0
for i in range(int(n/2)):
    v2.append(v[j+1])
    j+=2

import collections

v1n = collections.Counter(v1)
v2n = collections.Counter(v2)

if v1n.most_common()[0][0] != v2n.most_common()[0][0]:
    print(n - v1n.most_common()[0][1] - v2n.most_common()[0][1])
else:
    if len(v1n) == 1 and len(v2n) == 1:
        print(int(n/2))
    else:
        xxx=(len(v1)-v1n.most_common()[0][1])+(len(v2)-v2n.most_common()[1][1])
        yyy=(len(v1)-v1n.most_common()[1][1])+(len(v2)-v2n.most_common()[0][1])
        print(min(xxx,yyy))

Solution (Python):
import collections

n = int(input())
v = list(map(int,input().split()))
vodd = v[0::2]
veven = v[1::2]

set_vodd = list(set(vodd))
set_veven = list(set(veven))
cnt_vodd = collections.Counter(vodd)
cnt_veven = collections.Counter(veven)

if len(set_vodd) == 1 and set_vodd == set_veven:
    print(n//2)
else:
    if cnt_vodd.most_common(1)[0][0] != cnt_veven.most_common(1)[0][0]:
        ans_vodd = (n//2)- cnt_vodd.most_common(1)[0][1]
        ans_veven = (n//2)- cnt_veven.most_common(1)[0][1]
        print(ans_vodd + ans_veven)
    elif len(set_vodd)>=2 and len(set_veven)>=2:
        ans_vodd_1 = (n//2)- cnt_vodd.most_common(1)[0][1]
        ans_veven_1 = (n//2)- cnt_veven.most_common(2)[1][1]
        ans_vodd_2 = (n//2)- cnt_vodd.most_common(2)[1][1]
        ans_veven_2 = (n//2)- cnt_veven.most_common(1)[0][1]
        print(min(ans_vodd_1+ans_veven_1,ans_vodd_2+ans_veven_2))

Solution (Python):
n=int(input())
v_list = list(map(int,input().split()))
odd_list = []
even_list = []

for i in range(n):
    if i % 2 == 0:
        odd_list.append(v_list[i]) 
    else:
        even_list.append(v_list[i])

import collections

odd_list_c = collections.Counter(odd_list)
even_list_c = collections.Counter(even_list)

if odd_list_c.most_common()[0][0] != even_list_c.most_common()[0][0]:
    ans = n - odd_list_c.most_common()[0][1] - even_list_c.most_common()[0][1]
else:
    if len(even_list_c) == 1 and len(odd_list_c) == 1:
        ans = n // 2
    else: 
        ans1 = n - odd_list_c.most_common()[0][1] - even_list_c.most_common()[1][1]
        ans2 = n - odd_list_c.most_common()[1][1] - even_list_c.most_common()[0][1]
        ans = min(ans1, ans2)

print(ans)

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

vo=v[0::2]
ve=v[1::2]

voc=collections.Counter(vo).most_common()
vec=collections.Counter(ve).most_common()

mvo=voc[0][0]
mve=vec[0][0]

if mvo!=mve:
  print(N-voc[0][1]-vec[0][1])
elif len(voc)==1 and len(vec)==1 and mvo==mve:
  print(N//2)
else:
  print(min(N-voc[0][1]-vec[1][1],N-voc[1][1]-vec[0][1]))

Solution (Python):
import collections

n=int(input())
v=list(map(int,input().split()))
count=0
vo=[]
ve=[]
for i in range(n):
    if i%2==0:
        ve.append(v[i])
    else:
        vo.append(v[i])
e=collections.Counter(ve)
o=collections.Counter(vo)

emax=e.most_common()[0][0]
omax=o.most_common()[0][0]

if emax==omax:
    if e.most_common()[0][1]==len(ve) and o.most_common()[0][1]==len(vo):
        count=n//2
    else:
        omax2 = o.most_common()[1][0]
        emax2 = e.most_common()[1][0]
        tempe = 0
        tempo = 0
        for i in range(n // 2):
            if ve[i] != emax2:
                tempe += 1
        for i in range(n // 2):
            if vo[i] != omax:
                tempe += 1
        for i in range(n // 2):
            if ve[i] != emax:
                tempo += 1
        for i in range(n // 2):
            if vo[i] != omax2:
                tempo += 1
        count = min(tempe, tempo)
else:
    for i in range(n // 2):
        if ve[i] != emax:
            count += 1
    for i in range(n // 2):
        if vo[i] != omax:
            count += 1

print(count)
print()

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

mO = [0,] * 100010
mE = [0,] * 100010

for a in vA[0::2]:
  mO[a] += 1
for a in vA[1::2]:
  mE[a] += 1

modeO = mO.index(max(mO))
modeE = mE.index(max(mE))
if modeO == modeE:
  O1 = mO.pop(modeO)
  E1 = mE.pop(modeE)
  print(min(N - O1 - max(mE), N - max(mO) - E1))
else:
  print(N - max(mO) - max(mE))