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

Solution (Python):
from collections import Counter
    
n = int(input())
v = list(map(int, input().split()))
odd = v[::2]
even = v[1::2]
    
c_even = Counter(even).most_common(2)
c_odd = Counter(odd).most_common(2)

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

Solution (Python):

from collections import Counter

def main():
    n = int(input())
    v_list = list(map(int, input().split()))
    v_list_even = v_list[::2]
    v_list_odd = v_list[1::2]
    counter_even = Counter(v_list_even)
    counter_odd = Counter(v_list_odd)
    if counter_even.most_common()[0][0] == counter_odd.most_common()[0][0]:
        even_first = counter_even.most_common()[0][1]
        odd_first = counter_odd.most_common()[0][1]
        if len(counter_even.most_common()) == 1:
            even_second = 0
        else:
            even_second = counter_even.most_common()[1][1]
        if len(counter_odd.most_common()) == 1:
            odd_second = 0
        else:
            odd_second = counter_odd.most_common()[1][1]
        ans = min(len(v_list_even) - even_first + len(v_list_odd) - odd_second, len(v_list_even) - even_second + len(v_list_odd) - odd_first)
    else:
        ans = len(v_list_even) - counter_even.most_common()[0][1] + len(v_list_odd) - counter_odd.most_common()[0][1]
    print(ans)
    
if __name__ == '__main__':
    main()

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

from collections import Counter
import operator
def f():
    evn = Counter(A[::2])
    odd = Counter(A[1::2])

    a = sorted(odd.most_common(2), key=operator.itemgetter(1, 0), reverse=True)
    b = sorted(evn.most_common(2), key=operator.itemgetter(1, 0), reverse=True)

    ac = a[0][1]
    bc = b[0][1]
    ret = n - (ac + bc)
    if a[0][0] == b[0][0]:
        bc_2 = b[1][1] if len(b) != 1 else 0
        ac_2 = a[1][1] if len(a) != 1 else 0
        ret = n - max(ac + bc_2, ac_2 + bc)
    return ret
print(f())

Solution (Python):
import collections

n = int(input())
v = [int(i) for i in input().split()]
odd = collections.Counter(v[1::2])
even = collections.Counter(v[0::2])


max_odd = max(odd, key=odd.get)

max_even = max(even, key=even.get)


max_odd_v = odd[max_odd]
max_even_v = even[max_even]

if max_odd == max_even:
    if len(odd) > 1:
        max_2nd_odd = odd.most_common(2)[1][0]
        max_2nd_odd_v = odd[max_2nd_odd]
    else:
        max_2nd_odd_v = 0
    if len(even) > 1:
        max_2nd_even = even.most_common(2)[1][0]
        max_2nd_even_v = even[max_2nd_even]
    else:
        max_2nd_even_v = 0
    if (max_odd_v + max_2nd_even_v) < (max_even_v + max_2nd_odd_v):
        print(n - (max_even_v + max_2nd_odd_v))
    else:
        print(n - (max_odd_v + max_2nd_even_v))
else:
    print(n - (max_odd_v + max_even_v))

Solution (Python):
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
e = []
o = []
for i, a in enumerate(v):
    if i % 2:
        o.append(a)
    else:
        e.append(a)
oc = Counter(o)
ec = Counter(e)
h = n//2
if oc.most_common(1)[0][0] != ec.most_common(1)[0][0]:
    a = h - oc.most_common(1)[0][1]
    b = h - ec.most_common(1)[0][1]
    print(a+b)
else:
    if len(oc) == 1:
        print(h)
        exit()
    E1 = E2 = 0
    for i, (k, v) in enumerate(ec.most_common(2)):
        if i == 0:
            E2 = E1 = k
        else:
            E2 = k
    O1 = O2 = 0
    for i, (k, v) in enumerate(oc.most_common(2)):
        if i == 0:
            O2 = O1 = k
        else:
            O2 = k
    print(min(h-ec[E1] + h - oc[O2], h - ec[E2] + h - oc[O1]))

Solution (Python):
iN = int(input())
aV = [int(_) for _ in input().split()]

aV0={}
aV1={}
for i in range(iN):
    iA = aV[i]
    if i % 2 == 0:
        if iA in aV0:
            aV0[iA] += 1
        else:
            aV0[iA] = 1
    else:
        if iA in aV1:
            aV1[iA] += 1
        else:
            aV1[iA] = 1
