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):
n = int(input())
v = list(map(int, input().split()))
o = []
e = []
for i, va in enumerate(v):
    if i % 2 == 0:
        o.append(va)
    else:
        e.append(va)
import collections
o = collections.Counter(o).most_common()
e = collections.Counter(e).most_common()
if o[0][0] == e[0][0]:
    if len(o) == 1 and len(e) == 1:
        print(min(o[0][1], e[0][1]))
    elif len(o) == 1:
        print(n - o[0][1] - e[1][1])
    elif len(e) == 1:
        print(n - o[1][1] - e[0][1])
    else:
        print(n - o[0][1] - max(o[1][1], e[1][1]))
else:
    print(n - o[0][1] - e[0][1])

Solution (Python):


import collections
import itertools
import sys


def getint(): return int(input())
def getints(): return list(map(int, input().split()))

n = getint()
vs = getints()


even = vs[0::2]
odds = vs[1::2]

even_counter = collections.Counter()
odds_counter = collections.Counter()

for e in even:
    even_counter[e] += 1
for e in odds:
    odds_counter[e] += 1

even_counter = list(sorted(list(even_counter.items()), key=lambda s: -s[1]))
odds_counter = list(sorted(list(odds_counter.items()), key=lambda s: -s[1]))

if len(even_counter) < 2:
    even_counter.append((-1, 0))
if len(odds_counter) < 2:
    odds_counter.append((-2, 0))

res = 2 * n
for i in range(2):
    for j in range(2):
        even_val = even_counter[i][0]
        odds_val = odds_counter[j][0]
        if even_val == odds_val:
            continue
        tmp1 = len(list(filter(lambda s: s != even_val, even)))
        tmp2 = len(list(filter(lambda s: s != odds_val, odds)))
        res = min(res, tmp1 + tmp2)

print(res)

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

a = Counter(v[0::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[0][1]+b[1][1]),n-(a[1][1]+b[0][1])))

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

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

i=0
while i<len(even):
    e=even[i]
    o=odd[i]
    if e[0]!=o[0]:
        if e[1]>=o[1]:
            ans=n-e[1]-odd[0][1]
            break
        else:
            ans=n-o[1]-even[0][1]
            break
    i+=1
else:
    ans=n-even[0][1] if len(even)==1 else n-even[0][1]-odd[1][1]
print(ans)

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

a = Counter(v[0::2]).most_common()
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):
n = int(input())
v = list(map(int,input().split()))

vo = [0] * (10**5 + 1)
ve = [0] * (10**5 + 1)

for i in range(n):
    if (i+1) % 2 == 0:
        ve[v[i]] += 1
    else:
        vo[v[i]] += 1
ve1 = sorted(ve, reverse = True)
vo1 = sorted(vo, reverse = True)
if vo.index(max(vo)) != ve.index(max(ve)):
    print(n - max(vo) - max(ve))
    
elif max(vo) > max(ve):    
    print(n - max(vo) - ve1[1])
elif max(vo) < max(ve):
    print(n - max(ve) - vo1[1])
else:
    print(n - max(vo) - max(ve1[1], vo1[1]))

Solution (Python):

import math
import sys
import collections
n = int(input())
vvv = list(map(int,input().split()))
odd = [vvv[i] for i in range(1,n,2)]
even = [vvv[i] for i in range(0,n,2)]
c_o = collections.Counter(odd)
_, odd_c = zip(*c_o.most_common())
c_e = collections.Counter(even)
_, even_c = zip(*c_e.most_common())
if c_o.most_common()[0][0] == c_e.most_common()[0][0]:
  print(min(sum(list(odd_c)[1:]) + list(even_c)[0] + sum(list(even_c)[2:]),
      sum(list(even_c)[1:]) + list(odd_c)[0] + sum(list(odd_c)[2:])))
  sys.exit()
ans = sum(list(odd_c)[1:]) + sum(list(even_c)[1:])
print(ans)

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

vo = [0]*(10**5+1)
ve = [0]*(10**5+1)

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

if vo.index(max(vo)) == ve.index(max(ve)):
    ans1 = sum(vo) - max(vo) + sum(ve) - sorted(ve)[-2]
    ans2 = sum(vo) - sorted(vo)[-2] + sum(ve) - max(ve)
    print(min(ans1, ans2))
