Problem:
 Score : 300 points    Problem Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:   For each i = 1,2,..., n-2 , a_i = a_{i+2} .  Exactly two different numbers appear in the sequence.   You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.      Constraints  2 \leq n \leq 10^5  n is even.  1 \leq v_i \leq 10^5  v_i is an integer.         Input Input is given from Standard Input in the following format:  n  v_1  v_2  ...  v_n       Output Print the minimum number of elements that needs to be replaced.        Sample Input 1 4
3 1 3 2      Sample Output 1 1  The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1 .       Sample Input 2 6
105 119 105 119 105 119      Sample Output 2 0  The sequence 105,119,105,119,105,119 is /\/\/\/.       Sample Input 3 4
1 1 1 1      Sample Output 3 2  The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.

Solution (Python):
from collections import Counter


N = int(input())
V = list(map(int, input().split()))
V1 = []
V0 = []
for i, v in enumerate(V):
    if i % 2 == 0:
        V0.append(v)
    else:
        V1.append(v)

V1C = Counter(V1)
V0C = Counter(V0)
ans = 0

if V1C.most_common()[0][0] != V0C.most_common()[0][0]:
    ans = V1C.most_common()[0][1] + V0C.most_common()[0][1]
elif len(V1C) != 1 and len(V0C) != 1:
    ans = max(V1C.most_common()[1][1] + V0C.most_common()[0][1], V1C.most_common()[0][1] + V0C.most_common()[1][1])
elif len(V1C) != 1:
    ans = V1C.most_common()[1][1] + V0C.most_common()[0][1]
elif len(V0C) != 1:
    ans = V1C.most_common()[0][1] + V0C.most_common()[1][1]
else:
    ans = N // 2

print(N - ans)

Solution (Python):
n,*v=map(int,open(0).read().split())
a,b={},{}
for i,j in zip(v[::2],v[1::2]):	
  a[i]=a.get(i,0)+1
  b[j]=b.get(j,0)+1
