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
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def split_even_or_odd(vv, n, start):
    res = {}
    for i in range(start,n,2):
        v = vv[i]
        if not v in res.keys(): res[v] = 1
        else: res[v] += 1
    return res

def find_fs(target):
    maxk1 = maxv1 = 0
    for k, v in target.items():
        if maxv1 < v:
            maxk1, maxv1 = k, v
    maxk2 = maxv2 = 0
    for k, v in target.items():
        if maxv2 < v and maxk1 != k:
            maxk2, maxv2 = k, v
    return (maxk1, maxv1), (maxk2, maxv2)

def main():
    n = II()
    vv = MII()
    ee = split_even_or_odd(vv, n, 0)
    oo = split_even_or_odd(vv, n, 1)

    e1kv, e2kv = find_fs(ee)
    o1kv, o2kv = find_fs(oo)

    minv = 10**5
    if e1kv[0] != o1kv[0]:
        minv = min(minv, n - (e1kv[1] + o1kv[1]))
    else:
        minv = min(minv, n - (e1kv[1] + o2kv[1]))
        minv = min(minv, n - (e2kv[1] + o1kv[1]))
    print(minv)

if __name__ == '__main__':
    main()

Solution (Python):
import collections
import sys

n = int(input())
vn = list(map(int,input().split()))
vnodd = collections.Counter(vn[1::2]).most_common()
vneven= collections.Counter(vn[0::2]).most_common()
vnodd.append([0,0])
vneven.append([0,0])

if vnodd[0][0] != vneven[0][0]:
  print(n - (vnodd[0][1] + vneven[0][1]))
else:
  print(min(n-vnodd[0][1]-vneven[1][1], n-vnodd[1][1]-vneven[0][1]))

Solution (Python):
from collections import defaultdict
odd_dic = defaultdict(int)
even_dic = defaultdict(int)
n = int(input())
ns = list(map(int, input().split()))
for i in range(0, n, 2):
    even_dic[ns[i]] += 1
for i in range(1, n, 2):
    odd_dic[ns[i]] += 1
even = sorted(even_dic.items(), key=lambda x:x[1], reverse=True)
odd = sorted(odd_dic.items(), key=lambda x:x[1], reverse=True)

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

Solution (Python):
n = int(input())
base = list(map(int,input().split()))
even = [0]*(10**5)
odd = [0]*(10**5)

for i in range(1,n+1):
  sign = i%2
  num = base[i-1]
  
  if sign == 0:
    even[num-1] += 1
  elif sign == 1:
    odd[num-1] += 1

ans_e = max(even)
ans_o = max(odd)
even_i = even.index(ans_e)
odd_i = odd.index(ans_o)

if even_i == odd_i:
  even.sort()
  odd.sort()
  if even[10**5 - 2] <= odd[10**5 - 2]:
    ans_o = odd[10**5 - 2]
  else:
    ans_e = even[10**5 - 2]
  
print(n - ans_e - ans_o)

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

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

    x = Counter(v[0:n:2])
    y = Counter(v[1:n:2])
    max_x, x_ = max(x.items(), key=itemgetter(1))
    max_y, y_ = max(y.items(), key=itemgetter(1))
    if max_x == max_y:
        x[max_x] = 0
        y[max_y] = 0
        sec_x = max(x.values())
        sec_y = max(y.values())
        y_ = max(sec_x, sec_y)

    print(n - x_ - y_)

main()

Solution (Python):
from collections import Counter
n = int(input())
v = [int(x) for x in input().split()]
c1 = Counter(v[0::2])
c2 = Counter(v[1::2])
if len(set(v)) == 1:
  res = n // 2
else:
  if c1.most_common()[0][0] == c2.most_common()[0][0]:
    res = n - max(c1.most_common()[0][1]+c2.most_common()[1][1], c1.most_common()[1][1]+c2.most_common()[0][1])
  else:
    res = n - c1.most_common()[0][1] - c2.most_common()[0][1]
print(res)

Solution (Python):
import collections

n=int(input())
v=list(map(int,input().split()))
cto1,cto2,cte1,cte2=0,0,0,0
fro1,fro2,fre1,fre2=0,0,0,0
ve=v[1::2]
vo=v[::2]
ve.sort()
vo.sort()
ans=-1
cnto=collections.Counter(vo)
cnte=collections.Counter(ve)
mco=cnto.most_common()
mce=cnte.most_common()

