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


def main():
    r"""
    数列 a1,a2,...,anが以下の条件を満たすとき、 /\/\/\/ と呼ぶ

        各 i=1,2...,n-2 について、ai=ai+2
        数列に現れる数はちょうど 2種類偶数長の数列

    v1,v2,...,vnが与えられます
    要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。
    書き換える要素の数は最小でいくつになるか求めてください。

    2 <= n <= 10^5, nは偶数
    1 <= vi <= 10^5, viは整数
    """
    n = int(input())
    *v, = map(int, input().split())

    ans = f(n, v)
    assert ans == simple(n, v)
    print(ans)


def simple(n, v):
    
    
    c1 = Counter(v[::2]).most_common() + [(0, 0)]
    c2 = Counter(v[1::2]).most_common() + [(0, 0)]

    if c1[0][0] == c2[0][0]:
        n_no_change = max(c1[0][1] + c2[1][1],
                          c1[1][1] + c2[0][1])
        return n - n_no_change
    else:
        return n - c1[0][1] - c2[0][1]

def f(n, v):
    """
    3 1 3 2:
        3種類
        a1=a3, a2 != a4
    """
    ans = float("inf")
    v_idx_even = []
    v_idx_odd = []
    for i, x in enumerate(v):
        if i % 2 == 0:
            v_idx_even.append(x)
        else:
            v_idx_odd.append(x)

    ve = Counter(v_idx_even)
    vo = Counter(v_idx_odd)

    if len(ve) == 1 and len(vo) == 1:
        
        ans = 0
        if ve.most_common()[0][0] == vo.most_common()[0][0]:
            ans = n // 2

    elif len(ve) == 1 or len(vo) == 1:
        
        idx = 0
        if ve.most_common()[0][0] == vo.most_common()[0][0]:
            idx = 1
        if len(ve) == 1:
            ans = n // 2 - vo.most_common()[idx][1]
        else:
            ans = n // 2 - ve.most_common()[idx][1]

    else:
        
        if ve.most_common()[0][0] != vo.most_common()[0][0]:
            ans = n - ve.most_common()[0][1] - vo.most_common()[0][1]
        else:
            ans = n - \
                max(ve.most_common()[0][1] + vo.most_common()[1][1],
                    ve.most_common()[1][1] + vo.most_common()[0][1])

    return ans


if __name__ == '__main__':
    main()

Solution (Python):
import collections
n=int(input())
v=list(map(int,input().split()))
s=[]
t=[]
for i in range(n):
    if i%2==0:
        s.append(v[i])
    else:
        t.append(v[i])
p=collections.Counter(s)
q=collections.Counter(t)
a=p.most_common()[0][0]
a1=p.most_common()[0][1]
b=q.most_common()[0][0]
b1=q.most_common()[0][1]
if a!=b:
    print(n-a1-b1)
elif len(set(s))==1 and len(set(t))==1:
            print(int(n/2))
else:
     c=p.most_common()[1][1]
     d=q.most_common()[1][1]
     print(n-max(c+b1,d+a1))

Solution (Python):
import collections

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

odd = []
even = []

for i in range(n):
	if i % 2 == 0:
		even.append(nums[i])
	else:
		odd.append(nums[i])

counter_even = collections.Counter(even)
counter_odd = collections.Counter(odd)

