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 = [int(i) for i in input().split()]
v_even = [v[i] for i in range(len(v)) if i % 2 == 0]
v_odd = [v[i] for i in range(len(v)) if i % 2 == 1]

even_c = Counter(v_even)
odd_c = Counter(v_odd)


if odd_c.most_common()[0][0] != even_c.most_common()[0][0]:  
    output = N-(odd_c.most_common()[0][1] + even_c.most_common()[0][1])
elif N - (odd_c.most_common()[0][1] + even_c.most_common()[0][1]) == 0:  
    output = N // 2
else:
    if len(even_c) != even_c.most_common()[0][1]:
        frag1 = True
        output1 = N - (odd_c.most_common()[0][1] + even_c.most_common()[1][1])
    else:
        frag1 = False
    if len(odd_c) != odd_c.most_common()[0][1]:
        frag2 = True
        output2 = N - (odd_c.most_common()[1][1] + even_c.most_common()[0][1])
    else:
        frag2 = False
    if frag1 and frag2:
        output = min(output1, output2)
    elif frag1:
        output = output1
    elif frag2:
        output = output2
print(output)

Solution (Python):
def sortcounts(c: dict):
    a = [(v, k) for k, v in c.items()]
    return sorted(a, reverse=True)


def solve(a):
    m = len(a)//2

    o = [a[i] for i in range(len(a)) if i%2==0]
    e = [a[i] for i in range(len(a)) if i%2==1]

    
    

    import collections
    co = sortcounts(collections.Counter(o))
    ce = sortcounts(collections.Counter(e))

    
    

    no, vo = co[0]
    ne, ve = ce[0]

    if vo != ve:
        ans = (m-no) + (m-ne)
    else:
        anse = (m-no) + m-(0 if len(co)<2 else co[1][0])
        anso = (m-ne) + m-(0 if len(ce)<2 else ce[1][0])
        ans = min(anse, anso)

    return ans


def main():
    _=input()
    a = list(map(int, input().split()))
    print(solve(a))


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
cnt = [[0 for j in range(10**5)] for i in range(2)]
for i in range(n):
  cnt[i%2][v[i]-1] += 1
maxce = max(cnt[0])
maxco = max(cnt[1])
maxve = -1
maxvo = -1
for i in range(len(cnt[0])):
  if(cnt[0][i] == maxce):
    maxve = i
    break
for i in range(len(cnt[1])):
  if(cnt[1][i] == maxco):
    maxvo = i
    break