A=list(a.items())
B=list(b.items())
A.sort(key=lambda x: x[1])
B.sort(key=lambda x: x[1])
c,d=A[-1][1],B[-1][1]
if len(set(v))==1:
    print(n//2)
    exit()
if A[-1][0]==B[-1][0]:
    if c==d:
        c=max(A[-2][1],B[-2][1])
    elif c>d:
        d=B[-2][1]
    else:c=A[-2][1]    
print(n-c-d)

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

from collections import Counter 
def main():
    n = int(readline())
    a = [int(i) for i in readline().split()]
    odd = Counter(a[::2]).most_common(2)
    even = Counter(a[1::2]).most_common(2)
    odd.append((0, 0))
    even.append((0, 0))
    if odd[0][0] == even[0][0]:
        print(min(n-odd[1][1]-even[0][1], n-odd[0][1]-even[1][1]))
        return
    print(n-odd[0][1]-even[0][1])
if __name__ == '__main__':
    main()

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

from collections import Counter 
from collections import defaultdict
def main():
    n = int(readline())
    a = [int(i) for i in readline().split()]
    odd = Counter(a[::2]).most_common(2)
    even = Counter(a[1::2]).most_common(2)
    odd.append((-1, 0))
    even.append((-1, 0))
    if odd[0][0] == even[0][0]:
        print(min(n-odd[1][1]-even[0][1], n-odd[0][1]-even[1][1])) 
    else:
        print(n-odd[0][1]-even[0][1])
if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
from collections import Counter
v_odd=Counter([v[i] for i in range(n) if i%2==0])
v_eve=Counter([v[i] for i in range(n) if i%2==1])
v_eve[-1]=0
v_odd[-1]=0

eve=[[k,v] for k,v in v_eve.items()]
odd=[[k,v] for k,v in v_odd.items()]
eve.sort(key=lambda x:x[1])
odd.sort(key=lambda x:x[1])

if eve[-1][0]!=odd[-1][0]:
  print(n-eve[-1][1]-odd[-1][1])
else:
  ans0=n-eve[-2][1]-odd[-1][1]
  ans1=n-eve[-1][1]-odd[-2][1]
  print(min(ans0,ans1))

Solution (Python):
from collections import Counter

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

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

if odd[0][0] != even[0][0]:
    res = n - odd[0][1] - even[0][1]
elif len(odd) == 1:
    res = odd[0][1]
else:
    if odd[0][1] == even[0][1]:
        if odd[1][1] >= even[1][1]:
            res = n - odd[1][1] - even[0][1]
        else:
            res = n - odd[0][1] - even[1][1]
    elif odd[0][1] > even[0][1]:
        res = n - odd[0][1] - even[1][1]
    else:
        res = n - odd[1][1] - even[0][1]

print(res)

Solution (Python):
from collections import defaultdict

n = int(input())
data_1 = defaultdict(int)
data_2 = defaultdict(int)
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(n // 2)
    exit()
for i in range(n):
    if i % 2 == 0:
        data_1[v[i]] += 1
    else:
        data_2[v[i]] += 1
data_1 = sorted(data_1.items(), key = lambda x: x[1],reverse = True)
data_2 = sorted(data_2.items(), key = lambda x: x[1],reverse = True)

ans = n - data_1[0][1] - data_2[0][1]
if data_1[0][0] == data_2[0][0]:
    ans = n - max(data_1[0][1] + data_2[1][1], data_1[1][1] + data_2[0][1])
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
L = list(map(int, input().split()))
L1 = L[::2]
L2 = L[1::2]
c1 = Counter(L1).most_common()
c2 = Counter(L2).most_common()
if len(set(L1)) == len(set(L2)) == 1:
    if L1[0] == L2[0]:
        print(len(L1))
    else:
        print(0)
else:
    if c1[0][0] != c2[0][0]:
        print(n - c1[0][1] - c2[0][1])
    else:
        print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v1 = [v[i] for i in range(n) if i % 2 == 0]
v2 = [v[i] for i in range(n) if i % 2 != 0]

c1 = Counter(v1)
c2 = Counter(v2)

c1 = sorted(c1.items(), key=lambda x:(x[1], -x[0]), reverse=True)
c2 = sorted(c2.items(), key=lambda x:(x[1], -x[0]), reverse=True)
ans = 0
if c1[0][0] != c2[0][0]:
    if len(c1) != 1:
        for k, v in c1[1:]:
            ans += v
    if len(c2) != 1:
        for k, v in c2[1:]:
            ans += v
    print(ans)
else:
    if len(c1) == 1 and len(c2) == 1:
        ans += n // 2
    elif len(c1) == 1 and len(c2) > 1:
        ans += len(v2) - c2[1][1]
    elif len(c1) > 1 and len(c2) == 1:
        ans += len(v1) - c1[1][1]
    else:
        if c1[1][1] < c2[1][1]:
            ans += len(v1) - c1[0][1]
            ans += len(v2) - c2[1][1]
        else:
            ans += len(v1) - c1[1][1]
            ans += len(v2) - c2[0][1]
    print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ue = [0]*10**6
sita = [0]*10**6
for i in range(n):
  if i % 2 == 0:
    ue[a[i]] += 1
  else:
    sita[a[i]] += 1

m_ue = max(ue)
m_ue_idx = ue.index(m_ue)
m_sita = max(sita)
m_sita_idx = sita.index(m_sita)
if m_ue_idx != m_sita_idx:
  print(n - m_ue - m_sita)
else:
  s_ue = sorted(ue, reverse=True)
  s_sita = sorted(sita, reverse=True)
  print(min(n-s_ue[0]-s_sita[1], n-s_ue[1]-s_sita[0]))

Solution (Python):
from operator import itemgetter
n = int(input())
even = {}
odd = {}
V = list(map(int,input().split()))
for i in range(n):
    if i % 2 == 0:
        if V[i] in even:
            even[V[i]] += 1
        else:
            even[V[i]] = 1
    else:
        if V[i] in odd:
            odd[V[i]] += 1
        else:
            odd[V[i]] = 1
E = sorted(even.items(),key=itemgetter(1))
O = sorted(odd.items(),key=itemgetter(1))
a1=E.pop()
b1=O.pop()
if a1[0] != b1[0]:
    print(n-a1[1]-b1[1])
else:
    ans=a1[1]
    if E:
        a2=E.pop()
        ans=max(ans,a2[1]+b1[1])
    if O:
        b2=O.pop()
        ans = max(ans,a1[1]+b2[1])
    print(n-ans)

Solution (Python):
import math
import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
input = stdin.readline
setrecursionlimit(10**7)

def main():
    do = defaultdict(int)
    de = defaultdict(int)
    do[-1] = 0
    de[-1] = 0
    n = int(input())
    v = list(map(int,input().split()))
    for i,vi in enumerate(v):
        if i%2 == 0:
            de[vi] += 1
        else:
            do[vi] += 1
    dem = 0
    demk = 0
    dom = 0
    domk = 0
    for dek,dev in de.items():
        if dem < dev:
            demk = dek
            dem = dev
    for dok,dov in do.items():
        if dom < dov:
            domk = dok
            dom = dov

    if demk == domk:
        if list(do.values()).count(dom) > 1 or list(de.values()).count(dem) > 1:
            print(n-dem-dom)
        else:
            de[demk] = 0
            do[domk] = 0
            dxm = dem
            dem = max(de.values())
            dom = max(do.values())
            if dem > dom:
                print(n-dxm-dem)
            else:
                print(n-dxm-dom)
    else:
        print(n-dem-dom)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

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

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

c1 = Counter(v1)
c2 = Counter(v2)

c1 = c1.most_common()
c2 = c2.most_common()

if c1[0][0] != c2[0][0]:
    ans = n - c1[0][1] - c2[0][1]
else:
    if len(c2) > 1:
        choice_1 = c1[0][1] + c2[1][1]
    else:
        choice_1 = c1[0][1]
    if len(c1) > 1:
        choice_2 = c2[0][1] + c1[1][1]
    else:
        choice_2 = c2[0][1]
    ans = n - (max(choice_1, choice_2))

print(ans)

Solution (Python):
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


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

    d_odd = defaultdict(int)
    d_even = defaultdict(int)
    one_kind = True
    for i, v in enumerate(V):
        if v != V[0]: one_kind = False
        if i % 2 == 0: d_even[v] += 1
        if i % 2 != 0: d_odd[v] += 1
    if one_kind:
        print(n // 2)
        return
    
    """
    修正した結果すべての数字が一致する場合を省かないといけないのがコーナーケース
    """
    
    even_list = list(d_even.values())
    even_list.sort()
    even_max = even_list.pop()
    even_pre_max = even_list.pop() if len(even_list) > 0 else -10**10
    odd_list = list(d_odd.values())
    odd_list.sort()
    odd_max = odd_list.pop()
    odd_pre_max = odd_list.pop() if len(odd_list) > 0 else -10**10

    even_max_key = [k for k, v in d_even.items() if v == even_max]
    odd_max_key = [k for k, v in d_odd.items() if v == odd_max]
   

    if len(even_max_key) == 1 and len(odd_max_key) == 1 and even_max_key[0] == odd_max_key[0]:
        print(min(n - even_max - odd_pre_max, n - even_pre_max - odd_max))
    else:
        print(n - even_max - odd_max)

if __name__ == "__main__":
    main()

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

cnt_even = Counter(v[0::2])
cnt_odd = Counter(v[1::2])


common_even = cnt_even.most_common()
common_odd = cnt_odd.most_common()
common_even.append((0, 0))
common_odd.append((0, 0))


if common_even[0][0] != common_odd[0][0]:
    ans = n - common_even[0][1] - common_odd[0][1]
else:
    ans = min(n - common_even[1][1] - common_odd[0][1], \
              n - common_even[0][1] - common_odd[1][1])

print(ans)

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

cnt_even = Counter(v[0::2])
cnt_odd = Counter(v[1::2])


common_even = cnt_even.most_common()
common_odd = cnt_odd.most_common()
if len(common_even) == 1:   
    common_even.append((0, 0))
if len(common_odd) == 1:
    common_odd.append((0, 0))


if common_even[0][0] != common_odd[0][0]:
    ans = n - common_even[0][1] - common_odd[0][1]
else:
    ans = min(n - common_even[1][1] - common_odd[0][1], \
              n - common_even[0][1] - common_odd[1][1])

print(ans)

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

even_ocr = defaultdict(int) 
odd_ocr = defaultdict(int)  

for i in range(n // 2):
    even_ocr[v[2 * i]] += 1
    odd_ocr[v[2 * i + 1]] += 1

even_max_num = 0;  even_max_ocr = 0;
odd_max_num = 0;  odd_max_ocr = 0;
for (num, ocr) in even_ocr.items():
    if ocr > even_max_ocr:
        even_max_ocr = ocr
        even_max_num = num

for (num, ocr) in odd_ocr.items():
    if ocr > odd_max_ocr:
        odd_max_ocr = ocr
        odd_max_num = num

if even_max_num != odd_max_num:
    ans = n - even_max_ocr - odd_max_ocr
else:

    even_next_num = 0;  even_next_ocr = 0;
    odd_next_num = 0;  odd_next_ocr = 0;
    for (num, ocr) in even_ocr.items():
        if num != even_max_num and ocr > even_next_ocr:
            even_next_ocr = ocr
            even_next_num = num

    for (num, ocr) in odd_ocr.items():
        if num != odd_max_num and ocr > odd_next_ocr:
            odd_next_ocr = ocr
            odd_next_num = num

    if even_next_ocr + odd_max_ocr > even_max_ocr + odd_next_ocr:
        
        ans = n - even_next_ocr - odd_max_ocr
    else:
        ans = n - even_max_ocr - odd_next_ocr

print(ans)

Solution (Python):
import collections
n=int(input())
v=list(map(int,input().split()))
c1=collections.Counter(v[::2])
c2=collections.Counter(v[1::2])
c1_v1=c1.most_common()[0][0]
c2_v1=c2.most_common()[0][0]
c1_n1=c1.most_common()[0][1]
c2_n1=c2.most_common()[0][1]

if c1_v1!=c2_v1:
    print(n-c1_n1-c2_n1)
else:
    if c1_n1==n//2:
        if c2_n1==n//2:
            print(n//2)
        else:
            c2_n2=c2.most_common(2)[1][1]
            print(n-c1_n1-c2_n2)
    else:
        c1_n2=c1.most_common(2)[1][1]
        if c2_n1==n//2:
            print(n-c1_n2-c2_n1)
        else:
            c2_n2=c2.most_common(2)[1][1]
            print(min(n-c1_n2-c2_n1,n-c1_n1-c2_n2))

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

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
n = N//2
l = IL()

l1 = l[::2]
l2 = l[1::2]

dic1 = DD(int)
dic2 = DD(int)

for x in l1:
  dic1[x] += 1
for x in l2:
  dic2[x] += 1
  
l1 = list(dic1.items())
l2 = list(dic2.items())

l1 = sorted(l1,key=lambda x:x[1])
l2 = sorted(l2,key=lambda x:x[1])

l1_1st = l1.pop()
l2_1st = l2.pop()
l1_2nd = l2_2nd = (INF,0)

if l1:
  l1_2nd = l1.pop()
if l2:
  l2_2nd = l2.pop()
  
if l1_1st[0] != l2_1st[0]:
  print(N-l1_1st[1]-l2_1st[1])
else:
  if l1_2nd[1]>l2_2nd[1]:
    print(N-l1_2nd[1]-l2_1st[1])
  else:
    print(N-l1_1st[1]-l2_2nd[1])

Solution (Python):

import sys


def solve(n: int, v: "List[int]"):
    from collections import Counter
    a = Counter(v[::2]).most_common()
    b = Counter(v[1::2]).most_common()
    if a[0][0] != b[0][0]:
        return n - a[0][1] - b[0][1]
    a = a + [(0, 0)]
    b = b + [(0, 0)]
    return n - max(a[0][1] + b[1][1],
                   a[1][1] + b[0][1])



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    v = [int(next(tokens)) for _ in range(n)]  
    print(solve(n, v))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

Solution (Python):

import sys


def solve(n: int, v: "List[int]"):
    from collections import Counter
    a = sorted(Counter(v[::2]).items(), key=lambda x: (x[1], x[0]))
    b = sorted(Counter(v[1::2]).items(), key=lambda x: (x[1], x[0]))
    if a[-1][0] != b[-1][0]:
        return n - a[-1][1] - b[-1][1]
    a = [(0, 0)] + a
    b = [(0, 0)] + b
    return n - max(a[-1][1] + b[-2][1],
                   a[-2][1] + b[-1][1])



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    v = [int(next(tokens)) for _ in range(n)]  
    print(solve(n, v))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

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

    from collections import Counter
    a = Counter(v[::2]).most_common()
    b = Counter(v[1::2]).most_common()
    a.append((0,0))
    b.append((0,0))

    if a[0][0] != b[0][0]:
        print(n-(a[0][1]+b[0][1]))
    else:
        print(min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1])))
 
if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

n=int(input())
l=[int(i) for i in input().split()]
n=len(l)
l1=l[0::2]
l2=l[1::2]
c1=Counter(l1).most_common(2)
c2=Counter(l2).most_common(2)

if c1[0][0]!=c2[0][0]:
    ans=n-c1[0][1]-c2[0][1]
    print(int(ans))
else:
    if len(c1)==1 or len(c2)==1:
        print(n//2)
    else:
        res1=n-c1[1][1]-c2[0][1]
        res2=n-c1[0][1]-c2[1][1]
        ans=min(res1,res2)
        print(int(ans))

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
temp1=[]
temp2=[]
for i in range(0,n):
  if i%2==0:
    temp1.append(v[i])
  else:
    temp2.append(v[i])
count=0
from collections import Counter
c1=Counter(temp1)
values1,counts1=zip(*c1.most_common())
counts1=list(counts1)
mode1=counts1[0]
if len(counts1)>1:
  mode1s=counts1[1]
c2=Counter(temp2)
values2,counts2=zip(*c2.most_common())
counts2=list(counts2)
mode2=counts2[0]
if len(counts2)>1:
  mode2s=counts2[1]
if len(counts1)==1 and len(counts2)==1 and c1.most_common()[0][0]==c2.most_common()[0][0]:
  count=min(mode1,mode2)
elif c1.most_common()[0][0]==c2.most_common()[0][0]:
  if len(temp1)-mode1s>=len(temp2)-mode2s:
    count=len(temp1)-mode1+len(temp2)-mode2s
  else:
    count=len(temp2)-mode2+len(temp1)-mode1s
else:
  count=len(temp1)-mode1+len(temp2)-mode2
print(count)

Solution (Python):
from collections import Counter
import heapq

n = int(input())
v = list(map(int, input().split()))
o = [x for x in v[0:n:2]]
e = [x for x in v[1::2]]
oc = Counter(o)
ec = Counter(e)
ocfreq = [(x[1]*(-1),x[0]) for x in oc.items()]
ecfreq = [(x[1]*(-1),x[0]) for x in ec.items()]
heapq.heapify(ocfreq)
heapq.heapify(ecfreq)
o1 = heapq.heappop(ocfreq)
e1 = heapq.heappop(ecfreq)
if o1[1] != e1[1]:
    print(n+o1[0]+e1[0])
else:
    if len(ocfreq) == 0 and len(ecfreq) == 0:
        print(n//2)
    elif len(ocfreq) == 0:
        e2 = heapq.heappop(ecfreq)
        print((n//2)+e2[0])
    elif len(ecfreq) == 0:
        o2 = heapq.heappop(ocfreq)
        print((n//2)+o2[0])
    else:
        e2 = heapq.heappop(ecfreq)
        o2 = heapq.heappop(ocfreq)
        print(n+min(o1[0]+e2[0],o2[0]+e1[0]))

Solution (Python):
def main():
    n, *v = map(int, open(0).read().split())
    be = [0] * int(1e5)
    bo = [0] * int(1e5)
    for e, o in zip(*[iter(v)] * 2):
        be[e - 1] += 1
        bo[o - 1] += 1
    ve = max(be)
    vo = max(bo)
    ke = be.index(ve)
    ko = bo.index(vo)
    if ke == ko:
        be[ke] = 0
        bo[ko] = 0
        print(min(n - ve - max(bo), n - vo - max(be)))
    else:
        print(n - ve - vo)
    return


main()

Solution (Python):
from collections import Counter

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

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

V_odd = [i for i in V[::2]]
V_even = [i for i in V[1::2]]
V_odd_counter = Counter(V_odd)
V_even_counter = Counter(V_even)

vodd = V_odd_counter.most_common()
veven = V_even_counter.most_common()
vlen = len(V)
while True:
    if vodd[0][0] != veven[0][0]:
        print(vlen - vodd[0][1] - veven[0][1])
        exit()
    else:
        print(min(vlen - vodd[1][1] - veven[0][1],
                    vlen - vodd[0][1] - veven[1][1]))
        exit()

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

if len(set(v)) == 1:
    print(len(v)//2)
else:
    from collections import Counter
    ve = v[0::2]
    vec = Counter(ve).most_common()
    most_even = vec[0]

    vo = v[1::2]
    voc = Counter(vo).most_common()
    most_odd = voc[0]

    if most_even[0] == most_odd[0]:
        o2 = voc[1][1]
        e2 = vec[1][1]
        ans = n - max(most_even[1] + o2,
                      e2 + most_odd[1])
    else:
        ans = n - most_even[1] - most_odd[1]
    print(ans)

Solution (Python):
import sys
INF = 1 << 60
MOD = 10**9 + 7 
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import Counter
def resolve():
    n = int(input())
    odd = Counter()
    even = Counter()
    for i, a in enumerate(map(int, input().split())):
        if i & 1:
            odd[a] += 1
        else:
            even[a] += 1
    odd[-1] = even[-1] = 0

    res = n
    for key0, val0 in odd.most_common()[:2]:
        for key1, val1 in even.most_common()[:2]:
            if key0 != key1:
                res = min(res, n - val0 - val1)
    print(res)
resolve()

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

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

from collections import Counter

v1c = Counter(v1).most_common()
v2c = Counter(v2).most_common()

v1c.append([0,0])
v2c.append([0,0])

if v1c[0][0] == v2c[0][0]:
    ans = max(v1c[0][1] + v2c[1][1], v1c[1][1] + v2c[0][1])
else:
    ans = v1c[0][1] + v2c[0][1]

print(n-ans)

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

ki = li[::2]
gu = li[1::2]

ki.sort()
gu.sort()

from itertools import groupby

ki_li = []
gu_li = []

for key, value in groupby(ki):
    ki_li.append((key,len(list(value))))

for key, value in groupby(gu):
    gu_li.append((key,len(list(value))))

ki_li.sort(key=lambda x:(x[1]*(-1)))
gu_li.sort(key=lambda x:(x[1]*(-1)))

if ki_li[0][0] == gu_li[0][0]:
    if ki_li[0][1] > gu_li[0][1]:
        if len(gu_li) >= 2:
            ans = n-ki_li[0][1]-gu_li[1][1]
        else:
            ans = n-ki_li[0][1]
    elif ki_li[0][1] == gu_li[0][1]:
        if len(ki_li) >= 2:
            if ki_li[1][1] >= gu_li[1][1]:
                ans = n-gu_li[0][1]-ki_li[1][1]
            else:
                ans = n-ki_li[0][1]-gu_li[1][1]
        else:
            ans = n-ki_li[0][1]
    else:
        if len(ki_li) >= 2:
            ans = n-gu_li[0][1]-ki_li[1][1]
        else:
            ans = n-gu_li[0][1]
else:
    ans = n-gu_li[0][1]-ki_li[0][1]

print(ans)

Solution (Python):



from collections import Counter

N, *A = map(int, open(0).read().split())

ev = A[0::2]
od = A[1::2]

ev_C = Counter(ev)
od_C = Counter(od)


if ev == od and ev_C.most_common()[0][1] == N//2:
    print(N//2)
else:
    ans = N
    ev_common = ev_C.most_common()
    od_common = od_C.most_common()
    ev_most = ev_common[0][1]
    od_most = od_common[0][1]
    if ev_common[0][0] == od_common[0][0]:
        ev_second = ev_common[1][1]
        od_second = od_common[1][1]
        ans = min(ans, N-ev_most-od_second)
        ans = min(ans, N-ev_second-od_most)
    else:
        ans = min(ans, N-ev_most-od_most)

    print(ans)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    n=int(readline())
    v=list(map(int,readline().split()))

    cnt1=[0]*(10**5+1)
    cnt2=[0]*(10**5+1)

    for i in range(n):
        if i%2==0:
            cnt1[v[i]]+=1
        else:
            cnt2[v[i]]+=1

    max1=0
    m=0
    for i in range(1,10**5+1):
        if max1<cnt1[i]:
            max1=cnt1[i]
            m=i
    
    max2=0
    l=0
    for i in range(1,10**5+1):
        if max2<cnt2[i]:
            if i!=m:
                max2=cnt2[i]
                l=i

    max3=0
    o=0
    for i in range(1,10**5+1):
        if max3<cnt2[i]:
            max3=cnt2[i]
            o=i

    max4=0
    p=0
    for i in range(1,10**5+1):
        if max4<cnt1[i]:
            if i!=o:
                max4=cnt1[i]
                p=i

    ans=min(n-max1-max2,n-max3-max4)
    print(ans)

if __name__=="__main__":
    main()

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
from collections import Counter
even = Counter(v[::2]).most_common(2)
odd = Counter(v[1::2]).most_common(2)
even.append((0,0))
odd.append((0,0))
youso = n//2
if even[0][0] == odd[0][0]: 
    print(min(youso - even[1][1] + youso - odd[0][1],youso - odd[1][1] + youso - even[0][1]))
else: 
    print(youso - even[0][1] + youso - odd[0][1])

Solution (Python):
n = int(input())
V = list(map(int,input().split()))
Ce = {}
Co = {}
for i in range(n):
    v = V[i]
    if i%2==0:
        if v not in Ce:
            Ce[v] = 0
        Ce[v] += 1
    else:
        if v not in Co:
            Co[v] = 0
        Co[v] += 1
Ce = sorted(list(Ce.items()),key=lambda x:x[1],reverse=True)
Co = sorted(list(Co.items()),key=lambda x:x[1],reverse=True)
if len(Ce)==1 and len(Co)==1 and Ce[0][0]==Co[0][0]:
    m = n//2
else:
    if Ce[0][0]!=Co[0][0]:
        m = n-Ce[0][1]-Co[0][1]
    else:
        m1 = n-Ce[1][1]-Co[0][1]
        m2 = n-Ce[0][1]-Co[1][1]
        m = min(m1,m2)
print(m)

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

N = int(input())
lst1 = [[0, i] for i in range(10 ** 5  +10)]
lst2 = [[0, i] for i in range(10 ** 5 + 10)]

V = tuple(map(int, input().split()))

for i in range(N):
    if i % 2 == 0:
        lst1[V[i]][0] += 1
    else:
        lst2[V[i]][0] += 1

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

if lst1[0][1] != lst2[0][1]:
    print (N - lst1[0][0] - lst2[0][0])
else:
    print (N - max(lst1[0][0] + lst2[1][0], lst1[1][0] + lst2[0][0]))

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

A = V[::2]
B = V[1::2]

cntA = list(Counter(A).items())
cntB = list(Counter(B).items())

cntA.sort(key=lambda a: a[1], reverse=True)
cntB.sort(key=lambda a: a[1], reverse=True)

ans = 10**18
for a, c in cntA[:2]:
    for b, d in cntB[:2]:
        if a != b:
            ans = min(ans, N - c - d)
        elif max(len(cntA), len(cntB)) == 1:
                ans = min(ans, min(len(A), len(B)))

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
e = [a[k] for k in range(0,n,2)]
o = [a[k] for k in range(1,n,2)]
C = Counter(e).most_common()
D = Counter(o).most_common()
if C[0][0] != D[0][0]:
    print(n-C[0][1]-D[0][1])
else:
    if len(C) == len(D) == 1:
        print(n//2)
    elif len(C) == 1 and len(D) > 1:
        print(n-C[0][1]-D[1][1])
    elif len(D) == 1 and len(C) > 1:
        print(n-D[0][1]-C[1][1])
    else:
        print(n-max(D[0][1]+C[1][1],C[0][1]+D[1][1]))

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

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

cnt_o = {'*' : 0}
for vi in v[0::2]:
    key = str(vi)
    cnt_o.setdefault(key, 0)
    cnt_o[key] += 1
cnt_o = sorted(cnt_o.items(), key=lambda x: -x[1])

cnt_e = {'*' : 0}
for vi in v[1::2]:
    key = str(vi)
    cnt_e.setdefault(key, 0)
    cnt_e[key] += 1
cnt_e = sorted(cnt_e.items(), key=lambda x: -x[1])

key0, val0 = cnt_o[0]
key1, val1 = cnt_o[1]

ans = N
for key, val in cnt_e:
    if key != key0:
        ans_tmp = N - val0 - val
    else:
        ans_tmp = N - val1 - val
    
    ans = min(ans, ans_tmp)

print(ans)

Solution (Python):
from collections import Counter
N = int(input())
T = [int(hoge) for hoge in input().split()]
A = T[::2]
B = T[1::2]
Adic = Counter(A)
AA = sorted(list(Adic.items()),key = lambda x: x[1],reverse=True)
AA.append((-2,0))
Bdic = Counter(B)
BB = sorted(list(Bdic.items()),key = lambda x: x[1],reverse=True)
BB.append((-1,0))
print(N - max([AA[x][1]+BB[y][1] 
for x,y in((0,0),(1,0),(0,1),(1,1)) 
if AA[x][0] != BB[y][0] ]))

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

a = Counter(lis[::2])
b = Counter(lis[1::2])

aa = sorted(a.items(), key=lambda x:x[1], reverse=True)
bb = sorted(b.items(), key=lambda x:x[1], reverse=True)

aa.append((0, 0))
bb.append((0, 0))

if aa[0][0] == bb[0][0]:
    res = n - max(aa[0][1]+bb[1][1], aa[1][1]+bb[0][1])
else:
    res = n - aa[0][1] - bb[0][1]
print(res)

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

a = Counter(lis[::2])
b = Counter(lis[1::2])

aa = sorted(a.items(), key=lambda x:x[1], reverse=True)
bb = sorted(b.items(), key=lambda x:x[1], reverse=True)

if aa[0][0] == bb[0][0]:
    if len(aa) > 1 and len(bb) > 1:
        res = n - max(aa[0][1]+bb[1][1], aa[1][1]+bb[0][1])
    elif len(aa) == 1 and len(bb) > 1:
        res = n - aa[0][1] - bb[1][1]
    elif len(aa) > 1 and len(bb) == 1:
        res = n - aa[1][1] - bb[0][1]
    else:
        res = n - aa[0][1]
else:
    res = n - aa[0][1] - bb[0][1]

print(res)