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 as coll

n = int(input())
v = list(map(int,input().split()))
even = []
odd = []

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

oddc = coll.Counter(odd).most_common()[:2]
evenc = coll.Counter(even).most_common()[:2]

if(len(oddc) == 1):
	oddc.append((0,0))
if(len(evenc) == 1):
	evenc.append((0,0))


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

Solution (Python):
from collections import Counter

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

o = v[::2]
e = v[1::2]
co = list(Counter(o).items()) + [(-1, 0)]
ce = list(Counter(e).items()) + [(-2, 0)]
co.sort(key=lambda x: x[1], reverse=True)
ce.sort(key=lambda x: x[1], reverse=True)

if co[0][0] == ce[0][0] :
    print(min(n - co[0][1] - ce[1][1], n - co[1][1] - ce[0][1]))
else :
    print(n - co[0][1] - ce[0][1])

Solution (Python):
import sys
from collections import Counter
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    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])))


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n = int(input())
V = [int(el) for el in input().split(' ')]
 
a = Counter(V[0::2]).most_common() + [(0,0)]
b = Counter(V[1::2]).most_common() + [(0,0)]



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

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

p=[0]+sorted(v[0:n-1:2])+[0]
l=r=o1=o2=0
for i in range(1,n//2+2):
  if p[i-1] != p[i]:
    if l>=o1:
      o2,o1,r=o1,l,p[i-1]
    elif l>o2:
      o2=l
    l=1
  else:
    l+=1

pr = r
po1 = o1
po2 = o2

p=[0]+sorted(v[1:n:2])+[0]
l=r=o1=o2=0
for i in range(1,n//2+2):
  if p[i-1] != p[i]:
    if l>=o1:
      o2,o1,r=o1,l,p[i-1]
    elif l>o2:
      o2=l
    l=1
  else:
    l+=1

if pr != r:
  print(n-po1-o1)
else:
  print(min(n-po1-o2,n-o1-po2))

Solution (Python):
import collections


n = int(input())
odd = []
even = []
for i,j in enumerate(map(int,input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(),key=lambda x:(x[1]),reverse=True)
even = sorted(collections.Counter(even).items(),key=lambda x:(x[1]),reverse=True)

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

if odd[0][0] == even[0][0]:
    if len(odd) >= 2 and len(even) >= 2:
        if odd[0][1] + even[1][1] > odd[1][1] + even[0][1]:
            print((n//2 - odd[0][1]) + (n//2 - even[1][1]))
        else:
            print((n//2 - odd[1][1]) + (n//2 - even[0][1]))
    else:
        if len(odd) == 1:
            print((n//2 - odd[0][1]) + (n//2 - even[1][1]))
        else:
            print((n//2 - odd[1][1]) + (n//2 - even[0][1]))
else:
    print((n//2 - odd[0][1]) + (n//2 - even[0][1]))

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

c0mc = Counter(V[::2]).most_common(2)
c1mc = Counter(V[1::2]).most_common(2)

if len(c0mc) == 1:
    c0mc.append((0, 0))
if len(c1mc) == 1:
    c1mc.append((0, 0))

print(N - max(a[1] + b[1] for (a, b) in product(c0mc, c1mc) if a[0] != b[0]))

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

dict_odd = dict()
dict_even = dict()

for i in range(N):
	if i % 2 == 1:
		if V[i] in dict_odd:
			dict_odd[V[i]] += 1
		else:
			dict_odd[V[i]] = 1
			
	else:
		if V[i] in dict_even:
			dict_even[V[i]] += 1
		else:
			dict_even[V[i]] = 1
			
odd_sorted = sorted(dict_odd.items(), key=lambda x:x[1], reverse = True)
even_sorted = sorted(dict_even.items(), key=lambda x:x[1], reverse = True)

if odd_sorted[0][0] != even_sorted[0][0]:
	print(N - odd_sorted[0][1] - even_sorted[0][1])
else:
	if len(odd_sorted) == 1 and len(even_sorted) == 1:
		print(int(N / 2))
	elif len(odd_sorted) == 1:
		print(N - odd_sorted[0][1] - even_sorted[1][1])
	elif len(even_sorted) == 1:
		print(N - even_sorted[0][1] - odd_sorted[1][1])
	else:
		print(N - max(odd_sorted[0][1] + even_sorted[1][1], odd_sorted[1][1] + even_sorted[0][1]))

Solution (Python):
import collections

n = int(input())
odd = []
even = []
for i, j in enumerate(map(int, input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(), reverse=True, key=lambda x: x[1])
even = sorted(collections.Counter(even).items(), reverse=True, key=lambda x: x[1])

if len(odd) == 1 and len(even) == 1 and odd[0][0] == even[0][0]:
    print(n // 2)
elif odd[0][0] == even[0][0]:
    if odd[0][1] == even[0][1]:
        for i in range(2):
            if odd[i][1] == even[i][1]:
                continue
            elif odd[i][1] > even[i][1]:
                print((n // 2 - odd[1][1]) + (n // 2 - even[0][1]))
                break
            elif odd[i][1] < even[i][1]:
                print((n // 2 - odd[0][1]) + (n // 2 - even[1][1]))
                break
        else:
            print((n // 2 - odd[0][1]) + (n // 2 - even[1][1]))
else:
    print((n // 2 - odd[0][1]) + (n // 2 - even[0][1]))

Solution (Python):
from collections import Counter

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

s1 = Counter(V).most_common(2)[0]
s2 = Counter(V).most_common(2)[0]
V1 = V[0::2]
V2 = V[1::2]
c1 = c2 = c3 = c4 = 0
Z1 = Counter(V1)
Z2 = Counter(V2)
x1, c1 = Z1.most_common(1)[0]
x2, c2 = Z2.most_common(1)[0]
if len(Z1) > 1:
    x3, c3 = Counter(V1).most_common(2)[1]
if len(Z2) > 1:
    x4, c4 = Counter(V2).most_common(2)[1]
if x1 == x2:
    a = max(c1+c4, c2+c3)
    print(N-a)
else:
    print(N - c1 - c2)

Solution (Python):
from collections import Counter

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

s1 = Counter(V).most_common(2)[0]
s2 = Counter(V).most_common(2)[0]
V1 = V[0::2]
V2 = V[1::2]
x1, c1 = Counter(V1).most_common(1)[0]
x2, c2 = Counter(V2).most_common(1)[0]
if x1 == x2:
    if c1 > c2:
        x2, c2 = Counter(V2).most_common(2)[1]
    elif c1 < c2:
        x1, c1 = Counter(V1).most_common(2)[1]
    elif c1 == c2 == N // 2:
        c1, c2 = N//2, 0
    else:

        x2, c2 = Counter(V2).most_common(2)[1]
        x3, c3 = Counter(V1).most_common(2)[1]
        c2 = max(c2, c3)

print(N - c1 - c2)

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

dE={};dO={}
for i in range(n):
    dX=dE if i%2==0 else dO
    if v[i] in dX:
        dX[v[i]]+=1
    else:
        dX[v[i]]=1

lE=sorted(list(dE.items()),key=lambda x:x[1],reverse=True)
lO=sorted(list(dO.items()),key=lambda x:x[1],reverse=True)

me=lE[0][1];mo=lO[0][1]
ae=lE[0][0];ao=lO[0][0]

se=0 if len(lE)==1 else lE[1][1]
so=0 if len(lO)==1 else lO[1][1]

if ae==ao:
    ans=n-max(me+so,mo+se)
else:
    ans=n-(me+mo)

print(ans)

Solution (Python):
N=int(input())
V=list(map(int,input().split()))
A=[0]*(10**5+1)
B=[0]*(10**5+1)
for i in range(N):
  if(i%2==0):
    A[V[i]]+=1
  else:
    B[V[i]]+=1
MA=0
NA=A[0]
MB=0
NB=B[0]
for i in range(10**5+1):
  if(A[i]>=NA):
    NA=A[i]
    MA=i
  if(B[i]>=NB):
    NB=B[i]
    MB=i
A.sort(reverse=True)
B.sort(reverse=True)
if(MA!=MB):
  print(N-NA-NB)
else:
  print(min(N-A[0]-B[1],N-A[1]-B[0]))

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
odds=[[0,i]  for i in range(10**5+1)]
even=[[0,i]  for i in range(10**5+1)]
for i in range(n):
    if i%2==0:
        even[v[i]][0]+=1
    else:
        odds[v[i]][0]+=1
even.sort(reverse=True)
odds.sort(reverse=True)
if even[0][1]==odds[0][1]:
    m=max(even[0][0]+odds[1][0],even[1][0]+odds[0][0])
    print(n-m)
else:
    print(n-even[0][0]-odds[0][0])

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

even_sorted = sorted(even.items(), key=lambda x:x[1], reverse=True)
odd_sorted = sorted(odd.items(), key=lambda x:x[1], reverse=True)

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

Solution (Python):
import collections

n = int(input())
v = list(map(int, input().split()))
even = []
odd = []
for i in range(0, n, 2):
    odd.append(v[i])
for i in range(1, n, 2):
    even.append(v[i])
odd_counter = collections.Counter(odd)
even_counter = collections.Counter(even)

odd_counter_sorted = sorted(odd_counter.items(),
                            key=lambda x: x[1],
                            reverse=True)
even_counter_sorted = sorted(even_counter.items(),
                             key=lambda x: x[1],
                             reverse=True)
if odd_counter_sorted[0][0] != even_counter_sorted[0][0]:
    print(
        len(odd) - odd_counter_sorted[0][1] + len(even) -
        even_counter_sorted[0][1])
else:
    ans = float("inf")
    if len(odd_counter_sorted) > 1:
        a = len(odd) - odd_counter_sorted[1][1] + len(
            even) - even_counter_sorted[0][1]
    else:
        a = len(odd) + len(even) - even_counter_sorted[0][1]

    if len(even_counter_sorted) > 1:
        b = len(odd) - odd_counter_sorted[0][1] + len(
            even) - even_counter_sorted[1][1]
    else:
        b = len(odd) - odd_counter_sorted[0][1] + len(even)
    print(min(a, b))

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
e=Counter(v[0::2]).most_common(2)
o=Counter(v[1::2]).most_common(2)
if len(set(v))==1:
    print(n//2)
else:
    if e[0][0]==o[0][0]:
        print(n-max(e[1][1],o[1][1])-e[0][1])
    else:
        print(n-e[0][1]-o[0][1])

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
v1 = Counter(v[::2]).most_common(2)
v2 = Counter(v[1::2]).most_common(2)
v1.append((0, 0))
v2.append((0, 0))
if v1[0][0] != v2[0][0]:
    print(n - v1[0][1] - v2[0][1])
else:
    print(min(n - v1[0][1] - v2[1][1], n - v1[1][1] - v2[0][1]))

Solution (Python):
import collections
import sys

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

even = v[0:n-1:2]
odd = v[1:n:2]

c_even = collections.Counter(even).most_common()
c_odd = collections.Counter(odd).most_common()

if c_odd[0][0] == c_even[0][0]:
  if len(c_even) == 1 and len(c_odd) == 1:
    print(int(n/2))
    sys.exit()
  elif len(c_even) == 1:
    print(int(n/2) - c_odd[1][1])
    sys.exit()

  elif len(c_odd) == 1:
    print(int(n/2) - c_even[1][1])
    sys.exit()
  
  if c_even[1][1] > c_odd[1][1]:
     answer = (len(even)-c_even[1][1])+(len(odd)-c_odd[0][1])
  else:
     answer = (len(even)-c_even[0][1])+(len(odd)-c_odd[1][1])
else:
  answer = (len(even)-c_even[0][1])+(len(odd)-c_odd[0][1])
print(answer)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
o=[]
e=[]
for i in range(n):
  if i%2==0:
    o.append(a[i])
  else:
    e.append(a[i])
from collections import Counter as co
o=co(o)
e=co(e)
o['x']=0
e['x']=0
ov=o.values()
ev=e.values()
mo=max(ov)
me=max(ev)
if n==2:
  if a[0]==a[1]:
    print(1)
  else:
    print(0)
else:
  if max(o,key=o.get)==max(e,key=e.get):
    if mo>me:
      me=sorted(ev)[-2]
    elif mo<me:
      mo=sorted(ov)[-2]
    else:
      mo=max(sorted(ev)[-2],sorted(ov)[-2])
  print(n-mo-me)

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
def doit(vs):
    ret = {}
    for v in vs:
        ret[v] = ret.get(v, 0) + 1
    return sorted((-ret[v], v) for v in ret) + [(0, None)]
odd = doit(v[0::2])
even = doit(v[1::2])
if odd[0][1] != even[0][1]:
    print(n + odd[0][0] + even[0][0])
else:
    print(n + min(odd[1][0] + even[0][0], odd[0][0] + even[1][0]))

Solution (Python):

import collections
import copy

n = int(input()) 
v_list = [int(e) for e in input().split()]










v_list_odd = [v_list[i] for i in range(n) if i%2==1]
v_list_even = [v_list[i] for i in range(n) if i%2==0]




c = collections.Counter(v_list_odd)
v_list_odd_counter = copy.copy(c)
if len(c)>1:
    fix_picklist_for_v_list_odd = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1],((c.most_common(2))[1])[0],((c.most_common(2))[1])[1]]
else:
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1]]
    
c = collections.Counter(v_list_even)
v_list_even_counter = copy.copy(c)
if len(c)>1:
    fix_picklist_for_v_list_even = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1],((c.most_common(2))[1])[0],((c.most_common(2))[1])[1]]
else:
    fix_picklist_for_v_list_even = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1]]
    


if fix_picklist_for_v_list_even[0] != fix_picklist_for_v_list_odd[0]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]



elif len(fix_picklist_for_v_list_even) == 2 and len(fix_picklist_for_v_list_odd) == 2:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = "!"

elif len(fix_picklist_for_v_list_even) == 2 and len(fix_picklist_for_v_list_odd) != 2:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[2]
elif len(fix_picklist_for_v_list_even) != 2 and len(fix_picklist_for_v_list_odd) == 2:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[2]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]

elif fix_picklist_for_v_list_even[1] + fix_picklist_for_v_list_odd[3] > fix_picklist_for_v_list_even[3]+fix_picklist_for_v_list_odd[1]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[2]
elif fix_picklist_for_v_list_even[1] + fix_picklist_for_v_list_odd[3] <= fix_picklist_for_v_list_even[3] + fix_picklist_for_v_list_odd[1]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[2]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]



        

ans_odd = n/2 - v_list_odd_counter[fix_char_for_v_list_odd]
ans_even = n/2 - v_list_even_counter[fix_char_for_v_list_even]
print(int(ans_odd + ans_even))

Solution (Python):
from collections import Counter

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

a = sorted(Counter(v[ ::2]).items(), key=lambda x: -x[1])
b = sorted(Counter(v[1::2]).items(), key=lambda x: -x[1])
def w(arr, index):
  arr = arr[index:] + arr[0:index]
  return sum(c for _, c in arr[1:])

if a[0][0] == b[0][0]:
  if len(a) == len(b) == 1:
    print(n // 2)
  else:
    print(min(w(a, 0) + w(b, 1), w(a, 1) + w(b, 0)))
else:
  print(w(a, 0) + w(b, 0))

Solution (Python):
n = int(input()) // 2
ns = list(map(int, input().split()))

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



da = {}
db = {}
for s in a:
    da[s] = da.get(s, 0) + 1
for s in b:
    db[s] = db.get(s, 0) + 1
ca = sorted([(v, k) for k, v in da.items()])[::-1]
cb = sorted([(v, k) for k, v in db.items()])[::-1]

if ca[0][1] != cb[0][1]:
    print(n-ca[0][0] + n-cb[0][0])
else:
    if len(ca) == 1 and len(cb) == 1:
        print(n)
    elif len(ca) == 1 and len(cb) > 1:
        print(n-ca[0][0] + n-cb[1][0])
    elif len(ca) > 1 and len(cb) == 1:
        print(n-ca[1][0] + n-cb[0][0])
    else:
        print(min(n-ca[1][0] + n-cb[0][0], n-ca[0][0] + n-cb[1][0]))

Solution (Python):
import itertools

n = int(input())
vs = [int(s) for s in input().split(' ')]
vs_odd = vs[0::2]
vs_odd.sort()
vs_even = vs[1::2]
vs_even.sort()
odd_group = {0: 0}
even_group = {0: 0}

for k, g in itertools.groupby(vs_odd):
    odd_group[k] = len(list(g))
for k, g in itertools.groupby(vs_even):
    even_group[k] = len(list(g))

ret = len(vs)

odd_max = max(odd_group, key=odd_group.get)
odd_max_v = odd_group[odd_max]
even_max = max(even_group, key=even_group.get)
even_max_v = even_group[even_max]
if odd_max == even_max:
    del odd_group[even_max]
    del even_group[even_max]
    odd_max2 = max(odd_group, key=odd_group.get)
    odd_max2_v = odd_group[odd_max2]
    even_max2 = max(even_group, key=even_group.get)
    even_max2_v = even_group[even_max2]
    ret -= max(odd_max_v + even_max2_v, odd_max2_v + even_max_v)
else:
    ret -= (odd_max_v + even_max_v )
print(ret)

Solution (Python):
from collections import Counter
def c_nb(i):
  b = Counter(v[i::2]).most_common()+[(0,0)]
  return b
def c_rpl(a,x,y):
  r = a-o[x][1]-e[y][1]
  return r
n = int(input())
v = list(map(int,input().split()))
o = c_nb(0)
e = c_nb(1)
if o[0][0]!=e[0][0]:
  ans = c_rpl(n,0,0)
else:
  ans = min(c_rpl(n,0,1),c_rpl(n,1,0))
print(ans)

Solution (Python):
import collections

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


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

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

c_even = collections.Counter(v_even)
n_v_even_majority = c_even.most_common()[0][1]
c_odd = collections.Counter(v_odd)
n_v_odd_majority = c_odd.most_common()[0][1]


if c_even.most_common()[0][0] == c_odd.most_common()[0][0]:
    if len(set(v_even)) == 1 & len(set(v_odd)) == 1:
        print(0)
    elif len(set(v_even)) > 1:
        tmp = n - c_even.most_common()[1][1] - n_v_odd_majority
        if len(set(v_odd)) > 1:
            tmp = min(tmp, n - n_v_even_majority - c_odd.most_common()[1][1])
        print(tmp)
else:
    print(n - n_v_even_majority - n_v_odd_majority)

Solution (Python):
def count_rewrite(v):
    ct = {}
    for x in v:
        if x in ct:
            ct[x] += 1
        else:
            ct[x] = 1
    total = 0
    for x in ct:
        total += ct[x]
    best = 0
    for x in ct:
        if ct[x] > best:
            best = ct[x]
            maxv = x
    del ct[maxv]
    second = 0
    for x in ct:
        if ct[x] > second:
            second = ct[x]
    return maxv, total - best, total - second


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

r1 = count_rewrite(v[::2])
r2 = count_rewrite(v[1::2])
if r1[0] != r2[0]:
    print(r1[1] + r2[1])
else:
    if r1[2] >= r2[2]:
        print(r1[1] + r2[2])
    else:
        print(r1[2] + r2[1])

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
v_1 = v[::2]
v_2 = v[1::2]
v_1_d = {}
v_2_d = {}
for i in v_1:
  if i in v_1_d:
    v_1_d[i] += 1
  else:
    v_1_d[i] = 1
    
for i in v_2:
  if i in v_2_d:
    v_2_d[i] += 1
  else:
    v_2_d[i] = 1
    
v_1_d = sorted(v_1_d.items(),key = lambda x: -x[1])
v_2_d = sorted(v_2_d.items(),key = lambda x: -x[1])


for i in v_2_d:
  if i[0] != v_1_d[0][0]:
    max_v_2 = v_1_d[0][1]+i[1]
    break
else:
  max_v_2 = v_1_d[0][1]
    
for i in v_1_d:
  if i[0] != v_2_d[0][0]:
    max_v_1 = v_2_d[0][1]+i[1]
    break
else:
  max_v_1 = v_2_d[0][1]
print(n-max(max_v_1,max_v_2))

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

even = {}
odd = {}


for i in range(N):
    if(i%2==0):
        if odd.get(V[i],None)==None:
            odd[V[i]]=1
        else:
            odd[V[i]]+=1
    else:
        if even.get(V[i],None)==None:
            even[V[i]]=1
        else:
            even[V[i]]+=1


max_odd_k = max(odd, key=odd.get)
max_even_k = max(even, key=even.get)
max_odd_v = max(odd.values())
max_even_v = max(even.values())
len_odd = len(odd)
len_even = len(even)

if(max_odd_k!=max_even_k):
    print(N-max_odd_v-max_even_v)
    exit()

if((len_odd==1)&(len_even==1)):
    print(N//2)
    exit()


if(len_odd==1):
    del even[max_even_k]
    max2_even_v = max(even.values())
    print(N-max_odd_v-max2_even_v)
    exit()

if(len_even==1):
    del odd[max_odd_k]
    max2_odd_v = max(odd.values())
    print(N-max2_odd_v-max_even_v)
    exit()

del even[max_even_k]
max2_even_v = max(even.values())
del odd[max_odd_k]
max2_odd_v = max(odd.values())

print(min((N-max2_odd_v-max_even_v),(N-max_odd_v-max2_even_v)))

Solution (Python):
import collections
n = int(input())
v = list(map(int,input().split()))
odd = collections.Counter(v[0::2]).most_common()
even = collections.Counter(v[1::2]).most_common()
odd.append((0, 0))
even.append((0, 0))
if odd[0][0] != even[0][0]:
    print(n - odd[0][1] - even[0][1])
else:
    print(n - max(odd[0][1] + even[1][1], odd[1][1] + even[0][1]))

Solution (Python):
from collections import Counter
import heapq

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

if len(set(Vs)) == 1:
  print(N//2)
  exit()

Veve, Vodd = [],[]
idx = 0
for v in Vs:
  if idx%2 == 0: Veve.append(v)
  else: Vodd.append(v)
  idx += 1

Veve_cnt, Vodd_cnt = [], []
[heapq.heappush(Veve_cnt, [-num,val]) for val, num in Counter(Veve).items()]
[heapq.heappush(Vodd_cnt, [-num,val]) for val, num in Counter(Vodd).items()]

neg_num, val = heapq.heappop(Veve_cnt)
eve_val = val
eve_num = -neg_num

neg_num, val = heapq.heappop(Vodd_cnt)
odd_val = val
odd_num = -neg_num

if eve_val != odd_val:
  print(N-eve_num-odd_num)
else:
  if len(Vodd_cnt) != 0:odd_num2 = -heapq.heappop(Vodd_cnt)[0]
  else:odd_num2 = -float('inf')

  if len(Veve_cnt) != 0:eve_num2 = -heapq.heappop(Veve_cnt)[0]
  else:eve_num2 = -float('inf')

  print(min(N-eve_num2-odd_num,N-eve_num-odd_num2))

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

Solution (Python):
import collections
N = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
  print(int(len(v)/2))
  exit()
cov = collections.Counter(v[1::2])
cev = collections.Counter(v[::2])
mov = cov.most_common()[0][0]
mev = cev.most_common()[0][0]
ans = len(v) - cov[mov] - cev[mev]

if mov == mev:
  ans1 = len(v) - cov.most_common()[1][1] - cev.most_common()[0][1]
  ans2 = len(v) - cov.most_common()[0][1] - cev.most_common()[1][1]
  ans = min(ans1, ans2)

print(ans)

Solution (Python):
import collections
N = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
  print(int(len(v)/2))
  exit()
ov = [v[i] for i in range(1,len(v),2)]
ev = [v[i] for i in range(0, len(v), 2)]

cov = collections.Counter(ov)
cev = collections.Counter(ev)
mov = cov.most_common()[0][0]
mev = cev.most_common()[0][0]
ans = len(v) - cov[mov] - cev[mev]

if mov == mev:
  ans1 = len(v) - cov.most_common()[1][1] - cev.most_common()[0][1]
  ans2 = len(v) - cov.most_common()[0][1] - cev.most_common()[1][1]
  ans = min(ans1, ans2)

print(ans)

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
v1 = Counter(v[::2]).most_common()
v2 = Counter(v[1::2]).most_common()
v1.append((0, 0))
v2.append((0, 0))
if v1[0][0] != v2[0][0]:
    print(n - v1[0][1] - v2[0][1])
else:
    print(min(n - v1[0][1] - v2[1][1], n - v1[1][1] - v2[0][1]))

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
v1 = sorted(Counter(v[::2]).items(), key=lambda x: x[1], reverse=True)
v2 = sorted(Counter(v[1::2]).items(), key=lambda x: x[1], reverse=True)
v1.append((0, 0))
v2.append((0, 0))
if v1[0][0] != v2[0][0]:
    print(n - v1[0][1] - v2[0][1])
else:
    print(min(n - v1[0][1] - v2[1][1], n - v1[1][1] - v2[0][1]))

Solution (Python):
n = int(input())
v_list = list(map(int, input().split()))
count1 = [[0, i] for i in range(10**5)]
count2 = [[0, i] for i in range(10**5)]  

for i in range(0, n, 2):
    count1[v_list[i]-1][0] += 1
    count2[v_list[i+1]-1][0] += 1

count1 = sorted(count1)[::-1]
count2 = sorted(count2)[::-1]
if count1[0][1] == count2[0][1]:
    if count1[0][0] > count2[0][0]:
        ans = n - count1[0][0] - count2[1][0]
    elif count1[0][0] < count2[0][0]:
        ans = n - count2[0][0] - count1[1][0]
    else:
        ans = min(n - count2[0][0] - count1[1][0], n - count1[0][0] - count2[1][0])
else:
    ans = n - count1[0][0] - count2[0][0]
print(ans)

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

Solution (Python):
import collections

n = int(input())
a = list(map(int,input().split()))
b,c = [],[]
nh = n // 2 
for i in range(nh):
    b.append(a[i*2])
    c.append(a[i*2+1])

cb = collections.Counter(b)
cc =collections.Counter(c)

cb2 = cb.most_common(2)
cc2 = cc.most_common(2)


if cb2[0] == cc2[0]:
    if len(cb2) == 1 and len(cc2) == 1:
        print(nh)
    elif len(cb2) == 1:
        print(nh - cc2[1][1])
    elif len(cc2) == 1:
        print(nh - cb2[1][1])
    elif cb2[1][1] >= cc2[1][1]:
        print(n - cb2[1][1] - cc2[0][1])
    else:
        print(n - cb2[0][1] - cc2[1][1])
else:
    print(n-cb2[0][1]-cc2[0][1])

Solution (Python):
N = int(input())
V = list(map(int,input().split()))
V1 = V[::2]
V2 = V[1::2]
V1_s = list(set(V1))
V2_s = list(set(V2))
S1 = len(V1_s)
S2 = len(V2_s)
if S1 == 1 and S2 == 1:
  if V1[0] != V2[0]:
    print(0)
  else:
    print(len(V) // 2)
else:
  V1_l = [0] * ((10 ** 5) + 1)
  V2_l = [0] * ((10 ** 5) + 1)
  for i in range(N // 2):
    V1_l[V1[i]] += 1
  for i in range(N // 2):
    V2_l[V2[i]] += 1
  S1_MAX = [V1_l.index(max(V1_l)),max(V1_l)]
  S2_MAX = [V2_l.index(max(V2_l)),max(V2_l)]
  if S1_MAX[0] != S2_MAX[0]:
    print(N - S1_MAX[1] - S2_MAX[1])
  else:
    V2_l.pop(S2_MAX[0])
    S2_MAX_s = [V2_l.index(max(V2_l)),max(V2_l)]
    ans1 = N - S1_MAX[1] - S2_MAX_s[1]
    V1_l.pop(S1_MAX[0])
    S1_MAX = [V1_l.index(max(V1_l)),max(V1_l)]
    ans2 = N - S1_MAX[1] - S2_MAX[1]
    print(min(ans1,ans2))

Solution (Python):
n = int(input())
low = [[0,i] for i in range(10**5+1)]
high = [[0,i] for i in range(10**5+1)]

v = list(map(int,input().split()))
for i,a in enumerate(v):
    if i%2==0:
        low[a][0] +=1
    else:
        high[a][0] +=1

low.sort(reverse=True)
high.sort(reverse=True)



if low[0][1] !=high[0][1]:
    ans = n-(low[0][0] +high[0][0])
else:
    ans = n - (low[0][0] + max(low[1][0],high[1][0]))
print(ans)

Solution (Python):
import collections

n=int(input())
V=list(map(int,input().split()))
V1=collections.Counter(V[0::2])
V2=collections.Counter(V[1::2])
V1v,V1c = zip(*V1.most_common())
V2v,V2c = zip(*V2.most_common())
V1v=list(V1v)
V1c=list(V1c)
V2v=list(V2v)
V2c=list(V2c)
V1v.append(-1)
V2v.append(-2)
V1c.append(0)
V2c.append(0)

if V1v[0] != V2v[0]:
    print(n-V1c[0]-V2c[0])
else:
    if V1c[1] >= V2c[1]:
        print(n-V1c[1]-V2c[0])
    else:
        print(n-V1c[0]-V2c[1])

Solution (Python):
from collections import Counter


def f(d, val):
    res = 0
    for elem, amount in d.items():
        if elem == val:
            continue
        res += amount
    return res


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

e = Counter(V[0::2])
o = Counter(V[1::2])

e1 = e.most_common()[0]
o1 = o.most_common()[0]

ans = 0
if e1 != o1:
    ans += f(e, e1[0])
    ans += f(o, o1[0])
else:
    if e1[1] > o1[1]:
        if len(o) < 2:
            ans += o1[1]
        else:
            ans += f(o, o.most_common()[1][0])
        ans += f(e, e1[0])
    elif e1[1] < o1[1]:
        if len(e) < 2:
            ans += e1[1]
        else:
            ans += f(e, e.most_common()[1][0])
        ans += f(o, o1[0])
    else:
        if len(o) == len(e) == 1:
            ans += e1[1]
        elif len(o) == 1:
            ans += f(e, e.most_common()[1][0])
        elif len(e) == 1:
            ans += f(o, o.most_common()[1][0])
        else:
            e2 = e.most_common()[1]
            o2 = o.most_common()[1]

            if e2[1] > o2[1]:
                ans += f(e, e2[0])
                ans += f(o, o1[0])
            else:
                ans += f(e, e1[0])
                ans += f(o, o2[0])
print(ans)

Solution (Python):
n, *v = map(int, open(0).read().split())
o, e = v[::2], v[1::2]
o.sort();e.sort()

on = []
prev = 0
cnt = 0
for i in o:
  if i==prev: cnt += 1
  else: on.append([prev,cnt]);cnt=1
  prev = i
on.append([prev,cnt])
on.sort(key=lambda x:x[1])


en = []
prev = 0
cnt = 0
for i in e:
  if i==prev: cnt += 1
  else: en.append([prev,cnt]);cnt=1
  prev = i
en.append([prev,cnt])
en.sort(key=lambda x:x[1])

if on[-1][0]==en[-1][0]:
  o=list(zip(*on))[1]
  e=list(zip(*en))[1]
  ans = sum(o)+sum(e)
  print(ans-max(o[-2]+e[-1],o[-1]+e[-2]))
else:
  o=list(zip(*on))[1]
  e=list(zip(*en))[1]
  print(sum(o)+sum(e)-o[-1]-e[-1])

Solution (Python):
n, *v = map(int, open(0).read().split())
o, e = v[::2], v[1::2]
o.sort();e.sort()

on = []
prev = 0
cnt = 0
for i in o:
  if i==prev: cnt += 1
  else: on.append([prev,cnt]);cnt=1
  prev = i
on.append([prev,cnt])
on.sort(key=lambda x:x[1])


en = []
prev = 0
cnt = 0
for i in e:
  if i==prev: cnt += 1
  else: en.append([prev,cnt]);cnt=1
  prev = i
en.append([prev,cnt])
en.sort(key=lambda x:x[1])

if on[-1][0]==en[-1][0]:
  o=list(zip(*on))[1]
  e=list(zip(*en))[1]
  ans = sum(o)+sum(e)
  print(ans-max(o[-2]+e[-1],o[-1]+e[-2]))
else:
  o=list(zip(*on))[1]
  e=list(zip(*en))[1]
  print(sum(o)+sum(e)-o[-1]-e[-1])

Solution (Python):
from collections import Counter

N = int(input())
V = list(map(int, input().split()))
S1 = Counter([V[i] for i in range(0, N, 2)])
S2 = Counter([V[i] for i in range(1, N, 2)])

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

if S1[0][0] == S2[0][0]:
    ans = min(N-(S1[0][1]+S2[1][1]), N-(S1[1][1]+S2[0][1]))
else:
    ans = N - (S1[0][1] + S2[0][1])
print(ans)

Solution (Python):
import collections
N = int(input())
a = list(map(int, input().split()))
a_tmp = set(a)
if len(a_tmp) == 1:
    print(N//2)
    exit()
kisu = []
guu = []
for i in range(N):
    if i %2 ==0:
        guu.append(a[i])
    else:
        kisu.append(a[i])
kisu_c = collections.Counter(kisu)
guu_c = collections.Counter(guu)

kisu_max = kisu_c.most_common()[0][0]
guu_max = guu_c.most_common()[0][0]

if kisu_max == guu_max:
    tmp = len(a)-kisu.count(kisu_c.most_common()[0][0])-guu.count(guu_c.most_common()[1][0])
    tmp2 = len(a)-kisu.count(kisu_c.most_common()[1][0])-guu.count(guu_c.most_common()[0][0])
    if tmp < tmp2:
        print(tmp)
    else:
        print(tmp2)
    exit()

print(len(a)-kisu.count(kisu_max)-guu.count(guu_max))