else:
    print(sum(vo) - max(vo) + sum(ve) - max(ve))

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

vo=[0]*(10**5+1)
ve=[0]*(10**5+1)

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


if vo.index(max(vo))==ve.index(max(ve)):
    ans1 = sum(vo)-max(vo)+sum(ve)-sorted(ve)[-2]
    ans2 = sum(vo)-sorted(vo)[-2]+sum(ve)-max(ve)
    print(min(ans1,ans2))
else:
    print(sum(vo)-max(vo)+sum(ve)-max(ve))

Solution (Python):
from collections import Counter
N = int(input())
v = list(map(int, input().split()))
e = []
o = []
for idx, i in enumerate(v):
    if idx % 2 == 0:
        o.append(i)
    else:
        e.append(i)

e = Counter(e).most_common()
o = Counter(o).most_common()
e1 = e[0][1]
e2 = e[1][1] if len(e) > 1 else 0
o1 = o[0][1]
o2 = o[1][1] if len(o) > 1 else 0
cnt = 0
if e[0][0] != o[0][0]:
    cnt = N - e1 - o1
else:
    o = N - e1 - o2
    e = N - e2 - o1
    cnt = min(o, e)
print(cnt)

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

def mpsort(m):
	ary = sorted([[k, v] for (k, v) in m.items()], key=itemgetter(1), reverse=True)
	if len(ary) == 1:
		return ary[0], [0, 0]
	return ary[0], ary[1]

def main():
	n = int(input().strip())
	v = list(map(int, input().strip().split()))
	gu = [i for i in v[::2]]
	ki = [i for i in v[1::2]]
	gu_map = Counter(gu)
	ki_map = Counter(ki)
	s = n//2
	
	gu_f, gu_s = mpsort(gu_map)
	ki_f, ki_s = mpsort(ki_map)

	if gu_f[0] == ki_f[0]:
			print(min(s - gu_s[1] + s - ki_f[1],
					  s - gu_f[1] + s - ki_s[1]))
	else:
		print(s - gu_f[1] + s - ki_f[1])

if __name__ == '__main__':
	main()

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

def mpsort(m):
	ary = sorted([[k, v] for (k, v) in m.items()], key=itemgetter(1), reverse=True)
	if len(ary) == 1:
		return ary[0], [0, 0]
	return ary[0], ary[1]

def main():
	n = int(input().strip())
	v = list(map(int, input().strip().split()))
	gu = [i for i in v[::2]]
	ki = [i for i in v[1::2]]
	gu_map = Counter(gu)
	ki_map = Counter(ki)
	gu_sum = sum(gu_map.values())
	ki_sum = sum(ki_map.values())
	
	gu_f, gu_s = mpsort(gu_map)
	ki_f, ki_s = mpsort(ki_map)

	if gu_f[0] == ki_f[0]:
			print(min(gu_sum - gu_s[1] + ki_sum - ki_f[1],
					  gu_sum - gu_f[1] + ki_sum - ki_s[1]))
	else:
		print(gu_sum - gu_f[1] + ki_sum - ki_f[1])
		