change_even = len(even) - counter_even.most_common()[0][1]
change_odd = len(odd) - counter_odd.most_common()[0][1]
if len(counter_even.most_common()) == 1 and len(counter_odd.most_common()) == 1 and counter_even.most_common()[0][0] == counter_odd.most_common()[0][0]:
	print(n//2)
elif counter_even.most_common()[0][0] != counter_odd.most_common()[0][0]:
	print(change_odd + change_even)
else:
	if change_even < change_odd:
		change_odd_2 = len(odd) - counter_odd.most_common()[1][1]
		print(change_odd_2 + change_even)
	elif change_even > change_odd:
		change_even_2 = len(even) - counter_even.most_common()[1][1]
		print(change_even_2 + change_odd)
	else:
		change_even_2 = len(even) - counter_even.most_common()[1][1]
		change_odd_2 = len(odd) - counter_odd.most_common()[1][1]
		if change_even_2 < change_odd_2:
			print(change_even_2 + change_odd)
		else:
			print(change_odd_2 + change_even)

Solution (Python):
from collections import Counter

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





if len(Counter(v)) > 1:
    v1 = v[0:n+1:2]
    
    
    v2 = v[1:n+2:2]
    
    v1_count = Counter(v1)
    v2_count = Counter(v2)

    v1_1st_common = v1_count.most_common(1)
    v2_1st_common = v2_count.most_common(1)
    sols = []
    
    
    n1 = v1_1st_common[0][1]
    
    if v1_1st_common[0][0] == v2_1st_common[0][0]:
        if len(v2_count) >= 2:
            v2_2nd_common = v2_count.most_common(2)
            n2 = v2_2nd_common[1][1]
        else:
            print(n//2)
    else:
        n2 = v2_1st_common[0][1]
    sols.append(n-n1-n2)

    
    n2 = v2_1st_common[0][1]
    
    if v1_1st_common[0][0] == v2_1st_common[0][0]:
         if len(v1_count) >= 2:
            v1_2nd_common = v1_count.most_common(2)
            n1 = v1_2nd_common[1][1]
         else:
            print(n//2)
    else:
        n1 = v1_1st_common[0][1]
    sols.append(n-n1-n2)
    print(min(sols))
else:
    print(n//2)

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
odd = []
even = []

cnt = 1
for i in v:
	if cnt % 2 != 0:
		odd.append(i)
	else:
		even.append(i)
	cnt += 1

x = Counter(even).most_common()
y = Counter(odd).most_common()

if x[0][0] != y[0][0]:
	print(n - x[0][1] - y[0][1])
elif len(x) == 1 and len(y) == 1:
	print(int(n/2))
else:
	print(n - max(x[0][1] + y[1][1], x[1][1]+y[0][1]))

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

k = n // 2
half = [Counter(), Counter()]
for i in range(k):
    for par in range(2):
        half[par][v[2*i+par]] += 1

cmn = [0, 0]
for par in range(2):
    cmn[par] = half[par].most_common(2)
    if len(cmn[par]) == 1:
        cmn[par].append(('ghost', 0))
if cmn[0][0][0] != cmn[1][0][0]:
    ret = n - cmn[0][0][1] - cmn[1][0][1]
else:
    ret = n - max(cmn[0][0][1] + cmn[1][1][1], cmn[0][1][1] + cmn[1][0][1])
print(ret)

Solution (Python):
import sys
import math

N = sys.stdin.readline().strip()
N = int(N)

L = sys.stdin.readline().strip().split()
L = [int(x) for x in L]

d0={}
d1={}


for i in range(0,N,2):
  a = L[i]
  c = d0.get(a)
  if c is None:
    d0[a] = 1
  else:
    d0[a] = c+1
  a = L[i+1]
  c = d1.get(a)
  if c is None:
    d1[a] = 1
  else:
    d1[a] = c+1

d01 = sorted(d0.items(), key=lambda x: -x[1])[0:2]
d11 = sorted(d1.items(), key=lambda x: -x[1])[0:2]






res = 0

if (d01[0][0] != d11[0][0]):
  res = N - (d01[0][1] + d11[0][1])
else:
  
  flag = 0
  if (len(d01)<=1):
    flag = 1
  if (len(d11)<=1):
    flag = flag + 2

  temp = 0
  if flag == 3:
    
    temp = int(N/2)
  elif flag == 1:
    temp = d01[0][1] + d11[1][1]
  elif flag == 2:
    temp = d01[1][1] + d11[0][1]
  else:
    temp = max(d01[0][1] + d11[1][1], d01[1][1] + d11[0][1])
  res = N - temp

print(res)

Solution (Python):
import collections


n = int(input())
v = list(map(int, input().split()))
odd = []
even = []


for i in range(n):
    if i % 2 == 1:
        even.append(v[i])
    else:
        odd.append(v[i])


e = collections.Counter(even)
o = collections.Counter(odd)
v_count = collections.Counter(v)
even_max = e.most_common()[0][1]
odd_max = o.most_common()[0][1]
v_max = v_count.most_common()[0][1]


if e.most_common()[0][1] == int(n/2): 
    even_max2 = 0
elif o.most_common()[0][1] == int(n/2):
    odd_max2 = 0
else:
    even_max2 = e.most_common()[1][1]
    odd_max2 = o.most_common()[1][1]

if e.most_common()[0][0] == o.most_common()[0][0]:
    if v_max == n: 
        print(int(n/2))

    elif (even_max - even_max2) <= (odd_max - odd_max2):
        print(n - even_max2 - odd_max) 
    else:
        print(n - even_max - odd_max2) 

else:
    print(n - even_max - odd_max)

Solution (Python):
import collections

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

list_e = [list[i] for i in range(0,n-1,2)]
list_o = [list[i] for i in range(1,n,2)]
e = collections.Counter(list_e)
o = collections.Counter(list_o)
mode_e=e.most_common(2)
mode_o=o.most_common(2)
mode_e.append((-1,0))
mode_o.append((-1,0))
if mode_e[0][0]==mode_o[0][0]:
    print(n-max(mode_e[0][1]+mode_o[1][1],mode_e[1][1]+mode_o[0][1]))
    
    
    
    
    
    
else:
    mode_e_value = mode_e[0][1]
    mode_o_value = mode_o[0][1]
    print(n-mode_e_value-mode_o_value)

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

v1 = [v[2*i] for i in range(int(n/2))]
v2 = [v[2*i+1] for i in range(int(n/2))]

v1.sort()
v2.sort()

v1.append(-1)
v2.append(-1)


count1= 1
maxcount1=0
maxcount1sub=0
num1=0
num1sub=0

count2=1
maxcount2=0
maxcount2sub=0
num2=0
num2sub=0

for i in range(int(n/2)):
    if v1[i] == v1[i+1]:
        count1+=1
    else:
        if maxcount1sub<=count1:
            if maxcount1<=count1:
                maxcount1sub=maxcount1
                maxcount1=count1
                num1sub=num1
                num1=v1[i]
                
            else:
                maxcount1sub=count1
                num1sub=v1[i]                       
        count1=1
        
        
for i in range(int(n/2)):
    if v2[i] == v2[i+1]:
        count2+=1
    else:
        if maxcount2sub<=count2:
            if maxcount2<=count2:
                maxcount2sub=maxcount2
                maxcount2=count2
                num2sub=num2
                num2=v2[i]
                
            else:
                maxcount2sub=count2
                num2sub=v2[i]                       
        count2=1        
        
if num1!=num2:
    print(n-maxcount1-maxcount2)
else:
    print(min(n-maxcount1-maxcount2sub, n-maxcount2-maxcount1sub))

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

Solution (Python):
n = int(input())
lst = list(map(int, input().split()))
m1 = {}
m2 = {}
for i in range(0, n, 2):
    if lst[i] in m1:
        m1[lst[i]] += 1
    else:
        m1[lst[i]] = 1
    if lst[i+1] in m2:
        m2[lst[i+1]] += 1
    else:
        m2[lst[i+1]] = 1
if max(m1, key=m1.get) != max(m2, key=m2.get):
    mm = n - max(m1.values()) - max(m2.values())
else:
    mm1 = max(m1.values())
    mm2 = max(m2.values())
    m1[max(m1, key=m1.get)] = 0
    m2[max(m2, key=m2.get)] = 0
    mm = min(n - max(m1.values()) - mm2, n - max(m2.values()) - mm1) 
print(mm)

Solution (Python):
import collections

n = int(raw_input())
v = map(int, raw_input().split())

even = [vi for i,vi in enumerate(v) if i % 2 == 0]
odd  = [vi for i,vi in enumerate(v) if i % 2 == 1]

evenc = collections.Counter(even)
oddc = collections.Counter(odd)

evenc_most_common = evenc.most_common(len(set(even))) + [(None, 0)]
oddc_most_common = oddc.most_common(len(set(odd))) + [(None, 0)]

m = []

for i in range(2):
    for j in range(2):
        if evenc_most_common[i][0] != oddc_most_common[j][0]:
            a = len(even) - evenc_most_common[i][1]
            b = len(odd) - oddc_most_common[j][1]
            m.append(a+b)
print(min(m))

Solution (Python):
import collections

N = int(input())
v = list(map(int, input().split()))
ov = collections.Counter(v)
if ov.most_common()[0][1] == len(v):
  v[0] = (v[0] + 1) % 10
  v[1] = (v[1] + 1) % 10

odd = [v[2*i+1] for i in range(int(N/2))]
even = [v[2*i] for i in range(int(N/2))]
oo = collections.Counter(odd)
oe = collections.Counter(even)
max_odd = oo.most_common()[0][0]
max_even = oe.most_common()[0][0]

if oo.most_common()[0][0] == oe.most_common()[0][0]:
  if oo.most_common()[1][1] > oe.most_common()[1][1]:
    max_odd =  oo.most_common()[1][0]
  else:
    max_even = oe.most_common()[1][0]

print(len(odd)+len(even)-odd.count(max_odd)-even.count(max_even))

Solution (Python):
N = int(input())
v = list(map(int, input().split()))
d0 = {0: 0}
d1 = {0: 0}
for j, i in enumerate(v):
    if j % 2 == 0:
        if i in d0:
            d0[i] += 1
        else:
            d0[i] = 1
    else:
        if i in d1:
            d1[i] += 1
        else:
            d1[i] = 1

l0 = sorted(d0.items(), key=lambda x: -x[1])
l1 = sorted(d1.items(), key=lambda x: -x[1])

if l0[0][0] == l1[0][0]:
    a = min(N - l0[0][1] - l1[1][1], N - l0[1][1] - l1[0][1])
    print(a)
else:
    print(N - l0[0][1] - l1[0][1])

Solution (Python):
from collections import Counter

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

first = Counter(V[::2]).most_common(2) + [(0, 0)]
latter = Counter(V[1::2]).most_common(2) + [(0, 0)]

if first[0][0] == latter[0][0]:
    X = N - first[0][1] - latter[1][1]
    Y = N - first[1][1] - latter[0][1]
    cnt = min(X, Y)
else:
    cnt = N - first[0][1] - latter[0][1]

print(cnt)

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None


def main():
    N = int(input())
    V = li_input()

    VE = V[::2]
    VO = V[1::2]

    DE = collections.defaultdict(lambda: 0)
    DO = collections.defaultdict(lambda: 0)

    for ve in VE:
        DE[ve] += 1

    for vo in VO:
        DO[vo] += 1

    E1_k, E1_v = max(DE, key=DE.get), DE[max(DE, key=DE.get)]
    O1_k, O1_v = max(DO, key=DO.get), DO[max(DO, key=DO.get)]

    DE[max(DE, key=DE.get)] = 0
    DO[max(DO, key=DO.get)] = 0

    E2_k, E2_v = max(DE, key=DE.get), DE[max(DE, key=DE.get)]
    O2_k, O2_v = max(DO, key=DO.get), DO[max(DO, key=DO.get)]

    if E1_k != O1_k:
        ans = 0
        ans += len(VE) - E1_v
        ans += len(VO) - O1_v

    else:
        if set(VE) == set(VO) and len(set(VE)) == 1:
            ans = len(VO)
        else:
            ans_prio_E = 0
            ans_prio_E += len(VE) - E1_v
            ans_prio_E += len(VO) - O2_v

            ans_prio_O = 0
            ans_prio_O += len(VE) - E2_v
            ans_prio_O += len(VO) - O1_v

            ans = min(ans_prio_E, ans_prio_O)
    
    print(ans)

main()

Solution (Python):

from collections import Counter
def main(n,v):
    odd = Counter(v[0::2]).most_common(2) + [(0,0)]
    even = Counter(v[1::2]).most_common(2) + [(0,0)]

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


if __name__ == "__main__":
    n = int(input())
    v = list(int(i) for i in input().split())
    main(n,v)

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
checklist = [0 for i in range(max(v))]
cnt = 0
for i in range(0, n, 2):
    checklist[v[i] - 1] += 1
    cnt += 1
ans = cnt - (max(checklist))
cnt2 = 0
checklist2 = [0 for i in range(max(v))]
for i in range(1, n, 2):
    checklist2[v[i] - 1] += 1
    cnt2 += 1

checklist.append(0)
checklist2.append(0)



sortchecklist = sorted(checklist)
sortchecklist2 = sorted(checklist2)

e1 = checklist.index(sortchecklist[-1])
e2 = checklist.index(sortchecklist[-2])
o1 = checklist2.index(sortchecklist2[-1])
o2 = checklist2.index(sortchecklist2[-2])

anse1 = 0
anse2 = 0
anso1 = 0
anso2 = 0

for i in range(0, n, 2):
    if v[i] - 1 != e1:
        anse1 += 1
    if v[i] - 1 != e2:
        anse2 += 1
for i in range(1, n, 2):
    if v[i] - 1 != o1:
        anso1 += 1
    if v[i] - 1!= o2:
        anso2 += 1


if e1 != o1:
    print(anse1 + anso1)
else:
    print(min(anse1 + anso2, anse2 + anso1))

Solution (Python):
from collections import Counter
def main(n,v):
    
    
    odd = Counter(v[0::2]).most_common(2) + [(0, 0)]
    even = Counter(v[1::2]).most_common(2) + [(0, 0)]

    n_half = int(n / 2)

    if (len(odd) == 1 and len(even) == 1) and odd[0][0] == even[0][0]:
        ans = n_half
    elif odd[0][0] == even[0][0]:
        ans = min(n_half - odd[0][1] + n_half - even[1][1],\
                n_half - odd[1][1] + n_half - even[0][1])
    else:
        ans = n_half - odd[0][1] + n_half - even[0][1]

    print(ans)
    

if __name__ == "__main__":
    n = int(input())
    v = list(map(int, input().split()))
    main(n,v)

Solution (Python):
import collections

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

gusuList=[]
kisuList=[]

for i in range(n):
  if(i % 2==0):
    gusuList.append(vList[i])
  else:
    kisuList.append(vList[i])



g = collections.Counter(gusuList)
gStatus=g.most_common()

k = collections.Counter(kisuList)
kStatus=k.most_common()

ans=-100
if(not gStatus[0][0]==kStatus[0][0]):
    ans=(n/2-gStatus[0][1])+(n/2-kStatus[0][1])
else:
    ans1=-101
    ans2=-102
    if(not len(kStatus)==1):
      ans1=(n/2-gStatus[0][1])+(n/2-kStatus[1][1])
    else:
      ans1=(n/2-gStatus[0][1])+n/2

    if(not len(gStatus)==1):
      ans2=(n/2-gStatus[1][1])+(n/2-kStatus[0][1])
    else:
      ans2=n/2+(n/2-kStatus[0][1])

    ans=min(ans1,ans2)

print(int(ans))

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

s = [[],[]]
for i in range(n):
    s[i % 2].append(v[i])

t = []
t.append(list(set(s[0])))
t.append(list(set(s[1])))



t_dict = [{}, {}]

for j in range(2):
    for i in range(len(t[j])):
        t_dict[j][t[j][i]] = 0

for j in range(2):
    for i in range(len(s[j])):
        t_dict[j][s[j][i]] += 1

for j in range(2):
    t_dict[j] = list(reversed(sorted(t_dict[j].items(), key=lambda x:x[1])))


if t_dict[0][0] != t_dict[1][0]:
    print( len(s[0]) - t_dict[0][0][1] + len(s[1]) - t_dict[1][0][1])
elif len(t[0]) == 1 and len(t[1]) == 1:
    print(n // 2)
elif len(t[1]) == 1:
    print(1)
else:
    print(len(s[0]) + len(s[1]) - t_dict[0][0][1] - max(t_dict[0][1][1], t_dict[1][1][1]))

Solution (Python):
from collections import Counter
def main(n,v):
    
    
    odd = Counter(v[0::2]).most_common(2) + [(0, 0)]
    even = Counter(v[1::2]).most_common(2) + [(0, 0)]

    n_half = int(n / 2)

    if (len(odd) == 1 and len(even) == 1) and odd[0][0] == even[0][0]:
        ans = n_half
    elif odd[0][0] == even[0][0]:
        ans = min(n_half - odd[0][1] + n_half - even[1][1],\
                n_half - odd[1][1] + n_half - even[0][1])
    else:
        ans = n_half - odd[0][1] + n_half - even[0][1]

    print(ans)
    return 0

if __name__ == "__main__":
    n = int(input())
    v = list(map(int, input().split()))
    main(n,v)

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

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

def makeRank(items):
	rank = {}
	for i in items:
		if i in rank.keys():
			rank[i] += 1
		else:
			rank[i] = 1
	return sorted(rank.items(), key=lambda x: -x[1])

rankOdd = makeRank(odd)
rankEven = makeRank(even)

O1 = rankOdd[0]
E1 = rankEven[0]

if len(rankOdd) == 1 and len(rankEven) == 1:
	if O1[0] == E1[0]:
		print(n // 2)
	else:
		print(0)
elif len(rankOdd) == 1:
	E2 = rankEven[1]
	if O1[0] == E1[0]:
		print(n // 2 - E2[1])
	else:
		print(n // 2 - E1[1])
elif len(rankEven) == 1:
	O2 = rankOdd[1]
	if O1[0] == E1[0]:
		print(n // 2 - O2[1])
	else:
		print(n // 2 - O1[1])
else:
	E2 = rankEven[1]
	O2 = rankOdd[1]
	if O1[0] == E1[0]:
		print(n - O1[1] - max(O2[1], E2[1]))
	else:
		print(n - O1[1] - E1[1])

Solution (Python):
from collections import Counter

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

evens = Counter(v[::2])
odds = Counter(v[1::2])

evens[0] = 0  
odds[0] = 0

keep = 0
for even in evens.most_common(2):
    for odd in odds.most_common(2):
        if even[0] != odd[0]:
            keep = max(keep, even[1] + odd[1])

print(n - keep)

Solution (Python):
import collections
n=int(input())
v = list(map(int,input().split()))
od=[]
ev=[]
k=int(n/2)
cev=0
cod=0

for i in range(0,n,2):
  ev.append(v[i])
  od.append(v[i+1])

ev.sort()
od.sort()

c=collections.Counter(ev)
d=collections.Counter(od)

e=c.most_common()[0][1]
f=d.most_common()[0][1]

if len(set(v))==1:
  e=k
  f=0
else:
  if(c.most_common()[0][0]==d.most_common()[0][0])and(c.most_common()[0][1]==d.most_common()[0][1]):
    e=max(c.most_common()[1][1],d.most_common()[1][1])
print(n-e-f)

Solution (Python):
import collections

n = input()
line = input().split()
odd = line[::2]
even = line[1::2]
o = collections.Counter(odd)
e = collections.Counter(even)
maxoddcnt = o.most_common()[0][1]
maxevencnt = e.most_common()[0][1]


if odd == even and len(o.most_common()) == 1:
    print(len(odd))
    exit(0)


if o.most_common()[0][0] == e.most_common()[0][0]:
    if len(o.most_common()) > 1 and len(e.most_common()) <= 1:
        maxoddcnt = o.most_common()[1][1]
    if len(o.most_common()) <= 1 and len(e.most_common()) > 1:
        maxevencnt = e.most_common()[1][1]
    if o.most_common()[1][1] + e.most_common()[0][1] >= o.most_common()[0][1] + e.most_common()[1][1]:
        maxoddcnt = o.most_common()[1][1]
    else: 
        maxevencnt = e.most_common()[1][1]

print(len(odd)-maxoddcnt+len(even)-maxevencnt)

Solution (Python):
import collections

N = int(input())
V = [int(_) for _ in input().split()]

def calc(vs):
    cs = collections.Counter(vs)
    cs[0] = 0
    return cs.most_common()

ve = calc(V[::2])
vo = calc(V[1::2])

result = 0

if ve[0][0] != vo[0][0]:
    result = N - ve[0][1] - vo[0][1]
else:
    result = N - max(ve[0][1] + vo[1][1], ve[1][1] + vo[0][1])

print(result)

Solution (Python):
from collections import Counter
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(i) for i in stdin.readline().rstrip().split()]

even = []
odd = []
for i in range(n):
    if i % 2 == 0:
        even.append(a[i])
    else:
        odd.append(a[i])

even_conter = Counter(even)
odd_conter = Counter(odd)

even_sorted = even_conter.most_common()
odd_sorted = odd_conter.most_common()

even_key1 = even_sorted[0][0]
even_val1 = even_sorted[0][1]
odd_key1 = odd_sorted[0][0]
odd_val1 = odd_sorted[0][1]

ans = n
if even_key1 == odd_key1:
    if len(even_sorted) >= 2:
        even_val2 = even_sorted[1][1]
        odd_val2 = odd_sorted[1][1]
        ans -= max((even_val1 + odd_val2), (odd_val1 + even_val2))
    else:
        ans -= max(even_val1, odd_val1)
else:
    ans -= (even_val1 + odd_val1)

print(ans)

Solution (Python):
from collections import Counter

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

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

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

ans = 0

if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)
    else:
        if ki[1][1] > gu[1][1]:
            ans = n - ki[1][1] - gu[0][1]
        else:
            ans = n - ki[0][1] - gu[1][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print(ans)

Solution (Python):



from collections import defaultdict, Counter


def solve():
    n = int(input())
    v = [int(i) for i in input().split()]
    d1 = Counter(v[::2])
    d2 = Counter(v[1::2])
    rd1 = defaultdict(list)
    rd2 = defaultdict(list)
    for k, v in d1.items():
        rd1[v].append(k)
    for k, v in d2.items():
        rd2[v].append(k)
    a1 = [i for i in sorted(rd1.keys(), reverse=True)]
    a2 = [i for i in sorted(rd2.keys(), reverse=True)]
    ans, half = n, (n // 2)
    la1, la2 = len(a1) - 1, len(a2) - 1
    for h in range(3):
        for i in range(3):
            ai1, ai2 = min(h, la1), min(i, la2)
            aa1, aa2 = rd1[a1[ai1]], rd2[a2[ai2]]
            s1, s2 = set(aa1), set(aa2)
            if len(s1) > 1 or len(s2) > 1 or (s1 - s2):
                ans = min(
                    ans, 2 * half - a1[ai1] - a2[ai2])
            else:
                ans = min(ans,
                          2 * half - a1[ai1] - a2[ai2] + min(a1[ai1], a2[ai2]))
    print(ans)


if __name__ == "__main__":
    solve()

Solution (Python):



from collections import defaultdict, Counter


def solve():
    n = int(input())
    v = [int(i) for i in input().split()]
    d1 = Counter(v[::2])
    d2 = Counter(v[1::2])
    rd1 = defaultdict(list)
    rd2 = defaultdict(list)
    for k, v in d1.items():
        rd1[v].append(k)
    for k, v in d2.items():
        rd2[v].append(k)
    a1 = [i for i in sorted(rd1.keys(), reverse=True)]
    a2 = [i for i in sorted(rd2.keys(), reverse=True)]
    ans, half = n, (n // 2)
    la1 = len(a1) - 1
    la2 = len(a2) - 1
    for h in range(3):
        for i in range(3):
            ai1, ai2 = min(h, la1), min(i, la2)
            aa1, aa2 = rd1[a1[ai1]], rd2[a2[ai2]]
            s1, s2 = set(aa1), set(aa2)
            if len(s1) > 1 or len(s2) > 1 or (s1 - s2):
                ans = min(
                    ans, 2 * half - a1[ai1] - a2[ai2])
            else:
                ans = min(ans,
                          2 * half - a1[ai1] - a2[ai2] + min(a1[ai1], a2[ai2]))
    print(ans)


if __name__ == "__main__":
    solve()

Solution (Python):



from collections import defaultdict, Counter


def solve():
    n = int(input())
    v = [int(i) for i in input().split()]
    d1 = Counter(v[::2])
    d2 = Counter(v[1::2])
    rd1 = defaultdict(list)
    rd2 = defaultdict(list)
    for k, v in d1.items():
        rd1[v].append(k)
    for k, v in d2.items():
        rd2[v].append(k)
    a1 = [i for i in sorted(rd1.keys(), reverse=True)]
    a2 = [i for i in sorted(rd2.keys(), reverse=True)]
    ans = n
    la1 = len(a1) - 1
    la2 = len(a2) - 1
    for h in range(3):
        for i in range(3):
            aa1 = rd1[a1[min(h, la1)]]
            aa2 = rd2[a2[min(i, la2)]]
            s1 = set(aa1)
            s2 = set(aa2)
            if len(s1) > 1 or len(s2) > 1 or (s1 - s2):
                ans = min(
                    ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)])
            else:
                ans = min(ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)]
                          + min(a1[min(h, la1)], a2[min(i, la2)]))
    print(ans)


if __name__ == "__main__":
    solve()

Solution (Python):



from collections import defaultdict


def solve():
    n = int(input())
    v = [int(i) for i in input().split()]
    d1 = defaultdict(int)
    d2 = defaultdict(int)
    for i in range(n):
        if i % 2 == 0:
            d1[v[i]] += 1
        else:
            d2[v[i]] += 1
    rd1 = defaultdict(list)
    rd2 = defaultdict(list)
    for k, v in d1.items():
        rd1[v].append(k)
    for k, v in d2.items():
        rd2[v].append(k)
    a1 = [i for i in sorted(rd1.keys(), reverse=True)]
    a2 = [i for i in sorted(rd2.keys(), reverse=True)]
    ans = n
    la1 = len(a1) - 1
    la2 = len(a2) - 1
    for h in range(3):
        for i in range(3):
            aa1 = rd1[a1[min(h, la1)]]
            aa2 = rd2[a2[min(i, la2)]]
            s1 = set(aa1)
            s2 = set(aa2)
            if len(s1) > 1 or len(s2) > 1 or (s1 - s2) or (s2 - s1):
                ans = min(
                    ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)])
            else:
                ans = min(ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)]
                          + min(a1[min(h, la1)], a2[min(i, la2)]))
    print(ans)


if __name__ == "__main__":
    solve()

Solution (Python):
import math
import collections

n = int(input())
nums = list(map(int, input().split()))
ans1 = 0
ans2 = 0

even_list = nums[0::2]
odd_list = nums[1::2]

even_mod = collections.Counter(even_list).most_common(2)
odd_mod = collections.Counter(odd_list).most_common(2)

if even_mod[0][0] == odd_mod[0][0]:
    if len(even_mod) == 1:
        print(int(n / 2))
    else:
        print(n - even_mod[0][1] - max(even_mod[1][1], odd_mod[1][1]))
elif even_mod[0][0] != odd_mod[0][0]:
    for i in range(0, len(nums)):
        if i % 2 == 0:
            if nums[i] != even_mod[0][0]:
                ans1 += 1
        else:
            if nums[i] != odd_mod[0][0]:
                ans1 += 1
    print(ans1)
else:
    for i in range(0, len(nums)):
        if i % 2 == 0:
            if nums[i] != even_mod[0][0]:
                ans1 += 1
        else:
            if nums[i] != odd_mod[1][1]:
                ans1 += 1

    for i in range(0, len(nums)):
        if i % 2 == 0:
            if nums[i] != even_mod[1][1]:
                ans2 += 1
        else:
            if nums[i] != odd_mod[0][0]:
                ans2 += 1
    if ans1 < ans2:
        print(ans1)
    else:
        print(ans2)