aV0[0]=0
aV1[0]=0

aV0dec = sorted(aV0,key=aV0.get,reverse=True)
aV1dec = sorted(aV1,key=aV1.get,reverse=True)

iMax1aV0 = aV0dec[0]
iMax1aV1 = aV1dec[0]

if iMax1aV0 != iMax1aV1:
    print(iN - aV0[iMax1aV0] - aV1[iMax1aV1])
else:
    print(iN - max(aV0[iMax1aV0],aV1[iMax1aV1]) - max(aV0[aV0dec[1]],aV1[aV1dec[1]]))

Solution (Python):
import collections

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

Solution (Python):
n = int(input())
lst = list(map(int, input().split()))
ma = {}
mb = {}
for i in range(0, n, 2):
    lst[i] in ma
    if lst[i] in ma:
        ma[lst[i]] += 1
    else:
        ma[lst[i]] = 1
    lst[i+1] in mb
    if lst[i+1] in mb:
        mb[lst[i+1]] += 1
    else:
        mb[lst[i+1]] = 1
if max(ma, key=ma.get) != max(mb, key=mb.get):
    d = n - max(ma.values()) - max(mb.values())
else:
    ma2 = max(ma.values())
    mb2 = max(mb.values())
    ma[max(ma, key=ma.get)] = 0
    mb[max(mb, key=mb.get)] = 0
    d1 = n - ma2 - max(mb.values())
    d2 = n - max(ma.values()) - mb2
    d = min(d1, d2)
print(d)

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
gu = v[::2]
ki = v[1::2]
ans = 0
k,g = False,False



if v.count(v[0]) == n:
    ans += n // 2
else:
    kic = Counter(ki)
    guc = Counter(gu)
    k1 = kic.most_common(2)
    g1 = guc.most_common(2)
    if k1[0][0] == g1[0][0]:
        if k1[1][1] < g1[1][1]:
            g = True
        else:
            k = True

    kic = list(kic.values())
    guc = list(guc.values())
    kic.sort(reverse = True)
    guc.sort(reverse = True)
    if len(kic) != 1:
        if k:
            ans += kic[0]
            ans += sum(kic[2::])
        else:
            ans += sum(kic[1::]) 
    if len(guc) != 1:
        if g:
            ans += guc[0]
            ans += sum(guc[2::])
        else:
            ans += sum(guc[1::])

print(ans)

Solution (Python):
import collections

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

def calc(vs):
    r = dict(collections.Counter(vs))
    r[0] = 0
    ri = r.items()
    return sorted(ri, key=lambda x:-x[1])

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 = min(N - ve[0][1] - vo[1][1], N - ve[1][1] - vo[0][1])

print(result)

Solution (Python):
from collections import Counter
n = int(input())
x = [int(i) for i in input().split()]
a,b = [],[]
for i in range(n):
	if i%2: a.append(x[i])
	else: b.append(x[i])