if __name__ == '__main__':
	main()

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
even = []
odd = []
for i in range(n//2):
  even.append(v[2*i]-1)
  odd.append(v[2*i+1]-1)

EVEN = [[i,0] for i in range(100000)]
ODD = [[i,0] for i in range(100000)]
for i in range(n//2):
  EVEN[even[i]][1] += 1
  ODD[odd[i]][1] += 1
maxE = max(EVEN, key=lambda x:x[1])
maxO = max(ODD,  key=lambda x:x[1])

if maxE[0] != maxO[0]:
  print( n - maxE[1] - maxO[1] )
else:
  del EVEN[maxE[0]]
  del ODD[maxO[0]]
  canE = maxE[1] + max(ODD,  key=lambda x:x[1])[1]
  canO = maxO[1] + max(EVEN, key=lambda x:x[1])[1]
  if canE > canO:
    print( n - canE )
  else:
    print( n - canO )

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

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



_ksum = 0
_gsum = 0

for i in range(N):
    if i % 2 == 0:
        k[A[i]][0] += 1
        k[A[i]][1] = A[i]
        _ksum += 1
    else:
        g[A[i]][0] += 1
        g[A[i]][1] = A[i]
        _gsum += 1

_kmax = 0
_gmax = 0

b_k = k.copy()
b_g = g.copy()

b_k.sort()
b_g.sort()

if b_k[-1][1] != b_g[-1][1]:
    print(_ksum-b_k[-1][0]+_gsum-b_g[-1][0])

else:
    print(min(_ksum-b_k[-1][0]+_gsum-b_g[-2][0], _ksum-b_k[-2][0]+_gsum-b_g[-1][0]))

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

v0 = v[::2]
v1 = v[1::2]
counter0 = [0] * (10 ** 5 + 1)
counter1 = [0] * (10 ** 5 + 1)

for vi in v0:
    counter0[vi] += 1
for vi in v1:
    counter1[vi] += 1

sorted_counter0 = sorted(counter0, reverse=True)
sorted_counter1 = sorted(counter1, reverse=True)

if counter0.index(max(counter0)) == counter1.index(max(counter1)):
    print(min(len(v) - sorted_counter0[0] - sorted_counter1[1],
              len(v) - sorted_counter0[1] - sorted_counter1[0]))
else:
    print(len(v) - sorted_counter0[0] - sorted_counter1[0])

Solution (Python):
from collections import Counter


def solve(V):
    n = len(V)
    ac = Counter(V[::2]).most_common(2)
    bc = Counter(V[1::2]).most_common(2)
   
    if ac[0][0] != bc[0][0]:
        return n - ac[0][1] - bc[0][1]
    else:
        if len(bc) == 1 or len(ac) == 1:
            return n // 2
        else:
            return n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])


if __name__ == "__main__":
    n = int(input())
    l = input()

    print(solve(l.split(" ")))

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

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

l0.sort()
l1.sort()