fro1,cto1=mco[0]
fre1,cte1=mce[0]
if cto1==cte1==n//2:
  if fro1==fre1:
    ans=n//2
  else:
    ans=0
elif cto1==n//2:
  if fro1!=fre1:
    ans=n//2-cte1
  else:
    fre2,cte2=mce[1]
    ans=n//2-cte2
elif cte1==n//2:
  if fro1!=fre1:
    ans=n//2-cto1
  else:
    fro2,cto2=mco[1]
    ans=n//2-cto2
if ans!=-1:
  print(ans)
  exit()


fro2,cto2=mco[1]
fre2,cte2=mce[1]

if cto1==cte1:
  if fro1!=fre1:
    ans=n-cto1-cte1
  else:
    if cto2!=cte2:
      ans=n-cto1-max(cte2,cto2)
    else:
      ans=n-cto1-cto2




print(ans)

Solution (Python):
from itertools import product
from collections import Counter 

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

    vo = Counter(v[::2])
    vo[-1] = 0
    vo = vo.most_common(2)
    ve = Counter(v[1::2])
    ve[-2] = 0
    ve = ve.most_common(2)

    ans = n
    for (k1, v1), (k2, v2) in product(ve, vo):
        if k1 == k2:
            continue
        ans = min(ans, n - v1 - v2)

    print(ans)