if(maxvo != maxve):
  print((n//2 - maxco) + (n - n//2 - maxce))
else:
  cnt[0].pop(maxve)
  cnt[1].pop(maxvo)
  maxce2 = max(cnt[0])
  maxco2 = max(cnt[1])
  print(min((n//2 - maxco2) + (n - n//2 - maxce), (n//2 - maxco) + (n - n//2 - maxce2)))

Solution (Python):
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
A=V[::2]
B=V[1::2]
A_counter=Counter(A)
a_freqnum=A_counter.most_common()[0][0]
a_freq=A_counter.most_common()[0][1]
B_counter=Counter(B)
b_freqnum=B_counter.most_common()[0][0]
b_freq=B_counter.most_common()[0][1]
if a_freqnum!=b_freqnum:
    ans=n-(a_freq+b_freq)
else:
    if a_freq==n//2:
        if b_freq==n//2:
            ans=n//2
        else:
            b_freq_sec=B_counter.most_common()[1][1]
            ans=n//2-b_freq_sec
    else:
        a_freq_sec=A_counter.most_common()[1][1]
        if b_freq==n//2:
            ans=n//2-a_freq_sec
        else:
            b_freq_sec=B_counter.most_common()[1][1]
            ans=n-a_freq-max(a_freq_sec,b_freq_sec)
print(ans)

Solution (Python):
import numpy as np
N=int(input())
s=np.array(list(map(int,input().split())))

d_even=np.zeros(np.max(s)+1)
d_odd=np.zeros(np.max(s)+1)

for i in range(N//2):
    d_even[s[2*i]]+=1
    d_odd[s[2*i+1]]+=1
    
se=np.argsort(d_even)[::-1]
so=np.argsort(d_odd)[::-1]

e1=se[0]
e2=se[1]
o1=so[0]
o2=so[1]

if e1!=o1:
    ans=N-d_even[e1]-d_odd[o1]
else:
    ans=min(N-d_even[e1]-d_odd[o2],N-d_even[e2]-d_odd[o1])     
        
print(int(ans))

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

even_dict = {}
odd_dict = {}

for i in range(n//2):
	tmp = v_even[i]
	if tmp not in even_dict:
		even_dict[tmp] = 1
	else:
		even_dict[tmp] += 1
	tmp = v_odd[i]
	if tmp not in odd_dict:
		odd_dict[tmp] = 1
	else:
		odd_dict[tmp] += 1

odd_items = sorted(odd_dict.items(), key=lambda x:x[1], reverse=True)
even_items = sorted(even_dict.items(), key=lambda x:x[1], reverse=True)
odd_items.append((0,0))
even_items.append((0,0))

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

Solution (Python):
import collections

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

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

odd_c = collections.Counter(odd)
eve_c = collections.Counter(eve)

odd_key = odd_c.most_common()[0][0]
odd_value = odd_c.most_common()[0][1]
eve_key = eve_c.most_common()[0][0]
eve_value = eve_c.most_common()[0][1]

if odd_key == eve_key:
    if odd_value > eve_value:
        if len(eve_c.most_common()) == 1:
            eve_value = 0
        else:
            eve_key = eve_c.most_common()[1][0]
            eve_value = eve_c.most_common()[1][1]
    elif odd_value > eve_value:
        if len(odd_c.most_common()) == 1:
            odd_value = 0
        else:
            odd_key = odd_c.most_common()[1][0]
            odd_value = odd_c.most_common()[1][1]
    elif odd_value == eve_value:
        if len(odd_c.most_common()) == 1 or len(eve_c.most_common()) == 1:
            odd_value = 0
        else:
            if odd_c.most_common()[1][1] >= eve_c.most_common()[1][1]:
                odd_key = odd_c.most_common()[1][0]
                odd_value = odd_c.most_common()[1][1]
            else:
                eve_key = eve_c.most_common()[1][0]
                eve_value = eve_c.most_common()[1][1]
else:
    pass

ans = int(n/2 - eve_value + n/2 - odd_value)
print(ans)

Solution (Python):


















import collections
def inpl(): return list(map(int, input().split()))


N = int(input())
h_H = int(N/2)
V = list(map(int,input().split()))
v1 = [i for i in V[::2]]
v2 = [i for i in V[1::2]]

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


best1 = h_H - c1.most_common()[0][1]

if c1.most_common()[0] != c2.most_common()[0]:
    best1 += h_H - c2.most_common()[0][1]
else:
    if len(c1) == 1:
      best1 += h_H
    else:
      best1 += h_H - c2.most_common()[1][1]


best2 = h_H - c2.most_common()[0][1]

if c1.most_common()[0] != c2.most_common()[0]:
    best2 += h_H - c1.most_common()[0][1]
else:
    if len(c2) == 1:
      best2 += h_H
    else:
      best2 += h_H - c1.most_common()[1][1]

print(min([best1, best2]))

Solution (Python):
from collections import Counter
n = int(input())
vl = [int(i) for i in input().split()]
oc = Counter(a for i, a in enumerate(vl) if i % 2 == 0)
ec = Counter(a for i, a in enumerate(vl) if i % 2 == 1)
ol = sorted(((v, k) for k, v in oc.items()), reverse=True)
el = sorted(((v, k) for k, v in ec.items()), reverse=True)

if ol[0][1] != el[0][1]:
    print(n - ol[0][0] - el[0][0])
else:
    res = 1 << 30
    if len(ol) == len(el) == 1:
        res = n // 2
    if len(ol) > 1:
        res = min(res, n - ol[1][0] - el[0][0])
    if len(el) > 1:
        res = min(res, n - ol[0][0] - el[1][0])
    print(res)

Solution (Python):
from collections import Counter


def main():
    n = int(input())
    aa = list(map(int, input().split()))
    cs_a0 = Counter(a for i, a in enumerate(aa) if i % 2 == 0)
    cs_a1 = Counter(a for i, a in enumerate(aa) if i % 2 == 1)
    vs_a0 = sorted(((v, k) for k, v in cs_a0.items()), reverse=True)
    vs_a1 = sorted(((v, k) for k, v in cs_a1.items()), reverse=True)
    if vs_a0[0][1] != vs_a1[0][1]:
        print(n - vs_a0[0][0] - vs_a1[0][0])
    else:
        res = 1 << 30
        if len(vs_a0) == 1 and len(vs_a1) == 1:
            res = n // 2
        if len(vs_a0) > 1:
            res = min(res, n - vs_a0[1][0] - vs_a1[0][0])
        if len(vs_a1) > 1:
            res = min(res, n - vs_a0[0][0] - vs_a1[1][0])
        print(res)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
V = list(map(int,input().split()))
even = [0]*(10**5+10)
odd = [0]*(10**5+10)
for v in V[::2]:
  even[v] += 1
for v in V[1::2]:
  odd[v] += 1
max_even = max(even)
max_odd = max(odd)
if(even.index(max_even) != odd.index(max_odd)):
  print(N - max_even - max_odd)
else:
  even.sort(reverse = True)
  odd.sort(reverse = True)
  print(min(N - even[0] - odd[1], N - even[1] - odd[0]))

Solution (Python):
import collections
n=int(input())
v=list(map(int,input().split()))
ve=v[0::2]
vo=v[1::2]

ce=collections.Counter(ve).most_common(2)
co=collections.Counter(vo).most_common(2)

if len(set(v))==1:
    ans=n//2
else:
    if ce[0][0]!=co[0][0]:
        ans=n-ce[0][1]-co[0][1]
    elif ce[0][0]==co[0][0] and len(ce)==1:
        ans=n//2-co[0][0]
    elif ce[0][0]==co[0][0] and len(co)==1:
        ans=n//2-ce[0][0]
    else:
        ans=n-max(ce[0][1],co[0][1])-max(ce[1][1],co[1][1])
print(ans)

Solution (Python):
N = int(input())
V = list(map(int,input().split()))
even = [0]*(10**5+10)
odd = [0]*(10**5+10)
for v in V[1::2]:
  even[v] += 1
for v in V[::2]:
  odd[v] += 1
max_even = max(even)
max_odd = max(odd)
if(even.index(max_even) != odd.index(max_odd)):
  print(N - max_even - max_odd)
else:
  even.sort(reverse = True)
  odd.sort(reverse = True)
  print(min(N - even[0] - odd[1], N - even[1] - odd[0]))

Solution (Python):
import collections
n=int(input())
v=list(map(int,input().split()))
ve=v[0::2]
vo=v[1::2]

ce=collections.Counter(vo).most_common(2)
co=collections.Counter(ve).most_common(2)

if ce[0][0] != co[0][0]:
    ans = len(v)-ce[0][1]-co[0][1]
elif len(ce)==1 and len(co)==1:
    ans = len(v)//2
elif len(ce)==1:
    ans = len(v)//2 - co[1][1]
elif len(co)==1:
    ans = len(v)//2-ce[1][1]
else:
    ans = len(v)-max(ce[0][1]+co[1][1],ce[1][1]+co[0][1])
print(ans)

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
e=[0 for _ in range(1,10**5+2)]
o=[0 for _ in range(1,10**5+2)]
for i in range(0,n,2):
    e[v[i]]+=1
    o[v[i+1]]+=1
ans=0
if len(set(v))==1:
    ans=n//2
else:
    me=max(e)
    mo=max(o)
    mei=e.index(me)
    moi=o.index(mo)
    if mei==moi:
        e[mei]=0
        o[moi]=0
        ans += n-max(me,mo)-max(max(e),max(o))
    else:
        ans=n-max(e)-max(o)
print(ans)

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
e=[0 for _ in range(1,10**5+2)]
o=[0 for _ in range(1,10**5+2)]
for i in range(0,n,2):
    e[v[i]]+=1
    o[v[i+1]]+=1
ans=0
if len(set(v))==1:
    ans=n//2
else:
    me=max(e)
    mo=max(o)
    mei=e.index(me)
    moi=o.index(mo)
    if mei==moi:
        e[mei]=0
        o[moi]=0
        ans += n-me-max(max(e),max(o))
    else:
        ans=n-max(e)-max(o)
print(ans)

Solution (Python):
N = input()

if N == 2:
    a,b = map(int,raw_input().split())
    if a != 0:
        print 0
    else:
        print 1
else:
    odd = [0 for i in range(100000)]
    even = [0 for i in range(100000)]
    v = map(int,raw_input().split())

    for i in range(N):
        if i%2 == 0:
            even[v[i]-1] += 1
        else:
            odd[v[i]-1] += 1
    
    if odd.index(max(odd)) != even.index(max(even)):
        print N-max(odd)-max(even)
    else:
        oddnum = max(odd)
        evennum = max(even)
        odd.remove(oddnum)
        even.remove(evennum)
        if max(odd) < max(even):
            print N-oddnum-max(even)
        else:
            print N-max(odd)-evennum

Solution (Python):
import collections

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

even = []
odd = []
for n, i in enumerate(lst):
    if n % 2 == 0:
        even.append(i)
    else:
        odd.append(i)

counter_odd = collections.Counter(odd)
counter_odd = counter_odd.most_common()

counter_even = collections.Counter(even)
counter_even = counter_even.most_common()


if counter_odd[0][0] != counter_even[0][0]:
    print(len(odd) - counter_odd[0][1] + len(even) - counter_even[0][1])
elif len(counter_odd) == len(counter_even) == 1:
    print(len(odd))
elif len(counter_odd) == 1:
    print(len(even) - counter_even[1][1])
elif len(counter_even) == 1:
    print(len(odd) - counter_odd[1][1])
elif counter_odd[1][1] + counter_even[0][1] > counter_even[1][1] + counter_odd[0][1]:
    print(len(odd) - counter_odd[1][1] + len(even) - counter_even[0][1])
else:
    print(len(odd) - counter_odd[0][1] + len(even) - counter_even[1][1])

Solution (Python):
import collections
n = int(input())
v = list(map(int, input().split()))
ve = v[0::2]
vo = v[1::2]


ce=collections.Counter(vo).most_common(2)
co=collections.Counter(ve).most_common(2)

if(ce[0][0] != co[0][0]):
    ans = len(v) - ce[0][1] - co[0][1]
elif(len(ce)==1 and len(co)==1):
    ans = len(v) // 2
elif(len(ce)==1):
    ans = len(v) // 2 - co[1][1]
elif(len(co)==1):
    ans = len(v) // 2 - ce[1][1]
else:
    ans = len(v) - max( ce[0][1]+co[1][1], ce[1][1]+co[0][1])

print(ans)

Solution (Python):
a = int(input())
x = list(map(int, input().split()))
y=[]
z=[]
from collections import Counter
for i in range(a):
    if i%2==0:
        y.append(x[i])
    else:
        z.append(x[i])
y.append(0)
z.append(0)
c= Counter(y)
d = Counter(z)
c1=c.most_common()[0][1]
if c.most_common()[1][0]==0:c2=0
else:c2=c.most_common()[1][1]
d1=d.most_common()[0][1]
if d.most_common()[1][0]==0:d2=0
else:d2=d.most_common()[1][1]

if c.most_common()[0][0]== d.most_common()[0][0]:
    s = a-max(c1+d2,c2+d1)
    
    
    

else:s= a - c.most_common()[0][1] - d.most_common()[0][1]
print(s)

Solution (Python):
import collections

n = int(input())
v_list = [int(x) for x in input().split()]
v_oddlist = v_list[::2]
v_evenlist = v_list[1::2]
c_odd = collections.Counter(v_oddlist)
c_even = collections.Counter(v_evenlist)
if c_odd.most_common()[0][0] != c_even.most_common()[0][0]:
    print(n - c_odd.most_common()[0][1] - c_even.most_common()[0][1])
elif len(c_odd.most_common()) == 1 and len(c_even.most_common()) == 1:
    print(n - c_odd.most_common()[0][1])
else:
    a = c_odd.most_common()[0][1] + c_even.most_common()[1][1]
    b = c_odd.most_common()[1][1] + c_even.most_common()[0][1]
    if a > b:
        print(n - a)
    else:
        print(n - b)

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
E=[0]*(n//2)
O=[0]*(n//2)
for i in range(n):
    if i%2==0:
        O[i//2]=v[i]
    else:
        E[i//2]=v[i]
cntE=Counter(E)
cntO=Counter(O)
if cntE.most_common()[0][0]!=cntO.most_common()[0][0]:
    print(n-cntE.most_common()[0][1]-cntO.most_common()[0][1])
else:
    if len(cntE.most_common())==1 and len(cntO.most_common())==1:
        print(n//2)
    elif len(cntE.most_common())==1:
        print(n-cntE.most_common()[0][1]-cntO.most_common()[1][1])
    elif len(cntO.most_common())==1:
        print(n-cntE.most_common()[1][1]-cntO.most_common()[0][1])
    else:
        print(min(n-cntE.most_common()[0][1]-cntO.most_common()[1][1],n-cntE.most_common()[1][1]-cntO.most_common()[0][1]))

Solution (Python):
n = int(input())
v = [int(i) for i in input().split()] 
import collections
if len(set(v))  == 1:
    print(int(len(v) / 2))
else:
    a = collections.Counter(v[0::2]).most_common()
    b = collections.Counter(v[1::2]).most_common() 
    if a[0][0] == b[0][0]:
        print(min((len(v[0::2]) - a[1][1] + len(v[1::2]) - b[0][1]),(len(v[0::2]) - a[0][1] + len(v[1::2]) - b[1][1])))
    else:
        print(len(v[0::2]) - a[0][1] + len(v[1::2]) - b[0][1])

Solution (Python):
N = int(input())
V = list(map(int,input().split()))
even = [0] * (10 ** 5 + 10)
odd = [0] * (10 ** 5 + 10)
for v in V[1::2]:
  even[v] += 1
for v in V[::2]:
  odd[v] += 1
max_even = max(even)
max_odd = max(odd)
if(even.index(max_even) != odd.index(max_odd)):
  print(N - max_even - max_odd)
else:
  even.sort(reverse = True)
  odd.sort(reverse = True)
  print(min(N - even[0] - odd[1], N - even[1] - odd[0]))

Solution (Python):


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

    ct = []
    ct.append([0] * 101010)
    ct.append([0] * 101010)

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

    m0 = max(ct[0])
    m1 = max(ct[1])
    i0 = ct[0].index(m0)
    i1 = ct[1].index(m1)

    r = 0
    if i0 != i1:
        r = n - m0 - m1
    else:
        ct[0][i0] = 0
        ct[1][i1] = 0
        m2 = max(ct[0])
        m3 = max(ct[1])
        r = n - m0 - max(m2, m3)


    print(r)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
tmp = list(map(int, input().split()))
V, W = {}, {}
for i in range(n):
    key = tmp[i]
    if i%2 == 0:
        if key not in V:
            V[key] = 0
        V[key] += 1
    else:  
        if key not in W:
            W[key] = 0
        W[key] += 1


V = sorted(V.items(), key=lambda x: -x[1])
W = sorted(W.items(), key=lambda x: -x[1])
if V[0][0] != W[0][0]:
    
    print(n - V[0][1] - W[0][1])

elif len(V) == 1 and len(W) == 1:
    print(n//2)
else:
    print(min(n - V[1][1] - W[0][1], n - V[0][1] - W[1][1]))

Solution (Python):
from collections import Counter
n = int(input())
list =input().split(" ")
odd_list = []
even_list = []
for i in range(n):

    if i % 2 == 0:
        even_list.append(list[i])
    else:
        odd_list.append(list[i])
Count_even_list = Counter(even_list)
Count_odd_list = Counter(odd_list)


if len(set(list)) == 1:
    print(int(len(list) / 2))
elif Count_even_list.most_common()[0][0] == Count_odd_list.most_common()[0][0]:
    print(min(len(even_list) - Count_even_list.most_common()[1][1] + len(odd_list) - Count_odd_list.most_common()[0][1],len(even_list) - Count_even_list.most_common()[0][1] + len(odd_list) - Count_odd_list.most_common()[1][1]))
else:
    print(len(even_list) - Count_even_list.most_common()[0][1] + len(odd_list) - Count_odd_list.most_common()[0][1])

Solution (Python):
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n = int(input())
    v = list(map(int, input().split()))
    import collections
    c1 = collections.Counter(v[::2]).most_common()
    c2 = collections.Counter(v[1::2]).most_common()
    c1.append(('a',0))
    c2.append(('b',0))
    if c1[0][0]==c2[0][0]:
        print(n-c1[0][1]-c2[0][1]+min([c1[0][1]-c1[1][1], c2[0][1]-c2[1][1]]))
    else:
        print(n-c1[0][1]-c2[0][1])

Solution (Python):
def getMode(target:list):
    cache = {}
    for x in target:
        if x in cache:
            cache[x] = cache[x] + 1
        else:
            cache[x] = 1
    return sorted(cache.items(), key=lambda x: x[1], reverse=True)


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

guu = []
ki = []
for i, n in enumerate(v):
    if i % 2 == 0:
        guu.append(n)
    else:
        ki.append(n)

gMode = getMode(guu)
g = gMode[0][0]
kMode = getMode(ki)
k = kMode[0][0]

if g == k:
    if len(gMode) == 1 and len(kMode) == 1:
        k = k + 1
    elif len(gMode) == 1 or len(kMode) == 1:
        if len(gMode) == 1:
            k = kMode[1][0]
        else:
            g = gMode[1][0]
    elif gMode[0][1] == kMode[0][1]:
        if gMode[1][1] < kMode[1][1]:
            k = kMode[1][0]
        else:
            g = gMode[1][0]
    elif gMode[0][1] < kmode[0][1]:
        g = gMode[1][0]
    else:
        k = kMode[1][0]    

result = 0
for n in guu:
    if n != g:
        result += 1

for n in ki:
    if n!= k:
        result += 1

print(result)

Solution (Python):
from collections import Counter
n = int(input())
A = [int(i) for i in input().split()]
A1 = Counter(A[::2]).most_common()
A2 = Counter(A[1::2]).most_common()

if A1[0][0] == A2[0][0]:
    if len(A1) == 1 and len(A2) == 1:
        ans = n // 2
    elif len(A1) == 1 and len(A2) != 1:
        ans = n // 2 - A2[1][1]
    elif len(A1) != 1 and len(A2) == 1:
        ans = n // 2 - A1[1][1]
    else:
        temp1 = n - A1[0][1] - A2[1][1]
        temp2 = n - A1[1][1] - A2[0][1]
        ans = min(temp1, temp2)
else:
    if len(A1) == 1 and len(A2) == 1:
        ans = 0
    elif len(A1) == 1 and len(A2) != 1:
        ans = n // 2 - A2[0][1]
    elif len(A1) != 1 and len(A2) == 1:
        ans = n // 2 - A1[0][1]
    else:
        ans = n - A1[0][1] - A2[0][1]
        
print(ans)

Solution (Python):
n =int(input())
l =[[0 for _ in range(10**5)]for _ in range(2)]
for i,j in enumerate(input().split()):
    l[i%2][int(j)-1] += 1
A = max(l[0])
B = max(l[1])
a = l[0].index(A)
b = l[1].index(B)
if l[0].count(A)>1 or l[1].count(B) >1 or a!=b:
    print(n-A-B)
else:
    l[0][a] =0
    l[1][b] =0
    C = max(l[0])
    D = max(l[1])
    print(min(n-A-D,n-B-C))

Solution (Python):
a=[0]*100001
b=[0]*100001

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

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

if a.index(max(a))==b.index(max(b)):
  a= sorted(a, reverse=True)
  b= sorted(b, reverse=True)
  print(min(n-a[1]-b[0],n-a[0]-b[1]))
else:
  print(n-max(a)-max(b))

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


def m():
    first = V[0::2]
    second = V[1::2]
    fdic = {}
    sdic = {}
    for i in range(N//2):
        if fdic.get(first[i], 0) == 0:
            fdic[first[i]] = 1
        else:
            fdic[first[i]] +=1

        if sdic.get(second[i], 0) == 0:
            sdic[second[i]] = 1
        else:
            sdic[second[i]] +=1
    flist = list(fdic.items())
    slist = list(sdic.items())

    flist.sort(reverse=True, key=lambda x:x[1])
    slist.sort(reverse=True, key=lambda x:x[1])

    if len(flist) == 1 and len(slist) == 1:
        if flist[0][0] == slist[0][0]:
            return N//2
        return 0
    if len(flist) == 1:
        return N//2 - slist[0][1]
    if len(slist) == 1:
        return N//2 - flist[0][1]

    if flist[0][0] != slist[0][0]:
        ans = 0
        for k, v in flist:
            if k != flist[0][0]:
                ans += v
        for k, v in slist:
            if k != slist[0][0]:
                ans += v
        return ans

    fans = 0
    sans = 0
    for k, v in flist:
        if k != flist[0][0]:
            fans += v
    for k, v in slist:
        if k != slist[1][0]:
            fans += v

    for k, v in flist:
        if k != flist[1][0]:
            sans += v
    for k, v in slist:
        if k != slist[0][0]:
            sans += v
    return min(fans,sans)

print(m())

Solution (Python):
import collections

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

oddSeq,evenSeq=[],[]
for i in range(N//2):
    oddSeq.append(V[i*2])
    evenSeq.append(V[i*2+1])

oddCounter = collections.Counter(oddSeq)
evenCounter = collections.Counter(evenSeq)

oddMostCommonNumber = oddCounter.most_common()[0][0]
evenMostCommonNumber = evenCounter.most_common()[0][0]

oddMostCommonTimes = oddCounter.most_common()[0][1]
evenMostCommonTimes = evenCounter.most_common()[0][1]

odd2ndCommonNumber = 0
even2ndCommonNumber = 0

odd2ndCommonTimes = 0
even2ndCommonTimes = 0

if len(oddCounter.most_common())!=1:
    odd2ndCommonNumber = oddCounter.most_common()[1][0]
    odd2ndCommonTimes = oddCounter.most_common()[1][1]
if len(evenCounter.most_common())!=1:
    even2ndCommonNumber = evenCounter.most_common()[1][0]
    even2ndCommonTimes = evenCounter.most_common()[1][1]

ans=-1
if evenMostCommonNumber!=oddMostCommonNumber:
    ans = N-oddMostCommonTimes-evenMostCommonTimes
else:
    ans1 = N-oddMostCommonTimes-even2ndCommonTimes
    ans2 = N-odd2ndCommonTimes-evenMostCommonTimes
    ans = min(ans1,ans2)
print(ans)

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

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

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

evec = Counter(eve)
oddc = Counter(odd)

evemosts = evec.most_common()
oddmosts = oddc.most_common()
evemostc = 0
oddmostc = 0

if evemosts[0][0] == oddmosts[0][0]:
    if len(evemosts) == 1:
        if len(oddmosts) == 1:
            evemostc = evemosts[0][1]
            oddmostc = 0
        else:
            evemostc = evemosts[0][1]
            oddmostc = oddmosts[1][0]
    elif len(oddmosts) == 1:
        if len(evemosts) == 1:
            evemostc = 0
            oddmostc = oddmosts[0][1]
        else:
            evemostc = evemosts[1][0]
            oddmostc = oddosts[0][1]
    elif evemosts[1][1] > oddmosts[1][1]:
        evemostc = evemosts[1][1]
        oddmostc = oddmosts[0][1]
    else:
        evemostc = evemosts[0][1]
        oddmostc = oddmosts[1][1]
else:
    evemostc = evemosts[0][1]
    oddmostc = oddmosts[0][1]

ans = n/2 - evemostc + n/2 - oddmostc
print(int(ans))

Solution (Python):
def main():
    n = int(input())
    v = list(map(int, input().split()))
    e = [0 for _ in range(1, 10 ** 5 + 2)]
    o = [0 for _ in range(1, 10 ** 5 + 2)]
    for i in range(0, n, 2):
        e[v[i]] += 1
        o[v[i + 1]] += 1
    ans = 0
    if len(set(v)) == 1:
        ans = n // 2
    else:
        me = max(e)
        mo = max(o)
        mei = e.index(me)
        moi = o.index(mo)
        if mei == moi:
            e[mei] = 0
            o[moi] = 0
            ans += n - me - max(max(e), max(o))
        else:
            ans = n - max(e) - max(o)
    print(ans)


main()

Solution (Python):
def count2(lst):
    ans = [["",0],0]
    def check():
        nonlocal ans
        if a > ans[0][1]:
            ans[1] = ans[0][1]
            ans[0][0] = last
            ans[0][1] = a
        elif a > ans[1]:
            ans[1] = a
    lst.sort()
    last =lst[0]
    a = 0
    for e in lst:
        if last == e:
            a +=1
        else:
            check()
            last = e
            a = 1
    check()
    return ans

def main(n:int,lst:list)->int:
    ans1 =count2(lst[::2])
    ans2 =count2(lst[1::2])
    if ans1[0][0] == ans2[0][0]:
        return n - max(ans1[0][1] + ans2[1],ans2[0][1] + ans1[1])
    else:
        return n - ans1[0][1] - ans2[0][1]
n = int(input())
lst = input().split()
print(main(n,lst))

Solution (Python):
from collections import Counter
def main(n:int,lst:list)->int:
    lst1 = lst[::2]
    lst2 = lst[1::2]
    c1 = Counter(lst1).most_common()
    c2 = Counter(lst2).most_common()
    if c1[0][0] == c2[0][0]:
        if len(c1)!=1 and len(c2)!=1:
            return n - max(c1[0][1] + c2[1][1],c2[0][1] + c1[1][1])
        else:
            return n//2
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = input().split()
print(main(n,lst))

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):
from collections import Counter
n=int(input())
v=[i for i in input().strip().split()]

v1,v2=[v[i] for i in range(n) if i%2==0],[v[i] for i in range(n) if not i%2==0]
v1c=Counter(v1).most_common()+[(0,0)]
v2c=Counter(v2).most_common()+[(0,0)]

if v1c[0][0]==v2c[0][0]:
    print(min(n-v1c[0][1]-v2c[1][1],n-v1c[1][1]-v2c[0][1]))

else:
    print(n-v1c[0][1]-v2c[0][1])

Solution (Python):
from collections import Counter
N = int(input())
V = list(map(int,input().split()))
c1 = Counter(V[::2])
c2 = Counter(V[1::2])
n1 = N//2 + N%2
n2 = N//2

if len(c1)==1 and len(c2)==1:
    if V[0]==V[1]:
        print(n2)
    else:
        print(0)
elif len(c1)==1:
    mc = c2.most_common()
    if mc[0][0] == V[0]:
        print(n2 - mc[1][1])
    else:
        print(n2 - mc[0][1])
elif len(c2)==1:
    mc = c1.most_common()
    if mc[0][0] == V[1]:
        print(n1 - mc[1][1])
    else:
        print(n1 - mc[0][1])
else:
    mc1 = c1.most_common()
    mc2 = c2.most_common()
    if mc1[0][0] != mc2[0][0]:
        print(N - mc1[0][1] - mc2[0][1])
    else:
        ans = N
        if mc1[0][0] != mc2[1][0]:
            ans = min(ans, N - mc1[0][1] - mc2[1][1])
        if mc1[1][0] != mc2[0][0]:
            ans = min(ans, N - mc1[1][1] - mc2[0][1])
        print(ans)

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

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

n1=[0 for i in range(10**5+1)]
n2=[0 for i in range(10**5+1)]

for a in v1:
    n1[a]+=1
for a in v2:
    n2[a]+=1
    
import numpy as np

i1=np.argsort(np.argsort(-np.array(n1)))
i2=np.argsort(np.argsort(-np.array(n2)))

zero1=list(i1).index(0)
zero2=list(i2).index(0)

if zero1!=zero2:
    print(n-n1[zero1]-n2[zero2])
else:
    one1=list(i1).index(1)
    one2=list(i2).index(1)
    if n1[zero1]-n1[one1]>n2[zero2]-n2[one2]:
        print(n-n1[zero1]-n2[one2])
    else:
        print(n-n1[one1]-n2[zero2])

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())
x = list(int(i) for i in input().split())
a = []
b = []
for i in range(0, n):
    if i % 2 == 0:
        a.append(x[i])
    else:
        b.append(x[i])
cnta = [0] * (100002 + 1)
cntb = [0] * (100002 + 1)
vala = 0
vala1 = 0
maxCnta = 0
maxCnta1 = 0
for i in a:
    cnta[i] += 1

for i in a:
    if maxCnta < cnta[i]:
        vala = i
        maxCnta = cnta[i]
for i in a:
    if maxCnta1 < cnta[i] and vala != i:
        maxCnta1 = cnta[i]
        vala1 = i

valb = 0
valb1 = 0
maxCntb = 0
maxCntb1 = 0
for i in b:
    cntb[i] += 1

for i in b:
    if maxCntb < cntb[i]:
        valb = i
        maxCntb = cntb[i]

for i in b:
    if maxCntb1 < cntb[i] and valb != i:
        maxCntb1 = cntb[i]
        valb1 = i

if valb != vala:
    res = 0
    for i in a:
        if i != vala:
            res += 1
    for i in b:
        if i != valb:
            res += 1
    print(res)
else:
    resa = 0
    resb = 0
    resa1 = 0
    resb1 = 0
    for i in a:
        if i != vala:
            resa += 1
        if i != vala1:
            resa1 += 1
    for i in b:
        if i != valb:
            resb += 1
        if i != valb1:
            resb1 += 1
    print(min(resa + resb1, resa1 + resb))