memo0 = [[1, l0[0]]]
memo1 = [[1, l1[0]]]
for i in range(1, n//2):
    if memo0[-1][1] == l0[i]:
        memo0[-1][0] += 1
    else:
        memo0.append([1, l0[i]])

    if memo1[-1][1] == l1[i]:
        memo1[-1][0] += 1
    else:
        memo1.append([1, l1[i]])

memo0.sort(reverse=True)
memo1.sort(reverse=True)

memo0.append([0, -1])
memo1.append([0, -1])




if memo0[0][1]!=memo1[0][1]:
    print(n-memo0[0][0]-memo1[0][0])
else:
    ans1 = n- memo0[0][0]-memo1[1][0]
    ans2 = n- memo0[1][0]-memo1[0][0]
    print(min(ans1, ans2))

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

kisuus = [a_list[i] for i in range(0,N,2)]
guusuus = [a_list[i] for i in range(1,N,2)]

n_kisuu = len(kisuus)
n_guusuus = len(guusuus)

from collections import Counter
kisuu_cnter = Counter(kisuus)
guusuu_cnter = Counter(guusuus)

def func(cnter):
    tmp = [(k,v) for k, v in sorted(cnter.items(), key=lambda x: -x[1])] + [(-1,0)]
    tmp0 = tmp[0]
    tmp1 = tmp[1]
    return tmp0,tmp1

(k0,kcnt0),(k1,kcnt1) = func(kisuu_cnter)
(g0,gcnt0),(g1,gcnt1) = func(guusuu_cnter)
kcnt0 = n_kisuu-kcnt0
kcnt1 = n_kisuu-kcnt1
gcnt0 = n_guusuus-gcnt0
gcnt1 = n_guusuus-gcnt1

if k0 != g0:
    print(kcnt0+gcnt0)
else:
    print(min(kcnt0+gcnt1,kcnt1+gcnt0))

Solution (Python):
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    V = string_to_int(inputs[0])
    N = len(V)
    N_HALF = N // 2
    counts = {
        0: {},
        1: {}
    }
    for i, v in enumerate(V):
        key = i % 2
        if v in counts[key]:
            counts[key][v] += 1
        else:
            counts[key][v] = 1

    counts_sorted = []
    for i in range(2):
        counts_sorted.append(
            sorted(list(counts[i].items()), key=lambda x: x[1], reverse=True)
        )

    def count_replace(first, first_i, second, second_i):
        replace_count = N_HALF - counts_sorted[first][first_i][1]
        replace_count += N_HALF - counts_sorted[second][second_i][1]
        return replace_count

    if counts_sorted[0][0] == counts_sorted[1][0]:
        len_0 = len(counts_sorted[0])
        len_1 = len(counts_sorted[1])
        if len_0 == 1 and len_1 == 1:
            return N_HALF
        elif len_0 == 1:
            return N_HALF - counts_sorted[1][1][1]
        elif len_1 == 1:
            return N_HALF - counts_sorted[0][1][1]
        else:
            cs = []
            cs.append(count_replace(0, 0, 1, 1))
            cs.append(count_replace(0, 1, 1, 0))
            return min(cs)

    else:
        return count_replace(0, 0, 1, 0)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Solution (Python):
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    V = string_to_int(inputs[0])
    N = len(V)
    N_HALF = N // 2
    counts = {
        0: {},
        1: {}
    }
    for i, v in enumerate(V):
        key = i % 2
        if v in counts[key]:
            counts[key][v] += 1
        else:
            counts[key][v] = 1

    counts_sorted = []
    for i in range(2):
        counts_sorted.append(
            sorted(list(counts[i].items()), key=lambda x: x[1], reverse=True)
        )

    def count_replace(first, first_i, second, second_i):
        replace_count = N_HALF - counts_sorted[first][first_i][1]
        replace_count += N_HALF - counts_sorted[second][second_i][1]
        return replace_count

    if counts_sorted[0][0] == counts_sorted[1][0]:
        len_0 = len(counts_sorted[0])
        len_1 = len(counts_sorted[1])
        if len_0 == 1 and len_1 == 1:
            return N_HALF
        elif len_0 == 1:
            return N_HALF - counts_sorted[1][1][1]
        elif len_1 == 1:
            return N_HALF - counts_sorted[0][1][1]
        else:
            cs = []
            cs.append(count_replace(0, 0, 1, 1))
            cs.append(count_replace(0, 1, 1, 0))
            return min(cs)

    else:
        return count_replace(0, 0, 1, 0)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Solution (Python):
from collections import Counter
n = int(input())

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

lst_odd = []
lst_eve = []

for i in range(n):
    if i%2 == 0:
        lst_odd.append(lst[i])
    else:
        lst_eve.append(lst[i])

cnt = Counter(lst_odd)
mod = cnt.most_common()
e1 = mod[0][0]
if len(mod) > 1:
    e2 = mod[1][0]
else:
    e2 = 0

cnt = Counter(lst_eve)
mod = cnt.most_common()
o1 = mod[0][0]
if len(mod) > 1:
    o2 = mod[1][0]
else:
    o2 = 0

if e1 != o1:
    ans = n - lst_odd.count(e1) - lst_eve.count(o1)
else:
    ans = n - max((lst_odd.count(e1) + lst_eve.count(o2)),(lst_odd.count(e2) + lst_eve.count(o1)))

print(ans)

Solution (Python):
from collections import Counter

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

v_odd = v[1::2]
v_even = v[0::2]

v_odd_mc = Counter(v_odd).most_common()
v_even_mc = Counter(v_even).most_common()

v_odd_mc.append((0, 0))
v_even_mc.append((0, 0))

if v_odd_mc[0] != v_even_mc[0]:
    print(n-v_odd_mc[0][1]-v_even_mc[0][1])
else:
    print(n - max(v_odd_mc[0][1] + v_even_mc[1][1], v_odd_mc[1][1]+v_even_mc[0][1]))

Solution (Python):
from collections import Counter
 
n = int(input())
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()
 
v_odd_common.append((0,0))
v_even_common.append((0,0))
 
if v_odd_common[0] != v_even_common[0]:
    print(n-v_odd_common[0][1]-v_even_common[0][1])
else:
    print(min(n-v_odd_common[0][1]-v_even_common[1][1],n-v_odd_common[1][1]-v_even_common[0][1]))

Solution (Python):
from collections import Counter
n=int(input())
w=input().split()
a=Counter(w[::2]).most_common(2)
b=Counter(w[1::2]).most_common(2)
if a[0][0]!=b[0][0]:
	stay=a[0][1]+b[0][1]
else:
	if a[0][1]==b[0][1]==n//2:
		stay=a[0][1]
	elif a[0][1]>b[0][1]:
		stay=a[0][1]+b[1][1]
	elif a[0][1]<b[0][1]:
		stay=a[1][1]+b[0][1]
	else:
		if a[1][1]>=b[1][1]:
			stay=a[1][1]+b[0][1]
		else:
			stay=a[0][1]+b[1][1]
print(n-stay)

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
v_odd,v_eve = v[0::2],v[1::2]
lvo,lve = len(v_odd),len(v_eve)

v_odd_s = {}
for c in v_odd:v_odd_s[c] = v_odd_s.get(c,0) + 1
v_odd_l = []
for c in v_odd_s.keys():v_odd_l.append([c,v_odd_s[c]])
sorted_v_odd_l = sorted(v_odd_l, key=lambda x: x[1],reverse = True)

v_eve_s = {}
for c in v_eve:v_eve_s[c] = v_eve_s.get(c,0) + 1
v_eve_l = []
for c in v_eve_s.keys():v_eve_l.append([c,v_eve_s[c]])
sorted_v_eve_l = sorted(v_eve_l, key=lambda x: x[1],reverse = True)

if (len(sorted_v_odd_l) == 1) or (len(sorted_v_eve_l) == 1):
    if (len(sorted_v_odd_l) == 1) and (len(sorted_v_eve_l) == 1):
        if sorted_v_odd_l[0][0] != sorted_v_eve_l[0][0]:print(0)
        else:print(n//2)
    else:
        if len(sorted_v_odd_l) == 1:
            if sorted_v_odd_l[0][0] != sorted_v_eve_l[0][0]:print(n//2-sorted_v_eve_l[0][1])
            else:print(0 + n//2-sorted_v_eve_l[1][1])
        else:
            if sorted_v_odd_l[0][0] != sorted_v_eve_l[0][0]:print(n//2-sorted_v_odd_l[0][1]) 
            else:print(0 + n//2-sorted_v_odd_l[1][1])
else:
    if sorted_v_odd_l[0] == sorted_v_eve_l[0]:
        p1 = lvo + lve - sorted_v_eve_l[0][1] - sorted_v_odd_l[1][1]
        p2 = lvo + lve - sorted_v_eve_l[1][1] - sorted_v_odd_l[0][1]
        p3 = p4 = -1
    else:
        p1 = lvo + lve - sorted_v_eve_l[0][1] - sorted_v_odd_l[0][1]
        p2 = lvo + lve - sorted_v_eve_l[1][1] - sorted_v_odd_l[0][1]
        p3 = lvo + lve - sorted_v_eve_l[0][1] - sorted_v_odd_l[1][1]
        p4 = lvo + lve - sorted_v_eve_l[1][1] - sorted_v_odd_l[1][1]
    for i in sorted([p1,p2,p3,p4]):
        if i>=0:
            print(i)
            break

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

num = 100001


even = [[0,i] for i in range(num)]
odd = [[0,i] for i in range(num)]

for i in range(n):
    if i%2 == 0:
        even[v[i]][0] += 1
    else:
        odd[v[i]][0] += 1
        
odd.sort(key=lambda x: -x[0])
even.sort(key=lambda x: -x[0])

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

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
v1 = {}
for i in range(0, n, 2):
    v1.setdefault(v[i], 0)
    v1[v[i]] += 1
v2 = {}
for i in range(1, n, 2):
    v2.setdefault(v[i], 0)
    v2[v[i]] += 1
v1 = [(i, j) for i, j in v1.items()]
v2 = [(i, j) for i, j in v2.items()]
v1.sort(key = lambda x: x[1])
v2.sort(key = lambda x: x[1])
if v1[-1][0] != v2[-1][0]:
    print(n - v1[-1][1] - v2[-1][1])
else:
    if len(v1) == 1:
        if len(v2) == 1:
            print(n // 2)
        else:
            print(n - v1[-1][1] - v2[-2][1])
    elif len(v2) == 1:
        print(n - v1[-2][1] - v2[-1][1])
    else:
        print(min(n - v1[-1][1] - v2[-2][1], (n - v1[-2][1] - v2[-1][1])))

Solution (Python):
import collections
def main():


    N = int(input())
    V = list(map(int,input().split()))
    V1 = V[0::2]
    V2 = V[1::2]
    count = 0

    fre1 = collections.Counter(V1).most_common(2)
    fre2 = collections.Counter(V2).most_common(2)
    

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


    if fre1[0][0] != fre2[0][0]:

        count += len(V1)-fre1[0][1]
        count += len(V2)-fre2[0][1]
        print(count)
    elif len(V1)-fre1[0][1] == len(V2)-fre2[0][1]:
        bigger = max(fre1[1][1],fre2[1][1])
        count += len(V1)-bigger
        count += len(V1)-fre1[0][1]
        print(count)
    else:
        if len(V1)-fre1[0][1] < len(V2)-fre2[0][1]:
            count += len(V1)-fre1[0][1]
            count += len(V2)-fre2[1][1]
            print(count)
        else:
            count += len(V1)-fre1[1][1]
            count += len(V2)-fre2[0][1]
            print(count)

        






if __name__== "__main__":
    main()

Solution (Python):

import collections
n = int(input())
lst = list(map(int, input().split()))
lst1 = lst[::2]
lst2 = lst[1::2]
dct1 = sorted(dict(collections.Counter(lst1)).items(), key=lambda x:-x[1])
dct2 = sorted(dict(collections.Counter(lst2)).items(), key=lambda x:-x[1])


ans = 0
if (len(dct1) == 1 and len(dct2) == 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = dct1[0][1]
	else:
		ans = 0
elif (len(dct1) == 1 and len(dct2) > 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = n // 2 - dct2[1][1]
	else:
		ans = n // 2 - dct2[0][1]
elif (len(dct2) == 1 and len(dct1) > 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = n // 2 - dct1[1][1]
	else:
		ans = n // 2 - dct1[0][1]
elif (len(dct1) > 1 and len(dct2) > 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = n - max(dct1[0][1] + dct2[1][1], dct1[1][1] + dct2[0][1])
	else:
		ans = n - dct1[0][1] - dct2[0][1]
print(ans)

Solution (Python):
from collections import Counter


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


if len(set(lst_v)) == 1:
    ans = n // 2
else:
    lst_odd = lst_v[::2]
    lst_even = lst_v[1::2]
    cnt_odd = sorted(Counter(lst_odd).items(), key=lambda x: -x[1])
    cnt_even = sorted(Counter(lst_even).items(), key=lambda x :-x[1])

    if cnt_odd[0][0] == cnt_even[0][0]:
        rem_number = max(cnt_odd[0][1] + cnt_even[1][1], cnt_odd[1][1] + cnt_even[0][1])
    else:
        rem_number = cnt_odd[0][1] + cnt_even[0][1]
    sum_odd = sum(t[1] for t in cnt_odd)
    sum_even = sum(t[1] for t in cnt_even)
    ans = sum_odd + sum_even - rem_number


print(ans)

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

set_even = set(v[0::2]) 
set_odd = set(v[1::2]) 
dic_even={i:0 for i in set_even}
dic_odd={i:0 for i in set_odd}

for i in range(n):
  if i%2==0:
    dic_even[v[i]]+=1
  else:
    dic_odd[v[i]]+=1
    
even = sorted(dic_even.items(),key = lambda x: x[1],reverse=True)
odd = sorted(dic_odd.items(),key = lambda x: x[1],reverse=True)
ans = 0

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

Solution (Python):

import sys, math, fractions, itertools, collections


def solve(n: int, v: "List[int]"):
    o = v[1::2]
    e = v[::2]
    oc = collections.Counter(o).most_common()
    ec = collections.Counter(e).most_common()
    if len(oc) > 1:
        om1, om2 = oc[0], oc[1]
    else:
        om1, om2 = oc[0], (-1, 0)
    if len(ec) > 1:
        em1, em2 = ec[0], ec[1]
    else:
        em1, em2 = ec[0], (-1, 0)
    if om1[0] != em1[0]:
        print(n - om1[1] - em1[1])
    else:
        print(min(n-om1[1]-em2[1], n-om2[1]-em1[1]))
    return



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) ]  
    solve(n, v)

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).most_common()
c2 = Counter(v2).most_common()
c1.append((0, 0))
c2.append((0, 0))

if c1[0][0] != c2[0][0]:
    ans = n // 2 - c1[0][1] + n // 2 - c2[0][1]
else:
    ans = min(n // 2 - c1[0][1] + n // 2 - c2[1][1], n // 2 - c1[1][1] + n // 2 - c2[0][1])

print(ans)

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
v1 = v[::2]
v2 = v[1::2]
v1_N = Counter(v1).most_common()
v2_N = Counter(v2).most_common()
if len(v1_N) == 1 and len(v2_N) == 1 and v1_N[0][0] == v2_N[0][0]:
    print(int(n/2))
elif v1_N[0] == v2_N[0]:
    print(min(n-v1_N[0][1]-v2_N[1][1],n-v1_N[1][1]-v2_N[0][1]))
else:
    print(n-v1_N[0][1]-v2_N[0][1])

Solution (Python):
from collections import Counter 
n = int(input())
v = list(map(int,input().split()))
 
odd = []
even = []
for i in range(n//2):
	odd.append(v[2*i+1])
	even.append(v[2*i])

odd = sorted(odd)
even = sorted(even)
ac = Counter(odd).most_common(2)
bc = Counter(even).most_common(2)
def cnt(X):
	count = 0
	ans = 0
	for i in range(len(X)-1):
		if X[i+1] == X[i]:
			count += 1
			ans = max(ans,count)
		else:
			count = 0
	return ans+1
            
if ac[0][0] != bc[0][0]:
  print(len(v)-cnt(odd)-cnt(even))
elif len(ac) == 1 and len(bc) == 1:
	print(n//2)
else:
	print(n-max(ac[0][1]+bc[1][1],ac[1][1]+bc[0][1]))

Solution (Python):
import collections

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

odd_number = [i for index, i in enumerate(v) if index % 2 != 0]
even_number = [i for index, i in enumerate(v) if index % 2 == 0]

odd_count = collections.Counter(odd_number).most_common()
even_count = collections.Counter(even_number).most_common()
odd_count.append((10**6, 0))
even_count.append((10**6, 0))

if odd_count[0][0] != even_count[0][0]:
  answer = [odd_count[0][0], even_count[0][0]]
else: 
  answer = [odd_count[1][0], even_count[0][0]] if odd_count[1][1] + even_count[0][1] > odd_count[0][1] + even_count[1][1] else [odd_count[0][0], even_count[1][0]]

print(len([i for i in odd_number if i != answer[0]]) + len([i for i in even_number if i != answer[1]]))

Solution (Python):


from collections import Counter

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])

e=Counter(even).most_common(2)
if len(e)<2:e=[e[0][0]]
else:e=list([e[0][0]]+[e[1][0]])
o=Counter(odd).most_common(2)
if len(o)<2:o=[o[0][0]]
else:o=list([o[0][0]]+[o[1][0]])

ans=float('inf')
for i in e:
    for j in o:
        cnt=0
        if i==j:continue
        for k in range(n):
            if k%2==0 and v[k]!=i:
                cnt+=1
            elif k%2==1 and v[k]!=j:
                cnt+=1
        ans=min(cnt,ans)

if ans==float('inf'):ans=n//2
print(ans)

Solution (Python):
import numpy as np

n = int(input())
arr = list(map(int,input().split()))
d1 = {}
d2 = {}

for i in range(n//2):
    if arr[i*2] in d1:
        d1[arr[i*2]]+=1
    else:
        d1[arr[i*2]] = 1
    if arr[i*2+1] in d2:
        d2[arr[i*2+1]]+=1
    else:
        d2[arr[i*2+1]] = 1

a1 = [[-1,0]]
a2 = [[-1,0]]

for key in d1.keys():
    a1.append([key,d1[key]])
for key in d2.keys():
    a2.append([key,d2[key]])

a1.sort(key = lambda x:x[1])
a2.sort(key = lambda x:x[1])

if a1[-1][0] == a2[-1][0]:
    temp1 = n-a1[-1][1]-a2[-2][1]
    temp2 = n-a1[-2][1]-a2[-1][1]
    print(min(temp1,temp2))
else:
    print(n-a1[-1][1]-a2[-1][1])

Solution (Python):
import collections
n = input()

li = list(map(int, input().split()))
odd_li = li[::2]
even_li = li[1::2]
odd_counter = collections.Counter(odd_li)
even_counter = collections.Counter(even_li)

odd_max = max(odd_counter.values())
even_max = max(even_counter.values())
odd_max_value = [key for key, value in odd_counter.items() if value == odd_max]
even_max_value = [key for key, value in even_counter.items() if value == even_max]

if len(odd_max_value) == 1 and odd_max_value == even_max_value:
    odd_counter.pop(odd_max_value[0])
    even_counter.pop(even_max_value[0])
    if len(odd_counter) == 0 and len(even_counter) == 0:
        print(len(odd_li)*2 - odd_max)
    elif len(odd_counter) == 0:
        print(len(odd_li)*2 - odd_max - max(even_counter.values()))
    elif len(even_counter) == 0:
        print(len(odd_li)*2 - odd_max - max(odd_counter.values()))
    else:
        second_max = max(max(odd_counter.values()),max(even_counter.values()) )
        print(len(odd_li)*2 - odd_max - second_max)
else:
    print(len(odd_li)*2 - odd_max - even_max)

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

v_even = []
v_odd = []

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

even_list = [0]*max(v_even)
odd_list = [0]*max(v_odd)
for j in range(len(v_even)):
    even_list[v_even[j]-1] += 1
    odd_list[v_odd[j]-1] += 1

even_list_sorted = sorted(even_list)
odd_list_sorted = sorted(odd_list)

if even_list.index(even_list_sorted[-1]) != odd_list.index(odd_list_sorted[-1]):
    ans = n - even_list_sorted[-1] - odd_list_sorted[-1]
elif len(even_list) == 1:
    ans = n // 2
elif even_list_sorted[-2] >= odd_list_sorted[-2]:
    ans = n - even_list_sorted[-2] - odd_list_sorted[-1]
else:
    ans = n - even_list_sorted[-1] - odd_list_sorted[-2]
    
print(ans)

Solution (Python):
from collections import Counter

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

co = Counter([v[i] for i in range(0, len(v), 2)])
ce = Counter([v[i] for i in range(1, len(v), 2)])
co1 = co.most_common()[0]
ce1 = ce.most_common()[0]
ans = n
if co1[0] == ce1[0]:
    if len(co) > 1:
        co2 = co.most_common()[1]
        ans = min(ans, n - co2[1] - ce1[1])
    if len(ce) > 1:
        ce2 = ce.most_common()[1]
        ans = min(ans, n - co1[1] - ce2[1])
    if len(co) == 1 and len(ce) == 1:
        ans = min(ans, n - max(co1[1], ce1[1]))
else:
    ans = min(ans, n - co1[1] - ce1[1])
print(ans)

Solution (Python):
from collections import Counter, deque
n=int(input())
V=deque(list(map(int,input().split())))
if len(set(V))==1:print(n//2)
else:
    Odd=[]
    Even=[]
    for _ in range(n//2):
        Odd.append(V.popleft())
        Even.append(V.popleft())
    O=Counter(Odd)
    E=Counter(Even)
    if len(set(Odd))==1:print(n//2-E.most_common()[0][1])
    elif len(set(Even))==1:print(n//2-O.most_common()[0][1])
    elif O.most_common()[0][0]==E.most_common()[0][0]:print(min(n-E.most_common()[0][1]-O.most_common()[1][1],n-E.most_common()[1][1]-O.most_common()[0][1]))
    else:print(n-E.most_common()[0][1]-O.most_common()[0][1])

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

evens = v[::2]
odds = v[1::2]


def means(arr):
    d = dict()
    for e in arr:
        if d.get(e) is None:
            d[e] = 1
        else:
            d[e] += 1
    m = sorted(d.items(), key=lambda e: e[1], reverse=True)
    m1, m1_cnt = m[0]
    m2, m2_cnt = m[1] if len(m) > 1 else (None, None)
    return (m1, m1_cnt), (m2, m2_cnt)


(e_m1, e_m1_cnt), (e_m2, e_m2_cnt) = means(evens)
(o_m1, o_m1_cnt), (o_m2, o_m2_cnt) = means(odds)

if e_m1 != o_m1:
    print(n - e_m1_cnt - o_m1_cnt)
else:
    if o_m2 is None and e_m2 is None:
        print(n // 2)
    else:
        candidate1 = n - e_m1_cnt - o_m2_cnt if o_m2_cnt is not None else float('inf')
        candidate2 = n - e_m2_cnt - o_m1_cnt if e_m2_cnt is not None else float('inf')
        print(min(candidate1, candidate2))