ca,cb = Counter(a).most_common(),Counter(b).most_common()
if ca[0][0]!=cb[0][0]: print(n-ca[0][1]-cb[0][1])
elif len(ca)!=1 and len(cb)!=1: print(min(n-ca[0][1]-cb[1][1],n-ca[1][1]-cb[0][1]))
elif len(ca)==len(cb): print(n//2)
elif len(ca)==1: print(n//2-cb[1][1])
else: print(n//2-ca[1][1])

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

"""
9
1 1 1 1 2 2 2 4 
1 1 1 1 3 3 4 4
"""



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

f1 = Counter(v1).most_common(2)
f2 = Counter(v2).most_common(2)

ans = 0

if len(set(v1)) == len(set(v2)) == 1:
    if v1 == v2:
        ans = min(len(v1), len(v2))
else:
    if f1[0][0] != f2[0][0]:
        ans = (len(v1) - f1[0][1]) + (len(v2) - f2[0][1])
    else:
        if f1[1][1] < f2[1][1]:
            ans = (len(v1) - f1[0][1]) + (len(v2) - f2[1][1])
        else:
            ans = (len(v1) - f1[1][1]) + (len(v2) - f2[0][1])
        
print(ans)

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

from collections import Counter
import operator
def f():
    evn = Counter(A[::2])
    odd = Counter(A[1::2])

    a = sorted(odd.most_common(2), key=operator.itemgetter(1, 0), reverse=True)
    b = sorted(evn.most_common(2), key=operator.itemgetter(1, 0), reverse=True)

    ac = (n // 2) - a[0][1]
    bc = (n // 2) - b[0][1]
    ret = ac + bc
    if a[0][0] == b[0][0]:
        bc_2 = n // 2 - (b[1][1] if len(b) != 1 else 0)
        ac_2 = n // 2 - (a[1][1] if len(a) != 1 else 0)
        ret = min(ac + bc_2, ac_2 + bc)
    return ret
print(f())

Solution (Python):
from collections import Counter

n = int(input())
v = [int(i) for i in input().split()]
v_0 = v[0::2]
v_1 = v[1::2]
ans = 0

c0 = Counter(v_0).most_common(2)
c1 = Counter(v_1).most_common(2)


if len(set(v_0)) == len(set(v_1)) == 1:
    if v_0 == v_1:
        ans = min(len(v_0), len(v_1))

else:
    
    if c0[0][0] != c1[0][0]:
        ans = (len(v_0) - c0[0][1]) + (len(v_1) - c1[0][1])
    else:
        w1 = (len(v_0) - c0[0][1]) + (len(v_1) - c1[1][1])
        w2 = (len(v_0) - c0[1][1]) + (len(v_1) - c1[0][1])
        ans = min(w1, w2)

print(ans)

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

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

array_0 = collections.Counter(array[::2]).most_common()
array_1 = collections.Counter(array[1::2]).most_common()


if array_0[0][0] == array_1[0][0]:
    if len(array_0) * len(array_1) == 1:
        print(n // 2)
        exit()
    elif array_0[0][1] > array_1[0][1]:
        print(len(array) - array_1[1][1] - array_0[0][1])
        exit()
    elif array_0[0][1] < array_1[0][1]:
        print(len(array) - array_1[0][1] - array_0[1][1])
        exit()
    else:
        print(min(len(array) - array_1[0][1] - array_0[1][1], len(array) - array_1[1][1] - array_0[0][1]))
        exit()
print(len(array) - array_1[0][1] - array_0[0][1])

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
gu = v[::2]
ki = v[1::2]
ans = 0
k,g = False,False

if v.count(v[0]) == n:
    ans += n // 2
else:
    kic = Counter(ki)
    guc = Counter(gu)
    k1 = kic.most_common(2)
    g1 = guc.most_common(2)
    if k1[0][0] == g1[0][0]:
        if k1[1][1] < g1[1][1]:
            k = True
        else:
            g = True

    kic = list(kic.values())
    guc = list(guc.values())
    kic.sort(reverse = True)
    guc.sort(reverse = True)
    if len(kic) != 1:
        if g:
            ans += kic[0]
            ans += sum(kic[2::])
        else:
            ans += sum(kic[1::]) 
    if len(guc) != 1:
        if k:
            ans += guc[0]
            ans += sum(guc[2::])
        else:
            ans += sum(guc[1::])

print(ans)

Solution (Python):
import collections

n = int(input())

al = [int(l) for l in input().split()]

a = []
b = []
for i, x in enumerate(al):
    if i%2 == 0:
        a.append(x)
    else:
        b.append(x)

ac = collections.Counter(a).most_common()
bc = collections.Counter(b).most_common()

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-max(ac[0][1], bc[0][1]))
    elif len(ac) == 1:
        print(n-max(ac[0][1], ac[1][1]+bc[0][1]))
    elif len(ac) == 1:
        print(n-max(bc[0][1], ac[0][1]+bc[1][1]))
    else:
        print(n-max(ac[1][1]+bc[0][1], ac[0][1]+bc[1][1]))

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

dd_even = defaultdict(int)
dd_odd  = defaultdict(int)


for i in range(0, n, 2):
    dd_even[v[i]] += 1

l_even = list(dd_even.items())
l_even.sort(key= lambda x:x[1])
top_even = l_even[-1][0]



for i in range(1, n, 2):
    dd_odd[v[i]] += 1

l_odd = list(dd_odd.items())
l_odd.sort(key= lambda x:x[1])

top_odd = l_odd[-1][0]

if top_even == top_odd:
    if len(l_odd) == 1: 
        res = int(n / 2)
        print(res)
        sys.exit()
    else:
        
        l_odd_1 = [l for l in l_odd if l[0] != l_odd[-2][0]]
        sum_odd_1 = sum(l[1] for l in l_odd_1)
        l_even_1 = [l for l in l_even if l[0] != top_even]
        sum_even_1 = sum(l[1] for l in l_even_1)
        sum_1 = sum_odd_1 + sum_even_1

        l_odd_2 = [l for l in l_odd if l[0] != top_odd]
        sum_odd_2 = sum(l[1] for l in l_odd_2)
        l_even_2 = [l for l in l_even if l[0] != l_even[-2][0]]
        sum_even_2 = sum(l[1] for l in l_even_2)
        sum_2 = sum_odd_2 + sum_even_2

        if sum_1 < sum_2:
            print(sum_1)
        else:
            print(sum_2)
        sys.exit()
else:
    l_odd = [l for l in l_odd if l[0] != top_odd]

sum_odd = sum(l[1] for l in l_odd)


l_even = [l for l in l_even if l[0] != top_even]
sum_even = sum(l[1] for l in l_even)


res = sum_odd + sum_even
print(res)

Solution (Python):
from collections import defaultdict

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

odds_counter = defaultdict(int)
evens_counter = defaultdict(int)

for o in V[0::2]:
    odds_counter[o] += 1
for e in V[1::2]:
    evens_counter[e] += 1

odds = sorted(odds_counter.items(), key=lambda x: x[1], reverse=True)
evens = sorted(evens_counter.items(), key=lambda x: x[1], reverse=True)

if odds[0][0] != evens[0][0]:
    ans = n - odds[0][1] - evens[0][1]
else:
    if len(odds) == 1 and len(evens) == 1:
        ans = odds[0][1]
    elif len(odds) == 1 and len(evens) != 1:
        ans = n - odds[0][1] - evens[1][1]
    elif len(odds) != 1 and len(evens) == 1:
        ans = n - odds[1][1] - evens[0][1]
    else:
        ans = min(n - odds[0][1] - evens[1][1], n - odds[1][1] - evens[0][1])
print(ans)

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

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

cv1 = collections.Counter(v[::2])
cv2 = collections.Counter(v[1::2])
num1 = cv1.most_common()[0][0]
num2 = cv2.most_common()[0][0]
cnt1 = cv1.most_common()[0][1]
cnt2 = cv2.most_common()[0][1]
if num1==num2:
  cnt3 = cv1.most_common()[1][1]
  cnt4 = cv2.most_common()[1][1]
  a,b = cnt1+cnt4,cnt2+cnt3
  print(min(n-a,n-b))
  exit()
print(n-(cnt1+cnt2))

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

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

f1 = Counter(v1).most_common(2)
f2 = Counter(v2).most_common(2)

ans = 0

if len(set(v1)) == len(set(v2)) == 1:
    if v1 == v2:
        ans = min(len(v1), len(v2))
else:
    if f1[0][0] != f2[0][0]:
        ans = (len(v1) - f1[0][1]) + (len(v2) - f2[0][1])
    else:
        ans1 = (len(v1) - f1[0][1]) + (len(v2) - f2[1][1])
        ans2 = (len(v1) - f1[1][1]) + (len(v2) - f2[0][1])
        ans = min(ans1, ans2)

print(ans)

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

a = [ v[i] for i in range(0,n,2)]
b = [ v[i] for i in range(1,n,2)]
A = [0] * 100010
B = [0] * 100010

for i in range(int(n/2)):
    A[a[i]] += 1
    B[b[i]] += 1

if A.index(max(A)) == B.index(max(B)):
    BB = sorted(B)
    cc1 = len(b) - BB[-2] + len(a) - max(A)
    AA = sorted(A)
    cc2 = len(a) - AA[-2] + len(b) - max(B)
    if cc1 > cc2:
        print(cc2)
    else:
        print(cc1)
else:
    print(n - max(A) - max(B))

Solution (Python):

import collections
n=int(input())
all_str=list(map(int,input().split()))
i=0
j=0
o_str=[]   
e_str=[]   
while(2*i<n):
  o_str.append(all_str[2*i])
  i+=1
while(2*j+1<n):
  e_str.append(all_str[2*j+1])
  j+=1

o_c=collections.Counter(o_str)
e_c=collections.Counter(e_str)
o_mode=o_c.most_common()[0][0]
e_mode=e_c.most_common()[0][0]
o_mode_n=o_str.count(o_mode)
e_mode_n=e_str.count(e_mode)
if(o_mode==e_mode):
  if(len(o_c)==1 and len(e_c)==1):
    if(o_mode_n>e_mode_n):
      e_mode_n=0
      
    else:
      
      o_mode_n=0
      
  else:
    if(len(o_c)==1):
      o_c_sec=0
      e_c_sec=e_c.most_common()[1][1]
    elif(len(e_c)==1):
      e_c_sec=0
      o_c_sec=o_c.most_common()[1][1]
    else:
      o_c_sec=o_c.most_common()[1][1]
      e_c_sec=e_c.most_common()[1][1]
    if(o_c_sec>e_c_sec):
      o_mode_n=o_c.most_common()[1][1]
    else:
      e_mode_n=e_c.most_common()[1][1]
alt=len(all_str)-o_mode_n-e_mode_n
print(alt)

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
l = list(range(n))
odd = [v[i] for i in l if i%2 == 0]
even = [v[i] for i in l if i%2 == 1]

import collections
oddm = collections.Counter(odd).most_common()
evenm = collections.Counter(even).most_common()

if oddm[0][0] != evenm[0][0]:
    a = (n/2)-oddm[0][1]+(n/2)-evenm[0][1]
else:
    if len(oddm) == 1 and len(evenm) == 1:
        a = n/2
    elif len(oddm) == 1:
        a = (n/2)-evenm[1][1]
    elif len(evenm) == 1:
        a = (n/2)-oddm[1][1]
    else:
        a = n-max(evenm[1][1]+oddm[0][1],evenm[0][1]+oddm[1][1])

print(int(a))

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

def add_entry(hist, aa):
    if aa in hist:
        hist[aa] += 1
    else:
        hist[aa] = 1


def make_hist(a):
    even_hist = {}
    odd_hist = {}

    for i in range(len(a)//2):
        add_entry(even_hist, a[2*i])
        add_entry(odd_hist, a[2*i+1])

    return even_hist, odd_hist


def get_sorted_hist(hist):
    return sorted(hist.items(), key=lambda x: -x[1])

eh, oh = make_hist(a)
seh = get_sorted_hist(eh)
soh = get_sorted_hist(oh)


if seh[0][0] != soh[0][0]:
    print(len(a) - seh[0][1] - soh[0][1])
else:
    if len(seh) == 1 and len(soh) == 1:
        print(len(a)//2)
    elif len(seh) == 1:
        print(len(a) - seh[0][1] - soh[1][1])
    elif len(soh) == 1:
        print(len(a) - soh[0][1] - seh[1][1])
    else:
        print(min(len(a) - seh[0][1] - soh[1][1], len(a) - soh[0][1] - seh[1][1]))

Solution (Python):
import collections

n = input()
nums = list(map(int, input().split()))
odd = nums[0::2]
even = nums[1::2]
odd_c = collections.Counter(odd)
even_c = collections.Counter(even)


if odd_c.most_common(1)[0][0] == even_c.most_common(1)[0][0]:
    if len(odd_c) >= 3 and len(even_c) >= 3:
        odd_first_count = len(odd) - odd_c.most_common(1)[0][1]
        even_first_count = len(even) - even_c.most_common(1)[0][1]
        odd_second_count = len(odd) - odd_c.most_common(2)[1][1]
        even_second_count = len(even) - even_c.most_common(2)[1][1]
        if odd_first_count + even_second_count < odd_second_count + even_first_count:
            print(odd_first_count + even_second_count)
            exit()
        else:
            print(odd_second_count + even_first_count)
            exit()
    odd_next_most = 0
    even_next_most = 0
    if len(odd_c) >= 2:
        odd_next_most = odd_c.most_common(2)[1][1]
    if len(even_c) >= 2:
        even_next_most = even_c.most_common(2)[1][1]
    if odd_next_most > even_next_most:
        print(len(odd) - odd_next_most + len(even) - even_c.most_common(1)[0][1])
    else:
        print(len(odd) - odd_c.most_common(1)[0][1] + len(even) - even_next_most)
else:
    odd_change = len(odd) - odd_c.most_common(1)[0][1]
    even_change = len(even) - even_c.most_common(1)[0][1]
    print(odd_change + even_change)

Solution (Python):
import collections
n = int(input())
v = input().split()
v_int = [int(i) for i in v]
v_odd = []
v_even = []
for i in range(int(n/2)):
  v_even.append(v_int[i*2])
  v_odd.append(v_int[i*2+1])
c_odd = collections.Counter(v_odd)
c_even = collections.Counter(v_even)
max_odd = 0
second_odd = 0
max_key_odd = 0
for key in c_odd:
  if max_odd < c_odd[key]:
    second_odd = max_odd
    max_odd = c_odd[key]
    max_key_odd = key
  elif second_odd < c_odd[key]:
    second_odd = c_odd[key]
    
max_even = 0
second_even = 0
max_key_even = 0
for key in c_even:
  if max_even < c_even[key]:
    second_even = max_even
    max_even = c_even[key]
    max_key_even = key
  elif second_even < c_even[key]:
    second_even = c_even[key]
    
if max_key_even != max_key_odd:
  print(int(n)- max_even - max_odd)
else:
  if max_even > max_odd:
    if max_even == second_even:
      print(int(n) - max_even - max_odd)
    else:
      print(int(n) - max_even - second_odd)
  elif max_even < max_odd:
    if max_odd == second_odd:
      print(int(n) - max_odd - max_even)
    else:
      print(int(n) - max_odd - second_even)
  else : 
    if second_odd > second_even:
      print(int(n) - max_even - second_odd)
    else :
      print(int(n) - max_odd - second_even)

Solution (Python):
n = int(input())

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

v1 = {}

v2 = {}

for i in range(n//2):
    if  v[2 *i +1] in v1.keys():
        v1[v[2 * i +1]] += 1
    else:
        v1[v[2 * i + 1]] = 1

    if v[2 * i] in v2.keys():
        v2[v[2 * i]] += 1
    else:
        v2[v[2 * i]] = 1


v1 = sorted(v1.items(),key=lambda x:  x[1])
v2 = sorted(v2.items(),key=lambda x:  x[1])
v1.reverse()
v2.reverse()
v1.append((None,0))
v2.append((None,0))

if v1[0][0] == v2[0][0]:
    ans = max(v1[0][1]+v2[1][1] , v1[1][1] + v2[0][1])
else:
    ans = v1[0][1] + v2[0][1]

print(n - ans)

Solution (Python):

from collections import Counter
import sys

def debug(*f):
    print(*f, file=sys.stderr)

def f(odd, even, N):
    debug(N, odd, even)


def main(N, V):
    debug("N=",N)
    debug("V=",V)
    N = int(N)
    V = [int(x) for x in V.split(" ")]

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

    if odd[0][0] != even[0][0]: 
        return N - odd[0][1] - even[0][1]
    else:
        if odd[0][1] > even[0][1]:
            return N - odd[0][1] - even[1][1]
        elif odd[0][1] < even[0][1]:
            return N - odd[1][1] - even[0][1]
        elif odd[0][1] == N // 2:
            return N // 2
        else:
            return N - odd[0][1]  - max(odd[1][1], even[1][1])



if 0==1:
    import sys
    assert main("4", "3 1 3 2") == 1
    assert main("4", "1 1 1 1") == 2
    assert main("6", "105 119 105 119 105 119") == 0
    assert main("14", "1 1 1 1 1 1 2 2 2 2 3 4 3 5") == 9

    print("OK", file=sys.stderr)


N = input()
V = input()
print(main(N, V))

Solution (Python):
from collections import Counter

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

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

counter1 = dict(Counter(v1))
counter2 = dict(Counter(v2))
x1 = max(counter1, key=counter1.get)
x2 = max(counter2, key=counter2.get)
x1_c = counter1[x1]
x2_c = counter2[x2]
del counter1[x1]
del counter2[x2]
y1_c = 0
y2_c = 0
if len(counter1) != 0:
    y1_c = max(counter1.values())
if len(counter2) != 0:
    y2_c = max(counter2.values())

n = n//2
ans = 0
if x1 == x2:
    ans = min((n - x1_c) + (n - y2_c), (n - y1_c) + (n - x2_c))
else:
    ans = (n - x1_c) + (n - x2_c)

print(ans)

Solution (Python):
n = int(input())
array = [int(x) for x in input().split()]
tmp_dict = {}
tmp_dict2 = {}
tmp_array = array[::2]
tmp_array2 = array[1::2]
for i in tmp_array:
    if i in tmp_dict.keys():
        tmp_dict[i] += 1
    else:
        tmp_dict[i] = 1
for i in tmp_array2:
    if i in tmp_dict2.keys():
        tmp_dict2[i] += 1
    else:
        tmp_dict2[i] = 1

sorted_dict = sorted(tmp_dict.items(), key=lambda x: x[1], reverse=True)
sorted_dict2 = sorted(tmp_dict2.items(), key=lambda x: x[1], reverse=True)
tmp = sorted_dict[0][0]
tmp2 = sorted_dict2[0][0]

aaa = array[0]
if array.count(aaa) == len(array):
    print(len(array)//2)
    exit()

if tmp == tmp2:
    if len(sorted_dict) == 1:
        tmp2 = sorted_dict2[1][0]
    elif len(sorted_dict2) == 1:
        tmp = sorted_dict[1][0]
    else:
        if sorted_dict2[1][1] > sorted_dict[1][1]:
            tmp2 = sorted_dict2[1][0]
        elif sorted_dict2[1][1] <= sorted_dict[1][1]:
            tmp = sorted_dict[1][0]
res = 0
for i in tmp_array:
    if i != tmp:
       res += 1

for i in tmp_array2:
    if i != tmp2:
       res += 1
print(res)

Solution (Python):
from collections import Counter

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

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

counter1 = dict(Counter(v1))
counter2 = dict(Counter(v2))
x1 = max(counter1, key=counter1.get)
x2 = max(counter2, key=counter2.get)
x1_c = counter1[x1]
x2_c = counter2[x2]
del counter1[x1]
del counter2[x2]
y1_c = 0
y2_c = 0
if len(counter1) != 0:
    y1_c = max(counter1.values())
if len(counter2) != 0:
    y2_c = max(counter2.values())

n = n//2
ans = 0
if x1 == x2:
    ans = min((n - x1_c) + (n - y2_c), (n - y1_c) + (n - x2_c))
    """
    if x1_c > x2_c:
        ans = (n - x1_c) + (n - y2_c)
    else:
        ans =  (n - y1_c) + (n - x2_c)
    """
else:
    ans = (n - x1_c) + (n - x2_c)

print(ans)

Solution (Python):
import collections

n = int(input())
vs = [int(i) for i in input().split()]
evens = []
odds = []
for i,num in enumerate(vs):
    if i % 2 == 0:
        evens.append(num)
    elif i % 2 == 1:
        odds.append(num)

def plana():
    if (len(set(vs)) == 2) and (len(set(evens)) == 1) and (len(set(odds)) == 1):
        return 0
    elif (len(set(vs)) == 1):
        return len(evens)
    ec = collections.Counter(evens)
    oc = collections.Counter(odds)

    
    if ec.most_common()[0][0] == oc.most_common()[0][0]:
        if len(set(evens))==1:
            return len(odds)-oc.most_common()[1][1]
        elif len(set(odds))==1:
            return len(evens)-ec.most_common()[1][1]
        e1 = ec.most_common()[0][1]
        e2 = ec.most_common()[1][1]
        o1 = oc.most_common()[0][1]
        o2 = oc.most_common()[1][1]
        count1 = 0
        count2 = 0
        count1 += (len(evens) - e1)
        count1 += (len(odds) - o2)
        count2 += (len(odds) - o1)
        count2 += (len(evens) - e2)
        if (count1 >= count2):
            return count2
        else:
            return count1

        
        
        
        
        
        
        
        
        
        

    count = 0
    count += (len(evens) - ec.most_common()[0][1])
    count += (len(odds) - oc.most_common()[0][1])
    return count

print(int(plana()))

Solution (Python):
def main():
    N = int(input())
    v = list(map(int, input().split()))
    v_ki = v[1:N:2].copy()
    val_ki = [i+1 for i in range(10**5)]
    count_ki = [0] * (10**5)
    v_gu = v[0:N:2].copy()
    val_gu = [i+1 for i in range(10**5)]
    count_gu = [0] * (10**5)
    for i in range(N//2):
        count_ki[v_ki[i]-1] += 1
        count_gu[v_gu[i]-1] += 1
    
    ki = list(zip(count_ki, val_ki))
    ki.sort()
    gu = list(zip(count_gu, val_gu))
    gu.sort()
    if ki[-1][1] != gu[-1][1]:
        return N-ki[-1][0]-gu[-1][0]
    else:
        return min(N-ki[-2][0]-gu[-1][0], N-ki[-1][0]-gu[-2][0])

if __name__ == "__main__":
    print(main())

Solution (Python):
import collections

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

odd = [v[2 * i] for i in range(N // 2)]
even = [v[2 * i + 1] for i in range(N // 2)]



odd_dict = sorted(collections.Counter(odd).items(), key=lambda x: x[1])[::-1]
even_dict = sorted(collections.Counter(even).items(), key=lambda x: x[1])[::-1]




if odd_dict[0][0] != even_dict[0][0]:
    odd_sum = N // 2 - odd_dict[0][1]
    even_sum = N//2 - even_dict[0][1]
    
    
    print(odd_sum + even_sum)

else:
    odd_len = len(odd_dict)
    even_len = len(even_dict)

    if (odd_len == 1) and (even_len == 1):
        print(N//2)
    elif (odd_len == 1) and (even_len != 1):
        even_val, even_sec_val = even_dict[0][1], even_dict[1][1]
        print(N//2 - even_sec_val)

    elif (odd_len != 1) and (even_len == 1):
        odd_val, odd_sec_val = odd_dict[0][1], odd_dict[1][1]
        print(N // 2 - odd_sec_val)

    else:
        odd_val, odd_sec_val = odd_dict[0][1], odd_dict[1][1]
        even_val, even_sec_val = even_dict[0][1], even_dict[1][1]
        print(min(N - odd_val - even_sec_val, N - odd_sec_val - even_val))

Solution (Python):
import collections
n=int(input())
N=list(map(int,input().split(" ")))
list_odd=N[::2]
list_even=N[1::2]
c_odd = collections.Counter(list_odd)
c_even = collections.Counter(list_even)
most_odd=c_odd.most_common()[0][1]
most_even=c_even.most_common()[0][1]
if (n<=2):
    print("0")
elif (len(list_even)==most_even and len(list_odd)==most_odd and c_odd.most_common()[0][0]==c_even.most_common()[0][0]):
    print(most_odd)
else:
    if(c_odd.most_common()[0][0]==c_even.most_common()[0][0]):
        M=max(c_odd.most_common()[1][1],c_even.most_common()[1][1])
        print(min((len(list_even)+len(list_odd)-M-most_odd),(len(list_even)+len(list_odd)-M-most_even)))
    else:
        print(len(list_even)+len(list_odd)-most_even-most_odd)

Solution (Python):
n = int(input())
nums = list(map(int,input().split()))
odd,even={},{}
for i in range(n):
  if i%2 == 0:
    if nums[i] in even:
      even[nums[i]] += 1
    else:
      even[nums[i]] = 1
  else:
    if nums[i] in odd:
      odd[nums[i]] += 1
    else:
      odd[nums[i]] = 1

if len(odd) == 1 and len(even) == 1:
  if odd == even:
    print(n//2)
  else:
    print(0)
elif len(even) == 1 and 1 < len(odd):
  for a,b in even.items():
    for k,v in sorted(odd.items(), key=lambda x: -x[1]):
      if a == k:
        continue
      else:
        print(n//2 - v)
        exit()
elif len(odd) == 1 and 1 < len(even):
  for a,b in odd.items():
    for k,v in sorted(even.items(), key=lambda x: -x[1]):
      if a == k:
        continue
      else:
        print(n//2 - v)
        exit()
else:
  a = sorted(odd.items(), key=lambda x: -x[1])
  b = sorted(even.items(), key=lambda x: -x[1])
  if a[0][0] == b[0][0]:
    print(n - max(a[0][1]+b[1][1],a[1][1]+b[0][1]))
  else:
    print(n - a[0][1] - b[0][1])

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

o=[]
e=[]


for i in range(n):
    if i%2==1:
        o.append(a[i])
    else:
        e.append(a[i])

oc = Counter(o)
ec = Counter(e)

ok=[]
ek=[]
ol=[]
el=[]
for word, cnt in oc.most_common():
    ok.append(cnt)
    ol.append(word)
for word, cnt in ec.most_common():
    ek.append(cnt)
    el.append(word)

if len(ok)==1:
    ok.append(0)
if len(ek)==1:
    ek.append(0)
if el[0]!=ol[0]:
    print(n-ok[0]-ek[0])
else:
    print(min(n-ok[1]-ek[0],n-ok[0]-ek[1]))