main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n = int(input())
    v = list(map(int, input().split()))
    if len(set(v)) == 1:
        print(n//2)
    else:
        a, b = [], []
        for i in range(n):
            if i%2 == 1:
                a.append(v[i])
            else:
                b.append(v[i])
        c = Counter(a)
        c = c.most_common()
        d = Counter(b)
        d = d.most_common()
        if c[0][0] != d[0][0]:
            print(n-c[0][1]-d[0][1])
        else:
            if len(c) == 1:
                if c[0][1]+d[1][1] > d[0][1]:
                    print(n-c[0][1]-d[1][1])
                else:
                    print(n-d[0][1])
            elif len(d) == 1:
                if d[0][1]+c[1][1] > c[0][1]:
                    print(n-d[0][1]-c[1][1])
                else:
                    print(n-c[0][1])
            else:
                if c[0][1]+d[1][1] > d[0][1]+c[1][1]:
                    print(n-c[0][1]-d[1][1])
                else:
                    print(n-c[1][1]-d[0][1])

if __name__ == '__main__':
    main()

Solution (Python):
'''
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
'''
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n = int(readline())
  v = list(map(int, readline().split()))
  odd = Counter(v[::2])
  even = Counter(v[1::2])
  odd[-1] = 0
  even[-2] = 0
  ev = even.most_common(2)
  od = odd.most_common(2)
  
  answer = n
  for (k1,v1), (k2,v2) in product(ev,od):
    if k1 == k2:
      continue
    x = n-v1-v2
    if answer>x:
      answer = x
      
  print(answer)
    
  
  
  
  
  
if __name__ == '__main__':
  main()

Solution (Python):

N = int(input().strip())
v = [int(str) for str in input().strip().split()]

a1_dict = dict()
a2_dict = dict()

for i in range(0, N, 2):
    a1_dict[v[i]] = a1_dict.get(v[i], 0) + 1
    a2_dict[v[i + 1]] = a2_dict.get(v[i + 1], 0) + 1

a1_list = sorted(a1_dict.items(), key=lambda x: x[1], reverse=True)
a2_list = sorted(a2_dict.items(), key=lambda x: x[1], reverse=True)

if a1_list[0][0] != a2_list[0][0]:
    print(N - a1_list[0][1] - a2_list[0][1])
else:
    a1_list.append((0, 0))
    a2_list.append((0, 0))
    if a1_list[1][1] > a2_list[1][1]:
        print(N - a1_list[1][1] - a2_list[0][1])
    else:
        print(N - a1_list[0][1] - a2_list[1][1])

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
even = []
odd = []
for i in range(n):
  if i % 2 == 0: even.append(v[i])
  else: odd.append(v[i])
from collections import Counter
freq_even = sorted(Counter(even).items(), key=lambda x: x[1], reverse=True)
freq_odd = sorted(Counter(odd).items(), key=lambda x: x[1], reverse=True)
ans = 0
if freq_even[0][0] != freq_odd[0][0]:
  ans = n - freq_even[0][1] - freq_odd[0][1]
else:
  if len(freq_even) == 1 and len(freq_odd) == 1:
    ans = n // 2
  elif len(freq_even) == 1:
    ans = n - freq_odd[1][1]
  elif len(freq_odd) == 1:
    ans = n - freq_even[1][1]
  else:
    ans = n - freq_even[0][1] - max(freq_even[1][1], freq_odd[1][1])
print(ans)

Solution (Python):
mod = 10 ** 9 + 7
mod2 = 2**61+1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

_NUMINT_ALL = list(range(10))

def main():
    ans = solve()
    if ans is not None:
        print(ans)

def solve():
    N = iip(False)

    V = iip()
    v1 = V[1::2]
    v2 = V[::2]

    d1 = count_elements(v1)
    d2 = count_elements(v2)


    d1 = d1.items()
    d2 = d2.items()

    d1 = sort_tuples(d1, 1)
    d2 = sort_tuples(d2, 1)

    m11 = d1[-1][1]
    if len(d1) >= 2:
        m12 = d1[-2][1]
    else:
        m12 = 0

    m21 = d2[-1][1]
    if len(d2) >= 2:
        m22 = d2[-2][1]
    else:
        m22 = 0

    if d1[-1][0] != d2[-1][0]:
        return N - (d1[-1][1]+d2[-1][1])
    else:
        return min(N - (m11+m22), N - (m12+m21))


    
    




def iip(listed=True, num_only = True):
    if num_only:
        ret = [int(i) for i in input().split()]
    else:
        ret = [int(i) if i in _NUMINT_ALL else i for i in input().split()]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def sort_tuples(l, index):
    if isinstance(l, list):
        l.sort(key=lambda x:x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x:x[index])



def count_elements(l):
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d



def iipt(l, listed=False, num_only = True):
    ret = []
    for i in range(l):
        ret.append(iip_ord(listed=listed, num_only=num_only))
    return ret

def sortstr(s):
    return "".join(sorted(s))

def iip_ord():
    return [ord(i) - ord("a") for i in input()]

def YesNo(s):
    if s:
        print("Yes")
    else:
        print("No")

def fprint(s):
    for i in s:
        print(i)

def bitall(N):
    ret = []
    for i in range(2**N):
        a = []
        for j in range(N):
            a.append(i%2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):
    print(" ".join([str(i) for i in s]))

def split_print_enter(s):
    print("\n".join([str(i) for i in s]))


def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l


def searchsorted(sorted_list, n, side="left"):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l


def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        
        pass
    return ret


def inv(n, mod):
    return power(n, mod - 2)


def power(n, p, mod_= mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Solution (Python):
mod = 10 ** 9 + 7
mod2 = 2**61+1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

_NUMINT_ALL = list(range(10))

def main():
    ans = solve()
    if ans is not None:
        print(ans)

def solve():
    N = iip(False)

    V = iip()
    v1 = V[1::2]
    v2 = V[::2]

    d1 = {}
    for i in v1:
        if i in d1:
            d1[i] += 1
        else:
            d1[i] = 1

    d2 = {}
    for i in v2:
        if i in d2:
            d2[i] += 1
        else:
            d2[i] = 1

    d1 = list(d1.items())
    d1.sort(key=lambda x:x[1])
    d2 = list(d2.items())
    d2.sort(key=lambda x:x[1])

    m11 = d1[-1][1]
    if len(d1) >= 2:
        m12 = d1[-2][1]
    else:
        m12 = 0

    m21 = d2[-1][1]
    if len(d2) >= 2:
        m22 = d2[-2][1]
    else:
        m22 = 0

    if d1[-1][0] != d2[-1][0]:
        return N - (d1[-1][1]+d2[-1][1])
    else:
        return min(N - (m11+m22), N - (m12+m21))


    
    




def iip(listed=True, num_only = True):
    if num_only:
        ret = [int(i) for i in input().split()]
    else:
        ret = [int(i) if i in _NUMINT_ALL else i for i in input().split()]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iipt(l, listed=False, num_only = True):
    ret = []
    for i in range(l):
        ret.append(iip_ord(listed=listed, num_only=num_only))
    return ret

def sortstr(s):
    return "".join(sorted(s))

def iip_ord():
    return [ord(i) - ord("a") for i in input()]

def YesNo(s):
    if s:
        print("Yes")
    else:
        print("No")

def fprint(s):
    for i in s:
        print(i)

def bitall(N):
    ret = []
    for i in range(2**N):
        a = []
        for j in range(N):
            a.append(i%2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):
    print(" ".join([str(i) for i in s]))

def split_print_enter(s):
    print("\n".join([str(i) for i in s]))


def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l


def searchsorted(sorted_list, n, side="left"):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l


def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        
        pass
    return ret


def inv(n, mod):
    return power(n, mod - 2)


def power(n, p, mod_= mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Solution (Python):

import sys
from collections import Counter

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

    c_even = sorted(Counter(v[::2]).items(), key=lambda x: x[1],reverse=True)
    c_odd  = sorted(Counter(v[1::2]).items(), key=lambda x: x[1],reverse=True)
    if c_even[0][0] == c_odd[0][0]:
        if len(c_even) == 1:
            print(n//2)
        else:
            a = n - c_even[0][1] - c_odd[1][1]
            b = n - c_even[1][1] - c_odd[0][1]
            print(min(a,b))
    else:
        print(n - c_even[0][1] - c_odd[0][1])

if __name__ == '__main__':
    main()

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

        
import collections
cl_odd = collections.Counter(v_odd)
cl_even = collections.Counter(v_even)


if cl_odd.most_common()[0][0] != cl_even.most_common()[0][0]:
    
    print(len(v_odd) - cl_odd.most_common()[0][1] +
          len(v_even) - cl_even.most_common()[0][1])

elif cl_odd.most_common()[0][0] == cl_even.most_common()[0][0] and len(cl_odd) == 1 and len(cl_even) == 1:
    print(len(v_odd))

else:
    ans1 = 10**12
    if len(cl_odd) >= 2:
        ans1 = len(v_odd) - cl_odd.most_common()[1][1]
        ans1 += len(v_even) - cl_even.most_common()[0][1]

    ans2 = 10**12
    if len(cl_even) >= 2:
        ans2 = len(v_even) - cl_even.most_common()[1][1]
        ans2 += len(v_odd) - cl_odd.most_common()[0][1]

    print(min(ans1, ans2))

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
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()
a = []
b = []
for i in range(n):
    if i % 2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])
a = list(Counter(a).items())
b = list(Counter(b).items())
a.sort(key = lambda x:x[1], reverse=1)
b.sort(key = lambda x:x[1], reverse=1)
if len(a) == 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print(n//2)
    else:
        print(0)
elif len(a) > 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print((n-1)//2 + 1 - a[1][1])
    else:
        print((n-1)//2 + 1 - a[0][1])
elif len(a) == 1 and len(b) > 1:
    if a[0][0] == b[0][0]:
        print(n//2 - b[1][1])
    else:
        print(n//2 - b[0][1])
else:
    if a[0][0] == b[0][0]:
        print(min((n-1)//2 + 1 - a[1][1] + (n // 2) - b[0][1], (n-1)//2 + 1 - a[0][1] + (n // 2) - b[1][1]))
    else:
        print(min((n-1)//2 + 1 - a[0][1] + (n // 2) - b[0][1], (n-1)//2 + 1 - a[0][1] + (n // 2) - b[0][1]))

Solution (Python):
from collections import Counter

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

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

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

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

if even[0][0] == odd[0][0]:
    mode = max(even[0][1] + odd[1][1], even[1][1] + odd[0][1])


else:
    mode = even[0][1]
    mode += odd[0][1]
ans = n - mode
print(ans)

Solution (Python):
import sys
from collections import Counter

input = sys.stdin.readline

n = int(input())
v = list(map(int, input().split()))
arr1 = list(Counter([v[i] for i in range(n) if i % 2 == 0]).items())
arr2 = list(Counter([v[i] for i in range(n) if i % 2 == 1]).items())

arr1.append((0, 0))
arr2.append((0, 0))

arr1.sort(key=lambda x:x[1])
arr2.sort(key=lambda x:x[1])

if arr1[-1][0] == arr2[-1][0]:
    ans = min(n - arr1[-1][1] - arr2[-2][1], n - arr1[-2][1] - arr2[-1][1])
else:
    ans = n - arr1[-1][1] - arr2[-1][1]

print(ans)

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


c1=collections.Counter(odd)
values=list(c1.values())	
key=list(c1.keys())	
for i in range(len(key)):
    l1.append([key[i],values[i]])
c2=collections.Counter(even)
values=list(c2.values())	
key=list(c2.keys())	
for i in range(len(key)):
    l2.append([key[i],values[i]])
l1.sort(key=lambda x:x[1],reverse=True) 
l2.sort(key=lambda x:x[1],reverse=True) 


if l1[0][0]!=l2[0][0]:
    print(len(v)-l2[0][1]-l1[0][1])
else:
    if (len(l1)==1)and(len(l2)==1):
        print(len(v)-max(l1[0][1],l2[0][1]))
    elif len(l1)==1:
        print(len(v)-l1[0][1]-l2[1][1])
    elif len(l2)==1:
        print(len(v) - l1[1][1] - l2[0][1])
    else:
        print(min(len(v)-l1[0][1]-l2[1][1],len(v)-l1[1][1]-l2[0][1]))

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
a = [[0, i] for i in range(10 ** 5 + 1)]
b = [[0, i] for i in range(10 ** 5 + 1)]
for i in range(n):
    if i % 2 == 0:
        a[v[i]][0] += 1
    else:
        b[v[i]][0] += 1
a.sort(reverse = True)
b.sort(reverse = True)
if a[0][1] == b[0][1]:
    ans = n - max(a[0][0] + b[1][0], a[1][0] + b[0][0])
else:
    ans = n - (a[0][0] + b[0][0])
print(ans)

Solution (Python):
from collections import Counter

if __name__ == "__main__":
    n = int(input())
    v = list(map(int, input().split()))
    even = v[1::2]
    odd = v[0::2]

    even_num = Counter(even).most_common(2)
    odd_num = Counter(odd).most_common(2)
    even_num.append((0, 0))
    odd_num.append((0, 0))

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

Solution (Python):
from collections import Counter

if __name__ == "__main__":
    n = int(input())
    v = list(map(int, input().split()))
    even = v[1::2]
    odd = v[0::2]

    even_num = Counter(even).most_common(2)
    odd_num = Counter(odd).most_common(2)
    even_num.append((0, 0))
    odd_num.append((0, 0))

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

Solution (Python):
from collections import Counter

if __name__ == "__main__":
    n = int(input())
    v = list(map(int, input().split()))
    even = v[0::2]
    odd = v[1::2]

    even_num = Counter(even).most_common(2)
    odd_num = Counter(odd).most_common(2)
    even_num.append((0, 0))
    odd_num.append((0, 0))

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

Solution (Python):
from collections import Counter
n = int(input())
li = list(map(int,input().split()))
a = [l for i,l in enumerate(li) if i % 2 == 0]
b = [l for i,l in enumerate(li) if i % 2 == 1]
se_a = list(set(a))
se_b = list(set(b))
if Counter(a).most_common()[0][0] != Counter(b).most_common()[0][0]:
    a_change = len(a) - Counter(a).most_common()[0][1]
    b_change = len(b) - Counter(b).most_common()[0][1]
    print(a_change+b_change)
else:
    if len(se_a) == 1 and len(se_b) == 1:
        print(len(a))
    else:
        x = len(a) - Counter(a).most_common()[0][1] + len(b) - Counter(b).most_common()[1][1]
        y = len(a) - Counter(a).most_common()[1][1] + len(b) - Counter(b).most_common()[0][1]
        print(min(x,y))

Solution (Python):
from collections import Counter

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

v1=v[::2]
n1=len(set(v1))
v2=v[1::2]
n2=len(set(v2))

cnt1=Counter(v1)
cnt2=Counter(v2)

cnt1=cnt1.most_common()
cnt2=cnt2.most_common()

if cnt1[0][0]!=cnt2[0][0]:
  print(N-cnt1[0][1]-cnt2[0][1])
else:
  if n1==1 and n2==1:
    print(N-cnt1[0][1])
  elif n1==1:
    print(N-cnt1[0][1]-cnt2[1][1])
  elif n2==1:
    print(N-cnt1[1][1]-cnt2[0][1])
  else:
    print(N-max(cnt1[0][1]+cnt2[1][1],cnt1[1][1]+cnt2[0][1]))

Solution (Python):
from collections import Counter

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

counter_a = Counter(v[0::2])
counter_b = Counter(v[1::2])

keys_a, values_a = zip(*counter_a.most_common())
keys_b, values_b = zip(*counter_b.most_common())

if keys_a[0] != keys_b[0]:
  cnt_a = n//2 - values_a[0]
  cnt_b = n//2 - values_b[0]
  ans = cnt_a + cnt_b
else:  
  if n//2 == values_a[0]:
    ans = n//2
  elif values_a[0] + values_b[1] >= values_a[1] + values_b[0]:
    cnt_a = n//2 - values_a[0]
    cnt_b = n//2 - values_b[1]
    ans = cnt_a + cnt_b
  else:
    cnt_a = n//2 - values_a[1]
    cnt_b = n//2 - values_b[0]
    ans = cnt_a + cnt_b

print(ans)

Solution (Python):
from collections import Counter

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

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

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

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
import collections
even=collections.Counter(l[::2]).most_common(2)
odd=collections.Counter(l[1::2]).most_common(2)

if even[0][0]!=odd[0][0]:
    print(n-even[0][1]-odd[0][1])
else:
    if len(even)==1 or len(odd)==1:
        ans=n
        if len(even)==1 and len(odd)==1:
            ans=n//2
        elif len(even)==1:
            ans=min(ans,n-even[0][1]-odd[1][1])
        else:
            ans=min(ans,n-odd[0][1]-even[1][1])
        print(ans)
    else:
        print(n-max(even[0][1]+odd[1][1],even[1][1]+odd[0][1]))

Solution (Python):
N = int(input())
L = input().split(" ")

import collections

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

if even[0][0] != odd[0][0]:
    print(N - even[0][1] - odd[0][1])
else:
    
    if len(even) == 1 or len(odd) == 1:
        print(N // 2)
    else:
        print(N - max(even[0][1] + odd[1][1], even[1][1] + odd[0][1]))

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

e = A[0::2]
cme = Counter(e).most_common()
e1 = cme[0][0]
e1_num = cme[0][1]
e2_num = 0
if len(cme) > 1:
  e2 = cme[1][0]
  e2_num = cme[1][1]

o = A[1::2]
cmo = Counter(o).most_common()
o1 = cmo[0][0]
o1_num = cmo[0][1]
o2_num = 0
if len(cmo) > 1:
  o2 = cmo[1][0]
  o2_num = cmo[1][1]

if e1 != o1:
  print(N - e1_num - o1_num)
else:
  print(min(N - e1_num - o2_num, N - e2_num - o1_num))

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
odd=v[0::2]
even=v[1::2]
from collections import Counter
o=Counter(odd).most_common(2)
e=Counter(even).most_common(2)
if len(set(v))==1:
    print(int(n//2))
elif o[0][0]!=e[0][0]:
    print(n-o[0][1]-e[0][1])
else:
    if o[0][1]==e[0][1]:
        print(n-o[0][1]-max(o[1][1],e[1][1]))
    elif o[0][1]>e[0][1]:
        print(n-o[0][1]-e[1][1])
    else:
        print(n-e[0][1]-o[1][1])

Solution (Python):
import collections

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

even_num=[v[i] for i in range(0,n,2)]
odd_num=[v[i] for i in range(1,n,2)]

count_even=collections.Counter(even_num).most_common()
count_odd=collections.Counter(odd_num).most_common()




if count_even[0][0] != count_odd[0][0]:
    print(n-count_even[0][1]-count_odd[0][1])
elif len(count_even)==1 and len(count_odd)==1:
    print(n//2)
elif len(count_even)==1:
    print(n-count_odd[1][1])
elif len(count_odd)==1:
    print(n-count_even[1][1])
else:
    odd_even=count_odd[0][1]+count_even[1][1]
    even_odd=count_even[0][1]+count_odd[1][1]
    if odd_even>even_odd:
        print(n-odd_even)
    else:
        print(n-even_odd)

Solution (Python):
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
even=defaultdict(int)
odd=defaultdict(int)
for i in range(n):
  if i%2==0:
    even[a[i]]+=1
  else:
    odd[a[i]]+=1
tmp=0
v1=-1
for key in even.keys():
  if even[key]>tmp:
    tmp=even[key]
    v1=key
tmp=0
v2=-1
for key in even.keys():
  if even[key]>tmp and key!=v1:
    tmp=even[key]
    v2=key
  
tmp=0
v3=-1   
for key in odd.keys():
  if odd[key]>tmp:
    tmp=odd[key]
    v3=key
  
tmp=0
v4=-1   
for key in odd.keys():
  if odd[key]>tmp and key!=v3:
    tmp=odd[key]
    v4=key

if v1!=v3:
  V1=n//2-even[v1]
  V2=n//2-odd[v3]
  print(V1+V2)
else:
  V1=n-even[v1]-odd[v4]
  V2=n-even[v2]-odd[v3]
  print(min(V1,V2))