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

Solution (Python):
import collections
n=int(input())
v=list(map(int, input().split()))
v1=v[0:n:2]
v2=v[1:n:2]
v10=collections.Counter(v1)
v11=v10.most_common()
v20=collections.Counter(v2)
v21=v20.most_common()
if v11[0][0]==v21[0][0] and v11[0][1]==n//2 and v21[0][1]==n//2:
    print(n//2)
elif v11[0][0]==v21[0][0]:
    x1=n//2-v11[0][1]
    x2=n//2-v11[1][1]
    y1=n//2-v21[0][1]
    y2=n//2-v21[1][1]
    print(min(x1+y2,x2+y1))
    
else:
    x1=n//2-v11[0][1]
    y1=n//2-v21[0][1]
    print(x1+y1)

Solution (Python):
from collections import Counter


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

    v0 = Counter(v[::2]).most_common()
    v1 = Counter(v[1::2]).most_common()

    if len(v0) == 1 and len(v1) == 1:
        if v0[0][0] == v1[0][0]:
            print(n // 2)
        else:
            print(0)
        return

    l0 = min(2, len(v0))
    l1 = min(2, len(v1))
    INF = 10 ** 9
    score = [[n - v0[i][1] - v1[j][1] if v0[i][0] != v1[j][0]
              else INF for j in range(l1)] for i in range(l0)]
    print(min([min(s) for s in score]))


main()

Solution (Python):
import collections


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

    v0 = count(v[::2])
    v1 = count(v[1::2])

    if len(v0) == 1 and len(v1) == 1:
        if v0[0][0] == v1[0][0]:
            print(n // 2)
        else:
            print(0)
        return

    l0 = min(2, len(v0))
    l1 = min(2, len(v1))

    INF = 10 ** 9
    score = [[0] * l1 for _ in range(l0)]
    for i in range(l0):
        for j in range(l1):
            score[i][j] = sum_v(v0, i) + sum_v(v1, j)
            if i >= l0 or j >= l1 or v0[i][0] == v1[j][0]:
                score[i][j] = INF
    print(min([min(s) for s in score]))


def count(v):
    return collections.Counter(v).most_common()


def sum_v(v, ii):
    return sum([vv[1] for i, vv in enumerate(v) if i != ii])


main()

Solution (Python):
from collections import Counter

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

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

ac = Counter(odd).most_common(2)
bc = Counter(even).most_common(2)

if ac[0][0] != bc[0][0]:
    print(n-ac[0][1]-bc[0][1])
else:
    if 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):
from collections import Counter

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

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

ac = Counter(odd).most_common(2)
bc = Counter(even).most_common(2)

if ac[0][0] != bc[0][0]:
    print(n-ac[0][1]-bc[0][1])
else:
    if len(ac) == 1 or len(bc) == 1:
        print(n//2)
    else:
        print(n-max(ac[0][1]+bc[1][1], ac[1][1]+bc[0][1]))

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())
v = [int(i) for i in input().split()] 

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

import collections as co
ki_c = co.Counter(ki)
gu_c = co.Counter(gu)


ki_m = ki_c.most_common()
gu_m = gu_c.most_common()

ki_m.append((0,0))
gu_m.append((0,0))

if ki_m[0][0] != gu_m[0][0]:
  ans = n - ki_m[0][1] - gu_m[0][1]
else:
  ans1 = n - ki_m[0][1] - gu_m[1][1]
  ans2 = n - ki_m[1][1] - gu_m[0][1]
  ans = min(ans1, ans2)
print(ans)

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

import collections as col

x_e=[]
x_o=[]

for i in range(n):
	if i%2==0:
		x_e.append(x[i])
	else:
		x_o.append(x[i])

x_e_c=col.Counter(x_e).most_common()    
x_o_c=col.Counter(x_o).most_common()

if x_e_c[0][1]>x_o_c[0][1]:
	fst=x_e_c
	snd=x_o_c
else:
	if x_e_c[0][1]<x_o_c[0][1]:	
		fst=x_o_c
		snd=x_e_c
	else:
		if len(x_e_c)>1 and len(x_o_c)>1:
			if x_e_c[1][1]<=x_o_c[1][1]:	
				fst=x_e_c
				snd=x_o_c
			else:
				fst=x_o_c
				snd=x_e_c
		else:
			fst=x_o_c
			snd=x_e_c

res=0

res+=n//2-fst[0][1]
if fst[0][0]!=snd[0][0]:
	res+=n//2-snd[0][1]
else:
	if len(snd)>1:
		res+=n//2-snd[1][1]
	else:
		res+=n//2

print(res)

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

    v0 = assemble(v[::2])
    v1 = assemble(v[1::2])

    if len(v0) == 1 and len(v1) == 1:
        if v0[0][0] == v1[0][0]:
            print(n // 2)
        else:
            print(0)
        return
    elif len(v0) == 1:
        if v0[0][0] == v1[0][0]:
            print(sum_v(v1, 1))
        else:
            print(sum_v(v1, 0))
        return
    elif len(v1) == 1:
        if v0[0][0] == v1[0][0]:
            print(sum_v(v0, 1))
        else:
            print(sum_v(v0, 0))
        return

    score = [[0, 0], [0, 0]]
    for i in range(2):
        for j in range(2):
            score[i][j] = sum_v(v0, i) + sum_v(v1, j)
            if v0[i][0] == v1[j][0]:
                score[i][j] = 10 ** 9
    print(min([min(s) for s in score]))


def assemble(v):
    dct = {}
    for vel in v:
        if vel in dct:
            dct[vel] += 1
        else:
            dct[vel] = 1
    return sorted(list(dct.items()), key=lambda x: x[1], reverse=True)


def sum_v(v, ii):
    return sum([vv[1] for i, vv in enumerate(v) if i != ii])


main()

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
num1=Counter(v[0::2])
num2=Counter(v[1::2])
num1sort=sorted(num1.items(),key=lambda x:x[1],reverse=True)
num2sort=sorted(num2.items(),key=lambda x:x[1],reverse=True)
if num1sort[0][0] == num2sort[0][0]:
    if (len(num1) == 1 ):
        if(len(num2) == 1):
            print(n//2)
        else:
            print(n//2-num2sort[1][1])
    elif (len(num2) == 1):
        print(n//2-num1sort[1][1])
    else:
        p1 = num1sort[0][1] + num2sort[1][1]
        p2 = num1sort[1][1] + num2sort[0][1]
        if p1 > p2:
            print(n-p1)
        else:
            print(n-p2)
else:
    print(n-num1sort[0][1]-num2sort[0][1])

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

odd = {}
even = {}

for idx in range(N):
  if idx%2 == 0:
    if V[idx] in even:
      even[V[idx]] += 1
    else:
      even[V[idx]] = 1
  else:
    if V[idx] in odd:
      odd[V[idx]] += 1
    else:
      odd[V[idx]] = 1
sorted_odd = sorted(odd.items(), key=lambda x: -x[1])
sorted_even = sorted(even.items(), key=lambda x: -x[1])
fs_odd = sorted_odd[0][0]
fs_even = sorted_even[0][0]
if fs_odd == fs_even:
  if sorted_odd[0][1] > sorted_even[0][1]:
    fs_even = sorted_even[1][0]
    print(N-odd[fs_odd]-even[fs_even])
  elif sorted_odd[0][1] < sorted_even[0][1]:
    fs_odd = sorted_odd[1][0]
    print(N-odd[fs_odd]-even[fs_even])
  else:
    if len(sorted_odd) == 1:
      print(N//2)
    else:
      if sorted_odd[1][1] > sorted_even[1][1]:
        fs_odd = sorted_odd[1][0]
        print(N-odd[fs_odd]-even[fs_even])
      else:
        fs_even = sorted_even[1][0]
        print(N-odd[fs_odd]-even[fs_even])
else:
  print(N-odd[fs_odd]-even[fs_even])

Solution (Python):
import collections

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

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

odd = v[::2]
even = v[1::2]
mo = collections.Counter(odd).most_common(2)
me = collections.Counter(even).most_common(2)

if mo[0][0] != me[0][0]:
    print(n - mo[0][1] - me[0][1])
elif len(mo) == 1:
    print(n - mo[0][1] - me[1][1])
elif len(me) == 1:
    print(n - mo[1][1] - me[0][1])
else:
    print(n - max(mo[0][1] + me[1][1], mo[1][1] + me[0][1]))

Solution (Python):
from collections import Counter
N = int(input())
a = list(map(int,input().split()))
even = [[0,0]] + sorted([v,k] for k,v in Counter(a[1::2]).items())
odd = [[0,0]] + sorted([v,k] for k,v in Counter(a[0::2]).items())

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

Solution (Python):
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])
v1.sort()
v2.sort()

v1num = []
v2num = []
cnt1 = []
cnt2 = [] 
for x in v1:
    if x not in v1num:
        v1num.append(x)
        cnt1.append(1)
    else:
        cnt1[-1] += 1
for x in v2:
    if x not in v2num:
        v2num.append(x)
        cnt2.append(1)
    else:
        cnt2[-1] += 1


res = 0
m1 = max(cnt1)
m2 = max(cnt2)
maxc1ind = cnt1.index(m1)
maxc2ind = cnt2.index(m2)
maxc1 = v1num[maxc1ind]
maxc2 = v2num[maxc2ind]
if maxc1 != maxc2:
    res = n - m1 - m2
else:
    if len(cnt1) == 1 and len(cnt2) == 1:
        res = n // 2
    else:    
        cnt1.sort(reverse=True)
        cnt2.sort(reverse=True)
        x1 = cnt1[0] + cnt2[1]
        x2 = cnt1[1] + cnt2[0]
        res = n - max(x1,x2)
print(res)

Solution (Python):
import sys
import numpy as np
input = sys.stdin.readline

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

    len1 = n//2 + n&1
    len2 = n//2

    d1 = {0:0}
    d2 = {0:0}
    for i in range(0,n,2):
        if v[i] in d1:
            d1[v[i]] += 1
        else:
            d1[v[i]] = 1
    for i in range(1,n,2):
        if v[i] in d2:
            d2[v[i]] += 1
        else:
            d2[v[i]] = 1

    a = sorted(d1.items(), key = lambda x: (x[1], x[0]) , reverse=True)
    b = sorted(d2.items(), key = lambda x: (x[1], -x[0]), reverse=True)
    a1_key, a1_val = a[0]
    a2_key, a2_val = a[1]
    b1_key, b1_val = b[0]
    b2_key, b2_val = b[1]
    if a1_key != b1_key:
        print(n - a1_val - b1_val)
    else:
        print(min(n - a1_val - b2_val, n - a2_val - b1_val))



if __name__ == "__main__":
    main()

Solution (Python):
def larger(x, y):
	if x > y:
		return x
	return y

N = int(input())
V = list(map(int, input().split()))
even = []
odd = []
for i in range(0, N):
	if i % 2 == 0:
		even.append(V[i])
	else:
		odd.append(V[i])
even.sort()
odd.sort()
evencount = [[even[0], 1]]
oddcount = [[odd[0], 1]]
for i in range(1, N//2):
	if even[i] != even[i-1]:
		evencount.append([even[i], 1])
	else:
		evencount[-1][1] += 1
	if odd[i] != odd[i-1]:
		oddcount.append([odd[i], 1])
	else:
		oddcount[-1][1] += 1
evencount.sort(key = lambda v: v[1], reverse = True)
oddcount.sort(key = lambda v: v[1], reverse = True)
ans = N - evencount[0][1] - oddcount[0][1]
if evencount[0][0] == oddcount[0][0]:
	if len(evencount) == 1 or len(oddcount) == 1:
		ans = N//2
	else:
		ans = N - larger(evencount[0][1]+oddcount[1][1], evencount[1][1]+oddcount[0][1])
print(ans)

Solution (Python):
n=int(input())
l=input().split()
a={"-1":0}
for i in range(0,len(l),2):
    if l[i] in a:
        a[l[i]]+=1
    else:
        a[l[i]]=1
b={"-1":0}  
for i in range(1,len(l),2):
    if l[i] in b:
        b[l[i]]+=1
    else:
        b[l[i]]=1
a = sorted(a.items(), key=lambda x:-x[1])
b = sorted(b.items(), key=lambda x:-x[1])
if a[0][0]==b[0][0]:
    m=max(a[0][1]+b[1][1],a[1][1]+b[0][1])
else:
    m=a[0][1]+b[0][1]
print(n-m)

Solution (Python):
from collections import Counter

n = int(input())
v = input().split()
v1 = []
v2 = []

for k in range(n):
    if k%2 == 0:
        v1.append(v[k])
    else:
        v2.append(v[k])

v1Counter = Counter(v1)
v2Counter = Counter(v2)
a1, b1 = zip(*v1Counter.most_common(2))
a2, b2 = zip(*v2Counter.most_common(2))

if a1[0] != a2[0]:
    print(n-b1[0]-b2[0])

else:
    if b1[0]==n/2 and b2[0]==n/2:
        print(int(n/2))
    elif b1[0]==n/2:
        print(n-b1[0]-b2[1])
    elif b2[0]==n/2:
        print(n-b2[0]-b1[1])
    else:
        c = max(b1[0]+b2[1],b1[1]+b2[0])
        print(n-c)

Solution (Python):
import collections
from operator import itemgetter

N = int(input())

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

ud = collections.Counter(up)
dd = collections.Counter(down)

ul = []
for u, c in ud.items():
    ul.append([u, c])
dl = []
for d, c in dd.items():
    dl.append([d, c])

ul.sort(key=itemgetter(1), reverse=True)
dl.sort(key=itemgetter(1), reverse=True)

if ul[0][0] != dl[0][0]:
    print(N - ul[0][1] - dl[0][1])
elif len(ul) == 1 and len(dl) > 1:
    print(N - ul[0][1] - dl[1][1])
elif len(ul) > 1 and len(dl) == 1:
    print(N - ul[1][1] - dl[0][1])
elif len(ul) == 1 and len(dl) == 1:
    print(N//2)
else:
    print(N - max(ul[0][1]+dl[1][1], ul[1][1]+dl[0][1]))

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
ev=[0]*100010
od=[0]*100010

for i in range(n):
    if i%2==0:
        ev[int(A[i])]+=1
    else:
        od[int(A[i])]+=1

if ev.index(max(ev))==od.index(max(od)):
    ev.sort(reverse=True)
    od.sort(reverse=True)
    if ev[0]!=ev[1] and od[0]!=od[1]:
        if ev[1]>=od[1]:
            print(n//2-ev[1]+n//2-od[0])
            exit(0)
        else:
            print(n // 2 - ev[0] + n // 2 - od[1])
            exit(0)

ev.sort(reverse=True)
od.sort(reverse=True)



print(n//2-ev[0]+n//2-od[0])

Solution (Python):
from collections import Counter

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

ac = Counter(ls[::2]).most_common(2)
bd = Counter(ls[1::2]).most_common(2)

if ac[0][0] != bd[0][0]:
    print(n-ac[0][1]-bd[0][1])
else:
    if len(ac) == 1 or len(bd) == 1:
        print(n//2)
    else:
        print(n-max(ac[0][1] + bd[1][1], ac[1][1] + bd[0][1]))

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

def collect(a):
  adic = {}
  for ai in a:
    if ai in adic.keys():
      adic[ai] += 1
    else:
      adic[ai] = 1
  adic = sorted(adic.items(), key=lambda x:x[1])[::-1]
  adic.append((0, 0))
  return adic

od = collect(an[::2])
ev = collect(an[1::2])

if od[0][0] == ev[0][0]:
  maxi = max(od[0][1] + ev[1][1], od[1][1] + ev[0][1])
else:
  maxi = od[0][1] + ev[0][1]
print(str(n-maxi))

Solution (Python):
n1 = [[j, 0] for j in range(100005)]
n2 = [[j, 0] for j in range(100005)]
n = int(input())
v = list(map(int, input().split()))
for i in range(n):
    if(i % 2 == 0):
        n1[v[i]][1] += 1
    else:
        n2[v[i]][1] += 1
n1 = sorted(n1, key=lambda x:x[1], reverse=True)
n2 = sorted(n2, key=lambda x:x[1], reverse=True)

if(n1[0][0] == n2[0][0]):
    ans1 = n//2 - n1[0][1] + n//2 - n2[1][1]
    ans2 = n//2 - n1[1][1] + n//2 - n2[0][1]
    ans = min(ans1, ans2)
    print(ans)
else:
    ans = n//2 - n1[0][1] + n//2 - n2[0][1]
    print(ans)

Solution (Python):



from operator import itemgetter
import collections

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

s = [v[i] for i in range(n) if i % 2 == 0]
t = [v[i] for i in range(n) if i % 2 == 1]

sc = collections.Counter(s)
tc = collections.Counter(t)
sc = list(sc.items())
tc = list(tc.items())
ls = len(sc)
lt = len(tc)
sc.sort(key = itemgetter(1))
tc.sort(key = itemgetter(1))
if sc[-1][0] == tc[-1][0]:
    if ls == 1 and lt == 1:
        print(n - sc[-1][1])
    elif ls == 1 and lt != 1:
        print(n - sc[-1][1] - tc[-2][1])
    elif ls != 1 and lt == 1:
        print(n - sc[-2][1] - tc[-1][1])
    else:
        ma = max(sc[-2][1],tc[-2][1])
        print(n - sc[-1][1] - ma)
else:
    print(n - sc[-1][1] - tc[-1][1])

Solution (Python):



from operator import itemgetter
import collections

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

s = [v[i] for i in range(n) if i % 2 == 0]
t = [v[i] for i in range(n) if i % 2 == 1]

sc = collections.Counter(s)
tc = collections.Counter(t)
sc = list(sc.items())
tc = list(tc.items())
ls = len(sc)
lt = len(tc)
sc.sort(key = itemgetter(1))
tc.sort(key = itemgetter(1))
if sc[-1][0] == tc[-1][0]:
    if ls == 1 and lt == 1:
        print(n - sc[-1][1])
    elif ls == 1 and lt != 1:
        print(n - sc[-1][1] - tc[-2][1])
    elif ls != 1 and lt == 1:
        print(n - sc[-2][1] - tc[-1][1])
    else:
        ma = max(sc[-2][1],tc[-2][1])
        print(n - sc[-1][1] - ma)
else:
    print(n - sc[-1][1] - tc[-1][1])

Solution (Python):
import collections

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

o=[]
e=[]
for i in range(n):
    if i%2==0:
        e.append(v[i])
    else:
        o.append(v[i])
count_o=collections.Counter(o)
count_e=collections.Counter(e)
count_o=list(count_o.items())
count_e=list(count_e.items())
count_o=sorted(count_o,key=lambda x:x[1])
count_e=sorted(count_e,key=lambda x:x[1])
if count_o[-1][0]==count_e[-1][0]:
    if len(count_e)==1:
        addnum_e=0
    else:
        addnum_e=count_e[-2][1]
    if len(count_o)==1:
        addnum_o=0
    else:
        addnum_o=count_o[-2][1]
    oe=count_o[-1][1]+addnum_e
    eo=addnum_o+count_e[-1][1]
    total=max(oe,eo)
else:
    total=count_o[-1][1]+count_e[-1][1]
print(n-total)

Solution (Python):
from collections import Counter
from operator import itemgetter

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

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

evens = list(sorted(evens.items(), key=itemgetter(1), reverse=True))
odds = list(sorted(odds.items(), key=itemgetter(1), reverse=True))


ans = n
for even_num, even_cnt in evens[:2] + [(-1, 0)]:
    for odd_num, odd_cnt in odds[:2] + [(-1, 0)]:
        if even_num == odd_num: continue
        ans = min(ans, n - even_cnt - odd_cnt)





print(ans)

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

Solution (Python):
a = int(input())
b = list(map(int, input().split()))
c = {}
for i in range(a):
    if str(b[i]) in c:
        c[str(b[i])] += 1
    else:
        c[str(b[i])] = 1
c = sorted(c.items(), key=lambda x: x[1], reverse=True)
if len(c) <= 1:
    print(a // 2)
elif len(c) == 2:
    e = [int(c[0][0]), int(c[1][0])] + b
    f = [int(c[1][0]), int(c[0][0])] + b
    ec = 0
    fc = 0
    for i in range(2, len(e)):
        if e[i] != e[i-2]:
            e[i] = e[i-2]
            ec += 1
        if f[i] != f[i-2]:
            f[i] = f[i-2]
            fc += 1
    print(min(ec, fc))
elif len(c) >= 3:
    e = [int(c[0][0]), int(c[1][0])] + b
    f = [int(c[1][0]), int(c[0][0])] + b
    g = [int(c[0][0]), int(c[2][0])] + b
    h = [int(c[1][0]), int(c[2][0])] + b
    j = [int(c[2][0]), int(c[0][0])] + b
    k = [int(c[2][0]), int(c[1][0])] + b

    ec = 0
    fc = 0
    gc = 0
    hc = 0
    jc = 0
    kc = 0
    for i in range(2, len(e)):
        if e[i] != e[i-2]:
            e[i] = e[i-2]
            ec += 1
        if f[i] != f[i-2]:
            f[i] = f[i-2]
            fc += 1
        if g[i] != g[i-2]:
            g[i] = g[i-2]
            gc += 1
        if h[i] != h[i-2]:
            h[i] = h[i-2]
            hc += 1
        if j[i] != j[i-2]:
            j[i] = j[i-2]
            jc += 1
        if k[i] != k[i-2]:
            k[i] = k[i-2]
            kc += 1
    print(min(ec, fc, gc, hc, jc, kc))

Solution (Python):
from collections import defaultdict

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

evens = defaultdict(lambda: 0)
odds = defaultdict(lambda: 0)
for i in range(0, n, 2):
    evens[numbers[i]] += 1
    odds[numbers[i + 1]] += 1

evens = list(evens.items())
odds = list(odds.items())

evens.sort(key=lambda pair: pair[1], reverse=True)
odds.sort(key=lambda pair: pair[1], reverse=True)

if len(evens) == 1 and len(odds) == 1:
    if evens[0][0] == odds[0][0]:
        print(n // 2)
    else:
        print(0)
    exit()

if len(evens) == 1 or len(odds) == 1:
    pairs = evens if len(evens) > len(odds) else odds
    if evens[0][0] == odds[0][0]:
        del pairs[1]
    else:
        del pairs[0]
    print(sum([v for _, v in pairs]))
    exit()

if evens[0][0] == odds[0][0]:
    if evens[0][1] == odds[0][1]:
        if evens[1][1] > odds[1][1]:
            del evens[1]
            del odds[0]
        else:
            del evens[0]
            del odds[1]
    elif evens[0][1] > odds[0][1]:
        del evens[0]
        del odds[1]
    else:
        del evens[1]
        del odds[0]
else:
    del evens[0]
    del odds[0]
print(sum([v for _, v in evens]) + sum([v for _, v in odds]))

Solution (Python):
import collections
N=int(input())
L=list(map(int,input().split()))
E=[i for i in L[::2]]
O=[i for i in L[1::2]]
e = collections.Counter(E).most_common()
o = collections.Counter(O).most_common()
if e[0][0] != o[0][0]:
    print(N - e[0][1] - o[0][1])
else:
    if len(e) == 1 or len(o) == 1:
        print(N // 2)
    else:
        a = N - e[1][1] - o[0][1]
        b = N - e[0][1] - o[1][1]
        print(min(a, b))

Solution (Python):
import collections

n = int(input())
value = input().split()

odd = [int(value[i]) for i in range(n) if i % 2]
even = [int(value[i]) for i in range(n) if not i % 2]

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


freq_odd = odd_c.most_common()
freq_even = even_c.most_common()

if len(set(value)) == 1:  
  freq = n // 2
elif freq_odd[0][0] != freq_even[0][0]:
  freq = freq_odd[0][1] + freq_even[0][1]
else:
  if len(freq_odd) == 1:
    freq = freq_odd[0][1] + freq_even[1][1]
  elif len(freq_even) == 1:
    freq = freq_odd[1][1] + freq_even[0][1]
  else:
    
    choice_a = freq_odd[0][1] + freq_even[1][1]
    choice_b = freq_odd[1][1] + freq_even[0][1]
    
    freq = max(choice_a, choice_b)

print(n - freq)

Solution (Python):
import collections

n = int(input())
value = input().split()

odd = [int(value[i]) for i in range(n) if i % 2]
even = [int(value[i]) for i in range(n) if not i % 2]

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


freq_odd = odd_c.most_common()
freq_even = even_c.most_common()

if len(set(value)) == 1:  
  freq = n // 2
elif freq_odd[0][0] != freq_even[0][0]:
  freq = freq_odd[0][1] + freq_even[0][1]
else:
  if len(freq_odd) == 1:
    freq = freq_odd[0][1] + freq_even[1][1]
  elif len(freq_even) == 1:
    freq = freq_odd[1][1] + freq_even[0][1]
  else:
    
    choice_a = freq_odd[0][1] + freq_even[1][1]
    choice_b = freq_odd[1][1] + freq_even[0][1]
    
    freq = max(choice_a, choice_b)

print(n - freq)

Solution (Python):
n = int(input())
v = [int(x) for x in input().split()]
big = 10**5+1
even = [0] * big
odd = [0] * big
for i in range(big):
    even[i] = [0] * 2
    odd[i] = [0]*2
    even[i][1] = i
    odd[i][1] = i

for j in range(n):
    if j % 2 == 0:
        even[v[j]][0] += 1
    else:
        odd[v[j]][0] += 1

even = sorted(even, reverse=True)
odd = sorted(odd, reverse=True)

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

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
v0 = []
v1 = []
for i in range(n):
    if i % 2 == 0:
        v0.append(v[i])
    else:
        v1.append(v[i])
v0.sort()
v1.sort()
l = [[0,-2]]
r = [[0,-1]]
hoge = v0[0]
count = 0
for i in v0:
    if i == hoge:
        count += 1
    else:
        l.append([count,hoge])
        hoge = i
        count = 1
l.append([count,hoge])
hoge = v1[0]
count = 0
for i in v1:
    if i == hoge:
        count += 1
    else:
        r.append([count,hoge])
        hoge = i
        count = 1
r.append([count,hoge])
l.sort(reverse = True)
r.sort(reverse = True)
if l[0][1] != r[0][1]:
    print(n-l[0][0]-r[0][0])
else:
    print(min(n-l[1][0]-r[0][0],n-l[0][0]-r[1][0]))

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

lst1 = Counter(lst[0::2]).most_common()
lst2 = Counter(lst[1::2]).most_common()

if lst1[0][0] != lst2[0][0]:
    print(n - lst1[0][1] - lst2[0][1])
else:
    if len(lst1) == 1 or len(lst2) == 1:
        print(n // 2)
    else:
        a = n - lst1[1][1] - lst2[0][1]
        b = n - lst1[0][1] - lst2[1][1]
        print(min(a, b))

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
gu, ki = [], []
for i in range(n):
	if i % 2 == 0:
		ki.append(v[i])
	else:
		gu.append(v[i])
ki_flag, gu_flag = False, False
kict = Counter(ki)
guct = Counter(gu)
kict_mc = kict.most_common()
guct_mc = guct.most_common()
if len(kict_mc) > 1:
	ki_flag = True
if len(guct_mc) > 1:
	gu_flag = True
ki_first = kict_mc[0][0]
if ki_flag:
	ki_second = kict_mc[1][0]
gu_first = guct_mc[0][0]
if gu_flag:
	gu_second = guct_mc[1][0]
if ki_flag & gu_flag:
	if ki_first == gu_first:
		print(min([n - kict_mc[0][1] - guct_mc[1][1], n - kict_mc[1][1] - guct_mc[0][1]]))
	else:
		print(n - kict_mc[0][1] - guct_mc[0][1])
elif ki_flag:
	if ki_first == gu_first:
		print(n - kict_mc[1][1] - guct_mc[0][1])
	else:
		print(n - kict_mc[0][1] - guct_mc[0][1])
elif gu_flag:
	if ki_first == gu_first:
		print(n - kict_mc[0][1] - guct_mc[1][1])
	else:
		print(n - kict_mc[0][1] - guct_mc[0][1])
else:
	if ki_first == gu_first:
		print(int(n / 2))
	else:
		print(n - kict_mc[0][1] - guct_mc[0][1])

Solution (Python):
from collections import defaultdict
dic1=defaultdict(int)
dic2=defaultdict(int)
n=int(input())
l=list(map(int,input().split()))
for i in range(0,n-1,2):
  dic1[l[i]]+=1
for i in range(1,n,2):
  dic2[l[i]]+=1
max11=0
i1=0
max12=0
i2=0
max21=0
i3=0
max22=0
i4=0
for i in dic1:
  if dic1[i]>=max11:
    max12=max11
    max11=dic1[i]
    i2=i1
    i1=i
  elif dic1[i]>max12:
    max12=dic1[i]
    i2=i
for i in dic2:
  if dic2[i]>=max21:
    max22=max21
    max21=dic2[i]
    i4=i3
    i3=i
  elif dic2[i]>max22:
    max22=dic2[i]
    i4=i
if i1!=i3:
  print(n-max11-max21)
elif i1==i3:
  print(min(n-max11-max22,n-max21-max12))

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


from collections import defaultdict
d1 = defaultdict(int)
d2 = defaultdict(int)

for i in range(n):
    if i%2==0:
        d1[ls[i]]+=1
    else:
        d2[ls[i]]+=1


d1=sorted(d1.items(),key=lambda x:x[1],reverse=True)
d2=sorted(d2.items(),key=lambda x:x[1],reverse=True)


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

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

li0 = li[::2]
li1 = li[1::2]
c0 = col.Counter(li0)
c1 = col.Counter(li1)
if c0.most_common()[0][0] != c1.most_common()[0][0]:
  print(n-c0.most_common()[0][1]-c1.most_common()[0][1])
else:
  if len(set(li0)) == 1:
    if len(set(li1)) == 1:
      print(n - len(li0))
    else:
      print(n - len(li0) - c1.most_common()[1][1])
  else:
    if len(set(li1)) == 1:
      print(n - len(li1) - c0.most_common()[1][1])
    else:
      if c0.most_common()[1][1] <= c1.most_common()[1][1]:
        print(n - c0.most_common()[0][1]-c1.most_common()[1][1])
      else:
        print(n - c1.most_common()[0][1]-c0.most_common()[1][1])

Solution (Python):
import collections

n = int(input())
v = list(map(int, input().split()))
v1 = v[0:n - 1:2]
v2 = v[1:n:2]

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

c1_sort = sorted(c1.items(), key=lambda x:x[1], reverse=True)
c2_sort = sorted(c2.items(), key=lambda x:x[1], reverse=True)

if c1_sort[0][0] != c2_sort[0][0]:
    ans = n - c1_sort[0][1] - c2_sort[0][1]
else:
    if len(c1_sort) == 1 and len(c2_sort) == 1:
        ans = n // 2
    else:
        ans = n - max(c1_sort[0][1] + c2_sort[1][1], c1_sort[1][1] + c2_sort[0][1])
print(ans)

Solution (Python):
import collections
n = int(input())
dat_a = list(map(int, input().split()))
dat_a_e = []
dat_a_o = []
for i in range(n//2):
    dat_a_e.append(dat_a[2*i])
    dat_a_o.append(dat_a[2*i+1])


c_e = collections.Counter(dat_a_e).most_common(2)
c_o = collections.Counter(dat_a_o).most_common(2)
if len(c_e) == 1:
    c_e.append((0,0))
if len(c_o) == 1:
    c_o.append((0,0))

if c_o[0][0] != c_e[0][0]:
    print(n//2 - c_e[0][1] + n//2 - c_o[0][1])
else:
    x = n//2 - c_e[0][1] + n//2 - c_o[1][1]
    y = n//2 - c_e[1][1] + n//2 - c_o[0][1]
    print(min(x, y))

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

L=II()
INL=LI()

ODDS=INL[::2]
EVNS=INL[1::2]

MP_ODDS = {}
MP_EVNS = {}

if L == 2:
    print(0)
    exit()

for i in ODDS:
    if not i in MP_ODDS:
        MP_ODDS[i] = 0
    MP_ODDS[i] += 1

for i in EVNS:
    if not i in MP_EVNS:
        MP_EVNS[i] = 0
    MP_EVNS[i] += 1

ODDSC = []
EVNSC = []
for i,j in MP_ODDS.items():
    ODDSC.append((j,i))
for i,j in MP_EVNS.items():
    EVNSC.append((j,i))
ODDSC.sort(reverse=True)
EVNSC.sort(reverse=True)
EVNSC.append((0, -1))
ODDSC.append((0, -1))


if ODDSC[0][1] == EVNSC[0][1]:
    print(min(L-ODDSC[1][0]-EVNSC[0][0], L-ODDSC[0][0]-EVNSC[1][0]))    
else:
    print(L - ODDSC[0][0] - EVNSC[0][0])

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

L=II()
INL=LI()

ODDS=INL[::2]
EVNS=INL[1::2]

MP_ODDS = {}
MP_EVNS = {}

if L == 2:
    print(0)
    exit()

for i in ODDS:
    if not i in MP_ODDS:
        MP_ODDS[i] = 0
    MP_ODDS[i] += 1

for i in EVNS:
    if not i in MP_EVNS:
        MP_EVNS[i] = 0
    MP_EVNS[i] += 1

ODDSC = []
EVNSC = []
for i,j in MP_ODDS.items():
    ODDSC.append((j,i))
for i,j in MP_EVNS.items():
    EVNSC.append((j,i))
ODDSC.sort(reverse=True)
EVNSC.sort(reverse=True)
EVNSC.append((0, -1))
ODDSC.append((0, -1))


if ODDSC[0][1] == EVNSC[0][1]:
    print(min(L-ODDSC[1][0]-EVNSC[0][0], L-ODDSC[0][0]-EVNSC[1][0]))    
else:
    print(L - ODDSC[0][0] - EVNSC[0][0])