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

Solution (Python):
def main():
    n = int(input())
    vs = [int(s) for s in input().split()]

    print(solve(vs))

def solve(vs):
    c1 = count(vs[0::2])
    c2 = count(vs[1::2])

    a1 = c1[0]
    a2 = c1[1] if len(c1) > 1 else (0, 0)
    b1 = c2[0]
    b2 = c2[1] if len(c2) > 1 else (0, 0)

    if a1[0] != b1[0]:
        return len(vs) - a1[1] - b1[1]

    if a1[1] + b2[1] > a2[1] + b1[1]:
        return len(vs) - a1[1] - b2[1]
    else:
        return len(vs) - a2[1] - b1[1]

def count(vs):
    c = dict()

    for v in vs:
        c[v] = c.get(v, 0) + 1

    cs = sorted(c.items(), key=lambda x: x[1], reverse=True)
    return cs

main()

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, V):
    v1 = [v for v in V[::2]]
    v2 = [v for v in V[1::2]]

    v1c = Counter(v1)
    v2c = Counter(v2)
    v1 = v1c.most_common(2)
    v2 = v2c.most_common(2)
    v1.append((-1, 0))
    v2.append((-1, 0))
    v1_1, v1_2 = v1[:2]
    v2_1, v2_2 = v2[:2]

    if v1_1[0] != v2_1[0]:
        return (N//2 - v1_1[1]) + (N//2 - v2_1[1])

    return min(
        (N//2 - v1_1[1]) + (N//2 - v2_2[1]),
        (N//2 - v1_2[1]) + (N//2 - v2_1[1]),
    )


def main():
    N = read_int()
    V = read_int_n()
    print(slv(N, V))


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
v=[int(i) for i in input().split()]
if N==2:
    if v[0]==v[1]:
        print(1)
        exit()
    else:
        print(0)
        exit()
A=dict()
B=dict()
L=0
R=0
def inc(D,k):
    if k in D:
        D[k]+=1
    else:
        D[k]=1
for i in range(N):
    if i%2==0:
        L+=1
        inc(A,v[i])
    else:
        R+=1
        inc(B,v[i])
X=[(L,-1)]
Y=[(R,-2)]
for i in A:
    X.append((L-A[i],i))
for i in B:
    Y.append((R-B[i],i))
X.sort(reverse=True)
Y.sort(reverse=True)
while(True):
    if X[-1][1]!=Y[-1][1]:
        print(X[-1][0]+Y[-1][0])
        exit()
    else:
        vl=X[-1][0]+Y[-2][0]
        vr=X[-2][0]+Y[-1][0]
        if vl<vr:
            Y.pop()
            R-=1
        else:
            X.pop()
            L-=1

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

k1 = C(v[::2]).most_common()[0][0]
v1 = C(v[::2]).most_common()[0][1]

if v1 == n/2:
    k2 = 0
    v2 = 0
else:
    k2 = C(v[::2]).most_common()[1][0]
    v2 = C(v[::2]).most_common()[1][1]

k3 = C(v[1::2]).most_common()[0][0]
v3 = C(v[1::2]).most_common()[0][1]

if v3 == n/2:
    k4 = 0
    v4 = 0
else:
    k4 = C(v[1::2]).most_common()[1][0]
    v4 = C(v[1::2]).most_common()[1][1]

if k1 != k3:
    print (n - v1 - v3)
else:
    print (min(n - v1 - v4, n - v2 - v3))

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

v0 = collections.Counter([v[2 * i] for i in range(n // 2)])
v1 = collections.Counter([v[2 * i + 1] for i in range(n // 2)])

if v0.most_common()[0][0] != v1.most_common()[0][0]:
    ans = n - v0.most_common()[0][1] - v1.most_common()[0][1]
else:
    if len(v0) == 1:
        if len(v1) == 1:
            ans = n // 2
        else:
            ans = n - v1.most_common()[1][1]
    else:
        if len(v1) == 1:
            ans = n - v0.most_common()[1][1]
        else:
            ans = min(n - v0.most_common()[0][1] - v1.most_common()[1][1], n - v0.most_common()[1][1] - v1.most_common()[0][1])

print(ans)

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

c = {0:{}, 1:{}}
for i,vi in enumerate(v):
    r = i % 2
    if vi not in c[r]:
        c[r][vi] = 0
    c[r][vi] += 1

c0 = sorted(c[0].items(), key=lambda x:-x[1])
c1 = sorted(c[1].items(), key=lambda x:-x[1])

if c0[0][0] == c1[0][0]:
    if len(c0) < 2:
        c0.append((-1,0))
    if len(c1) < 2:
        c1.append((-1,0))
    print(n - max(c0[0][1] + c1[1][1], c0[1][1] + c1[0][1]))
else:
    print(n - c0[0][1] - c1[0][1])

Solution (Python):
import sys

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

check=0
for i in range(n):
    if V[i]!=V[i-1]:
        check=1
        break

if check==0:
    print(n//2)
    sys.exit()


G=[]
K=[]
for i in range(n):
    if i%2==0:
        G.append(V[i])
    else:
        K.append(V[i])

G.sort()
K.sort()

GV=[]
count=1

for i in range(1,len(G)):
    if G[i]==G[i-1]:
        count+=1
    else:
        GV.append((count,G[i-1]))
        count=1

GV.append((count,G[i-1]))

count=1
KV=[]
for i in range(1,len(K)):
    if K[i]==K[i-1]:
        count+=1
    else:
        KV.append((count,K[i-1]))
        count=1

KV.append((count,K[i-1]))

GV.sort(reverse=True)
KV.sort(reverse=True)

if GV[0][1]!=KV[0][1]:
    ANS=len(G)+len(K)-GV[0][0]-KV[0][0]

else:
    ANS=min(len(G)+len(K)-GV[1][0]-KV[0][0],len(G)+len(K)-GV[0][0]-KV[1][0])

print(ANS)

Solution (Python):
N = int(input())
lis = [int(i) for i in input().split()]
i = 0
a = {}
b = {}
for nums in lis:
  if i%2==0:
    if nums in a.keys():
      a[nums] += 1
    else:
      a[nums] = 1
  else:
    if nums in b.keys():
      b[nums] += 1
    else:
      b[nums] = 1
  i += 1
a1 = sorted(a.items(), key=lambda x: -x[1])
b1 = sorted(b.items(), key=lambda x: -x[1])
if a1[0][0]!=b1[0][0]:
  print(N-a1[0][1]-b1[0][1])
else:
  if len(a1)>=2 and len(b1)>=2:
    print(min(N-a1[1][1]-b1[0][1],N-a1[0][1]-b1[1][1]))
  elif len(a1)==1 and len(b1)==1:
    print(min(N-a1[0][1],N-b1[0][1]))
  elif len(a1)==1:
    print(min(N-a1[0][1]-b1[1][1],N-b1[0][1]))
  else:
    print(min(N-b1[0][1]-a1[1][1],N-a1[0][1]))

Solution (Python):
from collections import Counter
n = int( input())
V = list( map( int, input().split()))
oddV = [ V[2*i+1] for i in range(n//2)]
evenV = [ V[2*i] for i in range(n//2)]
CoddV = Counter(oddV).most_common()
CevenV = Counter(evenV).most_common()
p, q = CoddV[0]
a, b = CevenV[0]
if p != a:
    ans = n-b-q
elif n == 2:
    ans = 1
else:
    if q == n//2 and b == n//2:
        ans = n//2
    elif q == n//2:
        ans = n//2 - CevenV[1][1]
    elif b == n//2:
        ans = n//2 - CoddV[1][1]
    else:
        r, s = CoddV[1]
        c, d = CevenV[1]
        if q + d >= s + b:
            ans = n-q-d
        else:
            ans = n-s-b
print(ans)

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

b=[a[i] for i in range(0,n,2)]
c=[a[i] for i in range(1,n,2)]
from collections import Counter
xb=list(Counter(b).items())
xc=list(Counter(c).items())
xb=sorted(xb, key=lambda x:-x[1])
xc=sorted(xc, key=lambda x:-x[1])
ans=[]
if xb[0][0]==xc[0][0]:
    if len(xc)>1:
        ans.append(n//2-xb[0][1]-(-n//2)-xc[1][1])
    if len(xb)>1:
        ans.append(n//2-xb[1][1]-(-n//2)-xc[0][1])
    if len(xc)==1 and len(xb)==1:
        ans.append(n//2)
else:
    ans.append(n//2-xb[0][1]-(-n//2)-xc[0][1])
print(min(ans))

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

l0 = [0 for i in range(10**5+1)]
l1 = [0 for i in range(10**5+1)]

a0 = [v[i] for i in range(0, n, 2)]
a1 = [v[i] for i in range(1, n, 2)]

for i in a0:
    l0[i] += 1
for i in a1:
    l1[i] += 1

first0 = 0
index0 = 0
for i in range(len(l0)):
    if l0[i] > first0:
        first0 = l0[i]
        index0 = i

l0[index0] = 0
second0 = max(l0)

first1 = 0
index1 = 0
for i in range(len(l1)):
    if l1[i] > first1:
        first1 = l1[i]
        index1 = i

l1[index1] = 0
second1 = max(l1)

if index0 != index1:
    print(n - first0 - first1)
else:
    print(min(n - first0 - second1, n - first1 - second0))

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

l1 = [l[i] for i in range(0, n, 2)]
l2 = [l[i] for i in range(1, n, 2)]
c1 = sorted(Counter(l1).items(), key = lambda x: x[1], reverse = True) + [(0, 0)]
c2 = sorted(Counter(l2).items(), key = lambda x: x[1], reverse = True) + [(0, 0)]

res = c1[0][1] + c2[0][1]
if c1[0][0] == c2[0][0]:
    res = max((c1[1][1] + c2[0][1]), (c1[0][1] + c2[1][1]))


print(n - res)

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

v_cnt = [[0] * 100001 for _ in range(2)]

for i in range(n):
    v_cnt[i%2][v[i]] += 1

from collections import Counter

c = [sorted(enumerate(v_cnt[i]), reverse=True, key=lambda x: x[1])[:2] for i in range(2)]


ans = 1e9
for i, i_cnt in c[0]:
    for j, j_cnt in c[1]:
        if i != j:
            ans = min(ans, n//2 - i_cnt + (n+1)//2 - j_cnt)

print(ans)

Solution (Python):

from sys import stdin
from collections import Counter

s_in = lambda: stdin.readline()[:-1] 
d_in = lambda: int(stdin.readline()) 
ds_in = lambda: list(map(int, stdin.readline().split())) 

n = d_in()
v_arr = ds_in()

e_arr = []
o_arr = []
for i in range(n//2):
    e_arr.append(v_arr[2*i])
    o_arr.append(v_arr[2*i+1])

e_c = Counter(e_arr)
o_c = Counter(o_arr)

if len(e_c) == 1:
    e_m = e_c.most_common(n=1)
    if len(o_c) == 1:
        o_m = o_c.most_common(n=1)
        if e_m[0] == o_m[0]:
            print(n // 2)
        else:
            print(0)
    else:
        o_m = o_c.most_common(n=2)
        if e_m[0] == o_m[0]:
            print(n//2 - o_m[1][1])
        else:
            print(n//2 - o_m[0][1])
else:
    e_m = e_c.most_common(n=2)
    if len(o_c) == 1:
        o_m = o_c.most_common(n=1)
        if e_m[0] == o_m[0]:
            print(n//2 - e_m[1][1])
        else:
            print(n//2 - e_m[0][1])
    else:
        o_m = o_c.most_common(n=2)
        if e_m[0] != o_m[0]:
            print(n - e_m[0][1] - o_m[0][1])
        else:
            print(n - e_m[0][1] - max(e_m[1][1], o_m[1][1]))

Solution (Python):
from collections import defaultdict


def main():
    n = input()
    vv = map(int, raw_input().split())
    d1 = defaultdict(int)
    for x in vv[::2]:
        d1[x] += 1
    d2 = defaultdict(int)
    for x in vv[1::2]:
        d2[x] += 1
    d1 = sorted([[c, x] for x, c in d1.items()], reverse=True)
    d2 = sorted([[c, x] for x, c in d2.items()], reverse=True)
    if d1[0][1] != d2[0][1]:
        print(n - d1[0][0] - d2[0][0])
        return
    if len(d1) == len(d2) == 1:
        print(n // 2)
        return
    if len(d1) == 1:
        print(n - d1[0][0] - d2[1][0])
        return
    if len(d2) == 1:
        print(n - d1[1][0] - d2[0][0])
        return
    print(n - max(d1[0][0] + d2[1][0], d1[1][0] + d2[0][0]))


if __name__ == '__main__':
    main()

Solution (Python):
from numpy import argmax, argmin
N = int(input())
V = list(map(int, input().split()))
V1 = []
V2 = []
for i in range(N):
    if i%2==0:
        V1.append(V[i])
    else:
        V2.append(V[i])

Cnt = [0]*100001
for v in V1:
    Cnt[v] += 1
a1 = N//2-max(Cnt)
arg1 = argmax(Cnt)
Cnt[arg1] = 0
a11 = N//2-max(Cnt)


Cnt = [0]*100001

for v in V2:
    Cnt[v] += 1
a2 = N//2-max(Cnt)
arg2 = argmax(Cnt)
Cnt[arg2] = 0
a22 = N//2-max(Cnt)

if arg1==arg2:
    print(min(a1+a22, a2+a11))
else:
    print(a1+a2)

Solution (Python):
from collections import Counter

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

one = sorted(Counter([v[i] for i in range(0, n, 2)]).items(), key=lambda x: x[1], reverse=True)
two = sorted(Counter([v[i] for i in range(1, n, 2)]).items(), key=lambda x: x[1], reverse=True)


if one[0][0] != two[0][0]:
	print(n - one[0][1] - two[0][1])
else:
	if len(one) == 1 and len(two) == 1:
		print(n // 2)
	elif len(one) == 1:
		print(n // 2 - two[1][1])
	elif len(two) == 1:
		print(n // 2 - one[1][1])
	else:
		print(min(n - one[0][1] - two[1][1], n - one[1][1] - two[0][1]))

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = a[::2]
    c = a[1::2]

    retB = {}
    for i in b:
        retB[i] = retB.get(i, 0) + 1

    retC = {}
    for i in c:
        retC[i] = retC.get(i, 0) + 1

    retB = sorted(retB.items(), key=lambda x: x[1], reverse=True)
    retC = sorted(retC.items(), key=lambda x: x[1], reverse=True)
    if retB[0][0] != retC[0][0]:
        tmpB = len(b) - retB[0][1]
        tmpC = len(c) - retC[0][1]
        print(tmpC + tmpB)
    else:
        if len(retB) == 1 and len(retC) == 1:
            print(len(c))
            return
        if len(retB) == 1:
            tmpB = len(b) - retB[0][1]
            tmpC = len(c) - retC[1][1]
            print(tmpB + tmpC)
            return
        if len(retC) == 1:
            tmpB = len(b) - retB[1][1]
            tmpC = len(c) - retC[0][1]
            print(tmpB + tmpC)
            return
        tmpB = len(b) - retB[1][1]
        tmpC = len(c) - retC[0][1]
        ret = [tmpB + tmpC]
        tmpB = len(b) - retB[0][1]
        tmpC = len(c) - retC[1][1]
        ret.append(tmpB + tmpC)
        print(min(ret))


main()

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

numList = [[0, i] for i in range(10**5+1)]
numList2 = [[0, i] for i in range(10**5+1)]

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

numList = list(reversed(sorted(numList)))
numList2 = list(reversed(sorted(numList2)))

if numList[0][1] == numList2[0][1]:
    print(n - max(numList[0][0] + numList2[1][0],numList[1][0] + numList2[0][0]))
else:
    print(n - numList[0][0] - numList2[0][0])

Solution (Python):

from collections import Counter

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

	v1 = [vs[i] for i in range(n) if i % 2 == 0]
	v2 = [vs[i] for i in range(n) if i % 2 == 1]

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

	mc1 = v1c.most_common(2)
	mc2 = v2c.most_common(2)
	
	if len(mc1) == 1:
		mc1.append((0, 0))

	if len(mc2) == 1:
		mc2.append((0, 0))

	if mc1[0][0] == mc2[0][0]:
		if mc1[0][1] - mc1[1][1] >= mc2[0][1] - mc2[1][1]:
			print(n - mc1[0][1] - mc2[1][1])
		else:
			print(n - mc1[1][1] - mc2[0][1])
	else:
		print(n - mc1[0][1] - mc2[0][1])


if __name__ == '__main__':
	main()

Solution (Python):
n = int(input())
t = list(map(int,input().split(" ")))
dic1 = {}
dic2 = {}
for i in range(n):
    v = t[i]
    if i % 2 == 1:
        if v in dic1:
            dic1[v] += 1
        else:
            dic1[v] = 1
    else:
        if v in dic2:
            dic2[v] += 1
        else:
            dic2[v] = 1


a = list(dic1.items())
b = list(dic2.items())
a.sort(key=lambda x:x[1])
b.sort(key=lambda x:x[1]) 

if a[-1][0] != b[-1][0]:
    m1 = a[-1][1]
    m2 = b[-1][1]

elif len(a) == 1 and len(b) == 1:
    m1 = a[-1][1]
    m2 = 0

elif  len(a) == 1:
    m1 = a[-1][1]
    m2 = b[-2][1]

elif len(b) == 1:
    m1 = a[-2][1]
    m2 = b[-1][1]

else:
    m = [ a[-1][1],a[-2][1],b[-2][1]]
    m.sort()
    m1 = m[-1]
    m2 = m[-2]

print(n - m1 - m2)

Solution (Python):
import numpy as np

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

seta= [0 for i in range(1,10**5 +1)]
setb= [0 for i in range(1,10**5 +1)]


for i in range(n/2):
    seta[v[2*i]-1]+=1
    setb[v[2*i+1]-1]+=1
seta = np.array(seta)
setb = np.array(setb)

argseta=seta.argsort()[::-1]
argsetb=setb.argsort()[::-1]


if argseta[0]!=argsetb[0]:
    print n - max(seta) - max(setb)
else:
    if setb[argseta[0]]-seta[argseta[1]]<setb[argsetb[0]]-setb[argsetb[1]]:
        print n - max(setb) - seta[argseta[1]]
    else:
        print n - max(seta) - setb[argsetb[1]]

Solution (Python):

def inpl(): return list(map(int, input().split()))
from collections import Counter
n = int(input())
A = inpl()

C1 = Counter(A[::2])
C2 = Counter(A[1::2])

S1 = sorted(C1.items(), key=lambda x: x[1], reverse=True) + [[0, 0]]
S2 = sorted(C2.items(), key=lambda x: x[1], reverse=True) + [[0, 0]]

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

Solution (Python):

from collections import Counter

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

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

odd_c = Counter(odd)
even_c = Counter(even)

odd_c = sorted(odd_c.items(), key=lambda x: x[1], reverse=True) + [(-1, 0)]
even_c = sorted(even_c.items(), key=lambda x: x[1], reverse=True) + [(-1, 0)]

if odd_c[0][0] != even_c[0][0]:
    print(n - odd_c[0][1] - even_c[0][1])
elif odd_c[0][1] + even_c[1][1] >= odd_c[1][1] + even_c[0][1]:
    print(n - odd_c[0][1] - even_c[1][1])
else:
    print(n - odd_c[1][1] - even_c[0][1])

Solution (Python):
import sys
n = int(raw_input())
nums = list(map(int,raw_input().split()))
cnt1 = [0 for x in range(100001)]
cnt2 = [0 for x in range(100001)]
for i in range(n):
    if i%2:
        cnt1[nums[i]] += 1
    else:
        cnt2[nums[i]] += 1
a1 = -1
a2 = -1
n1 = 0
n2 = 0
b1 = -1
b2 = -1
m1 = 0
m2 = 0
for i in range(100001):
    if cnt1[i]>a1:
        a2 = a1
        a1 = cnt1[i]
        n2 = n1
        n1 = i
    elif cnt1[i]>a2:
        a2 = cnt1[i]
        n2 = i
    if cnt2[i]>b1:
        b2 = b1
        b1 = cnt2[i]
        m2 = m1
        m1 = i
    elif cnt2[i]>b2:
        b2 = cnt2[i]
        m2 = i
if m1!=n1:
    print n-a1-b1
else:
    if a2+b1<a1+b2:
        print n-a1-b2
    else:
        print n-a2-b1

Solution (Python):
import collections
n = int(input())
a = list(map(int,input().split()))
mae = []
usi = []
for i in range(0,n,2):
  mae.append(a[i])
for i in range(1,n,2):
  usi.append(a[i])
mae = collections.Counter(mae)
usi = collections.Counter(usi)
mae = mae.most_common()
usi = usi.most_common()
if mae[0][0] != usi[0][0]:
  print(n-mae[0][1]-usi[0][1])
else:
  try:
    t = mae[0][1] + usi[1][1]
  except:
    t = 0
  try:
    s = mae[1][1] + usi[0][1]
  except:
    s = 0
  u = mae[0][1]
  print(n-max(t,s,u))

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

n = read()
v = reads()

evens = sorted(((v, k) for k, v in Counter(v[::2]).items()), reverse=True) + [(0, -1)]
odds = sorted(((v, k) for k, v in Counter(v[1::2]).items()), reverse=True) + [(0, -1)]

if evens[0][1] != odds[0][1]:
  ans = n - evens[0][0] - odds[0][0]
else:
  ans = n - max(evens[0][0] + odds[1][0], evens[1][0] + odds[0][0])

print(ans)

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

ctr = Counter(src)
if len(ctr) == 1:
    print(N//2)
    exit()

odd = Counter([a for i,a in enumerate(src) if i%2])
even = Counter([a for i,a in enumerate(src) if i%2==0])

ev = even.most_common()[:2]
ans = N
for k,v in odd.most_common():
    k1,v1 = ev[0]
    if k != k1:
        ans = min(ans, N-v1-v)
    if len(ev) < 2: continue
    k2,v2 = ev[1]
    if k != k2:
        ans = min(ans, N-v2-v)
print(ans)

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

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

bn=0
b1=('0',0)
b2=('0',0)
c1=('0',0)
c2=('0',0)
for i in b.most_common():
  if bn==0:
    b1=i
  if bn==1:
    b2=i
  bn+=1
cn=0  
for i in c.most_common():
  if cn==0:
    c1=i
  if cn==1:
    c2=i
  cn+=1
if b1[0]!=c1[0]:
  print(n-b1[1]-c1[1])
elif b1[1]+c2[1]>c1[1]+b2[1]:
  print(n-b1[1]-c2[1])
else:
  print(n-b2[1]-c1[1])

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

last = 0

odd = [0 for _ in range(10**5+1)]
even = [0 for _ in range(10**5+1)]

even_max = 0
odd_max = 0
even_max_index = 0
odd_max_index = 0
for i in range(N):
    if i%2 == 0:
        even[v[i]] += 1
        if even[v[i]] > even_max:
            even_max = even[v[i]]
            even_max_index = v[i]
    else:
        odd[v[i]] += 1
        if odd[v[i]] > odd_max:
            odd_max = odd[v[i]]
            odd_max_index = v[i]

ans = even_max + odd_max
if even_max_index == odd_max_index:
    even[even_max_index] = 0
    odd[odd_max_index] = 0
    ans = max(max(even)+odd_max, max(odd)+even_max)

print(N-ans)

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

from collections import Counter

odd = Counter(A[::2])
even = Counter(A[1::2])

odd = sorted(((c,v) for v,c in odd.items()), reverse=True)
even = sorted(((c,v) for v,c in even.items()), reverse=True)

odd.append((0,None))
even.append((0,None))

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

Solution (Python):
from collections import Counter
import sys
N=int(input())
v=[int(i) for i in input().split()]
A=[]
B=[]
for i in range(N):
    if i%2==0:
        A.append(v[i])
    else:
        B.append(v[i])
S=Counter(A).most_common(2)
T=Counter(B).most_common(2)
if S[0][0]!=T[0][0]:
    print(N-S[0][1]-T[0][1])
    sys.exit()
if len(S)==1 and len(T)==1:
    print(N-S[0][1])
    sys.exit()
if len(S)==1:
    print(N-S[0][1]-T[1][1])
    sys.exit()
if(len(T)==1):
    print(N-S[1][1]-T[0][1])
    sys.exit()    

a=S[0][1]+T[1][1]
b=S[1][1]+T[0][1]
c=max(a,b)
print(N-c)

Solution (Python):

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

l_dict = dict()
r_dict = dict()

for i in range(n):
    v = v_list[i]
    if i % 2 == 0:
        if v in l_dict.keys():
            l_dict[v] += 1
        else:
            l_dict[v] = 1
    else:
        if v in r_dict.keys():
            r_dict[v] += 1
        else:
            r_dict[v] = 1 

l1 = 0
l2 = 0
l1_cnt = 0
l2_cnt = 0

for k in l_dict.keys():
    if l_dict[k] > l1_cnt:
        l2 = l1
        l2_cnt = l1_cnt
        l1 = k
        l1_cnt = l_dict[k]
    elif l_dict[k] > l2_cnt:
        l2 = k
        l2_cnt = l_dict[k]
        
r1 = 0
r2 = 0
r1_cnt = 0
r2_cnt = 0

for k in r_dict.keys():
    if r_dict[k] > r1_cnt:
        r2 = r1
        r2_cnt = r1_cnt
        r1 = k
        r1_cnt = r_dict[k]
    elif r_dict[k] > r2_cnt:
        r2 = k
        r2_cnt = r_dict[k]
        
if l1 != r1:
    res = n - (l1_cnt + r1_cnt)
else:
    res = n - (l1_cnt + max(l2_cnt, r2_cnt))
    
print(res)

Solution (Python):


import math
import sys


DEBUG = False


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, V):
    M = N // 2

    def build(off):
        d = dict()
        for i in range(off, N, 2):
            if V[i] not in d:
                d[V[i]] = 0
            d[V[i]] += 1

        arr = []
        for k, v in d.items():
            arr.append((M - v, k))

        arr.append((M, -1))

        arr.sort()
        return arr

    A = build(0)
    B = build(1)

    best = N
    for c1, v1 in A:
        for c2, v2 in B:
            if v1 != v2:
                best = min(best, c1 + c2)
                break
    return best


def main():
    N = int(inp())
    V = [int(e) for e in inp().split()]
    assert len(V) == N
    print(solve(N, V))


if __name__ == '__main__':
    main()

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

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


odd = Counter(val for i,val in enumerate(v) if i%2==1)
even =Counter(val for i,val in enumerate(v) if i%2==0)
if odd.most_common(1)[0] != even.most_common(1)[0]:
    print(n-odd.most_common(1)[0][1] - even.most_common(1)[0][1])
else:
    try:
        a = n-odd.most_common(2)[1][1] - even.most_common(1)[0][1]
        b= n-odd.most_common(1)[0][1] - even.most_common(2)[1][1]
        print(min(a,b))
    except IndexError:
        print(n//2)

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

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

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

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

Solution (Python):
def ii():
    return int(input())
def mi():
    return map(int, input().split())
def li():
    return list(mi())
from collections import Counter

n = ii()
a = li()
c0 = Counter(a[::2])
c1 = Counter(a[1::2])
x0, y0 = c0.most_common(1)[0]
x1, y1 = c1.most_common(1)[0]
if x0 != x1:
    ans = n - y0 - y1
else:
    y00 = c0.most_common(2)[1][1] if len(c0) > 1 else 0
    y11 = c1.most_common(2)[1][1] if len(c1) > 1 else 0
    ans = min(n - y0 - y11, n - y00 - y1)
print(ans)

Solution (Python):
from collections import defaultdict
n = int(input())
A = [int(x) for x in input().split()]
even = A[0::2]
odd = A[1::2]
EC = defaultdict(int)
EC[0] = 0
OC = defaultdict(int)
OC[0] = 0
for e in even:
  EC[e] += 1
for o in odd:
  OC[o] += 1
E = sorted([[v, k] for k, v in EC.items()], reverse=True)
O = sorted([[v, k] for k, v in OC.items()], reverse=True)
if E[0][1] != O[0][1]:
  print(n - E[0][0] - O[0][0])
elif E[1][0] >= O[1][0]:
  print(n - E[1][0] - O[0][0])
else:
  print(n - E[0][0] - O[1][0])

Solution (Python):

import sys

input=sys.stdin.readline

n=int(input())

a=list(map(int,input().split()))

d1={-1:0}
for i in a[::2]:
    if i in d1: d1[i]+=1
    else: d1[i]=1

d2={-2:0}
for i in a[1::2]:
    if i in d2: d2[i]+=1
    else: d2[i]=1

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

l1=l1[:5]
l2=l2[:5]

keep=0
for i,j in l1:
    for k,l in l2:
        if i==k: continue
        keep=max(keep,j+l)
print(n-keep)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    n = I()
    a = LI()
    c1 = collections.defaultdict(int)
    c2 = collections.defaultdict(int)
    c1['.'] = 0
    c2['a'] = 0
    for i in range(n//2):
        c1[a[i*2]] += 1
        c2[a[i*2+1]] += 1
    m = 0
    for k,v in sorted(c1.items(), key=lambda x: [-x[1], x[0]])[:2]:
        for k2,v2 in sorted(c2.items(), key=lambda x: [-x[1], x[0]]):
            if k2 == k:
                continue
            if m < v+v2:
                m = v+v2
                break

    return n - m


print(main())