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):
n = int(input())
V = list(map(int, input().split()))

from collections import Counter

v = Counter(V).most_common()

if len(v)==1:
    print(n//2)
    
else:
    even = [V[2*i] for i in range(n//2)]
    odd = [V[2*j+1] for j in range(n//2)]
    
    e = Counter(even).most_common()
    o = Counter(odd).most_common()
    
    if e[0][0]!=o[0][0]:
        print(n-e[0][1]-o[0][1])
    else:
        sec = v[1][0]
        esec = even.count(sec)
        osec = odd.count(sec)
        print(n-max(esec+o[0][1], osec+e[0][1]))

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

from collections import Counter

v = Counter(V).most_common()

if len(v)==1:
    print(n//2)
    
else:
    even = [V[2*i] for i in range(n//2)]
    odd = [V[2*j+1] for j in range(n//2)]
    
    e = Counter(even).most_common()
    o = Counter(odd).most_common()
    
    if e[0][0]!=o[0][0]:
        print(n-e[0][1]-o[0][1])
    else:
        sec = v[1][0]
        esec = even.count(sec)
        osec = odd.count(sec)
        if esec>osec:
            print(n-esec-o[0][1])
        else:
            print(n-osec-e[0][1])

Solution (Python):
def count_nums(v):
    counter = {}
    for x in v:
        if x not in counter:
            counter[x] = 0
        counter[x] += 1
    retval = list(counter.items())
    retval.sort(lambda a: -a[1])
    
    
    
    
    return retval


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

    cv1 = count_nums(v1)
    cv2 = count_nums(v2)

    if cv1[0][0] != cv2[0][0]:
        print(n - (cv1[0][1] + cv2[0][1]))
    elif len(cv1) == 1 and len(cv2) == 1:
        print(len(v2))
    elif len(cv1) == 1:
        print(len(v2) - cv2[1][1])
    elif len(cv2) == 1:
        print(len(v1) - cv1[1][1])
    else:
        print(n - max(cv1[0][1]+cv2[1][1], cv1[1][1]+cv2[0][1]))


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter


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


lst_o = lst_v[::2]
lst_e = lst_v[1::2]
cnt_o = Counter(lst_o).most_common() + [(0, 0)]
cnt_e = Counter(lst_e).most_common() + [(0, 0)]


if cnt_o[0][0] == cnt_e[0][0]:
    rem_number = max(cnt_o[0][1] + cnt_e[1][1], cnt_o[1][1] + cnt_e[0][1])
else:
    rem_number = cnt_o[0][1] + cnt_e[0][1]
ans = n - rem_number


print(ans)

Solution (Python):









def separate(values,a,b):
    for v in values:
        a.append(v)
        a,b = b,a









def getCount(values):
    currentNum=0
    currentCount=0
    ret={'First' :{'Num':[],'Cnt':0},
         'Second':{'Num':[],'Cnt':0}}
    for v in values:
        if v==currentNum:
            currentCount+=1
        else:
            
            if ret['First']['Cnt'] < currentCount:
                
                ret['Second']=ret['First'].copy()
                ret['First']={'Num':[currentNum],'Cnt':currentCount}
            elif ret['First']['Cnt'] == currentCount:
                
                ret['First']['Num'].append(currentNum)
            elif ret['Second']['Cnt'] < currentCount:
                
                ret['Second']={'Num':[currentNum],'Cnt':currentCount}
            elif ret['Second']['Cnt'] == currentCount:
                
                ret['Second']['Num'].append(currentNum)

            currentNum=v
            currentCount=1

    
    if ret['First']['Cnt'] < currentCount:
        ret['Second']=ret['First'].copy()
        ret['First']={'Num':[currentNum],'Cnt':currentCount}
    elif ret['First']['Cnt'] == currentCount:
        ret['First']['Num'].append(currentNum)
    elif ret['Second']['Cnt'] < currentCount:
        ret['Second']={'Num':[currentNum],'Cnt':currentCount}
    elif ret['Second']['Cnt'] == currentCount:
        ret['Second']['Num'].append(currentNum)

    return ret





n = input()
vars = input ()
a=[]
b=[]
varArray=vars.split(" ")
separate(varArray,a,b)
a.sort()
b.sort()
a_result=getCount(a)
b_result=getCount(b)
if (len(a_result['First']['Num'])>1 or
    len(b_result['First']['Num'])>1):
    
    xa=len(a)-a_result['First']['Cnt']
    xb=len(b)-b_result['First']['Cnt']
    x=xa+xb
else:
    
    if a_result['First']['Num'][0]!=b_result['First']['Num'][0]:
        
        xa=len(a)-a_result['First']['Cnt']
        xb=len(b)-b_result['First']['Cnt']
        x=xa+xb
    else:
        
        xaa=len(a)-a_result['First']['Cnt']
        xab=len(b)-b_result['Second']['Cnt']
        xa=xaa+xab
        xba=len(a)-a_result['Second']['Cnt']
        xbb=len(b)-b_result['First']['Cnt']
        xb=xba+xbb
        x=xa if xa<xb else xb

print(x)

Solution (Python):
from collections import Counter


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


lst_o = lst_v[::2]
lst_e = lst_v[1::2]
cnt_o = Counter(lst_o).most_common() + [(0, 0)]
cnt_e = Counter(lst_e).most_common() + [(0, 0)]


if cnt_o[0][0] == cnt_e[0][0]:
    rem_number = max(cnt_o[0][1] + cnt_e[1][1], cnt_o[1][1] + cnt_e[0][1])
else:
    rem_number = cnt_o[0][1] + cnt_e[0][1]
ans = n - rem_number


print(ans)

Solution (Python):
from collections import Counter


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



if len(set(lst_v)) == 1:
    ans = n // 2
else:
    lst_o = lst_v[::2]
    lst_e = lst_v[1::2]
    cnt_o = Counter(lst_o).most_common()
    cnt_e = Counter(lst_e).most_common()

    if cnt_o[0][0] == cnt_e[0][0]:
        rem_number = max(cnt_o[0][1] + cnt_e[1][1], cnt_o[1][1] + cnt_e[0][1])
    else:
        rem_number = cnt_o[0][1] + cnt_e[0][1]
    ans = n - rem_number


print(ans)

Solution (Python):
from collections import Counter


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



if len(set(lst_v)) == 1:
    ans = n // 2
else:
    lst_o = lst_v[::2]
    lst_e = lst_v[1::2]
    cnt_o = sorted(Counter(lst_o).items(), key=lambda x: -x[1])
    cnt_e = sorted(Counter(lst_e).items(), key=lambda x :-x[1])


    if cnt_o[0][0] == cnt_e[0][0]:
        rem_number = max(cnt_o[0][1] + cnt_e[1][1], cnt_o[1][1] + cnt_e[0][1])
    else:
        rem_number = cnt_o[0][1] + cnt_e[0][1]
    ans = n - rem_number


print(ans)

Solution (Python):
from collections import Counter


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


if len(set(lst_v)) == 1:
    ans = n // 2
else:
    lst_odd = lst_v[::2]
    lst_even = lst_v[1::2]
    cnt_odd = sorted(Counter(lst_odd).items(), key=lambda x: -x[1])
    cnt_even = sorted(Counter(lst_even).items(), key=lambda x :-x[1])

    if cnt_odd[0][0] == cnt_even[0][0]:
        rem_number = max(cnt_odd[0][1] + cnt_even[1][1], cnt_odd[1][1] + cnt_even[0][1])
    else:
        rem_number = cnt_odd[0][1] + cnt_even[0][1]
    sum_odd = sum(t[1] for t in cnt_odd)
    sum_even = sum(t[1] for t in cnt_even)
    ans = sum_odd + sum_even - rem_number


print(ans)

Solution (Python):
from collections import Counter, OrderedDict


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


if len(set(lst_v)) == 1:
    ans = n // 2
else:
    lst_odd = lst_v[::2]
    lst_even = lst_v[1::2]
    cnt_odd = sorted(Counter(lst_odd).items(), key=lambda x: -x[1])
    cnt_even = sorted(Counter(lst_even).items(), key=lambda x :-x[1])

    if cnt_odd[0][0] == cnt_even[0][0]:
        rem_number = max(cnt_odd[0][1] + cnt_even[1][1], cnt_odd[1][1] + cnt_even[0][1])
    else:
        rem_number = cnt_odd[0][1] + cnt_even[0][1]
    sum_odd = sum(t[1] for t in cnt_odd)
    sum_even = sum(t[1] for t in cnt_even)
    ans = sum_odd + sum_even - rem_number


print(ans)

Solution (Python):
from collections import Counter


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


if len(set(lst_v)) == 1:
    ans = n // 2
else:
    lst_odd = lst_v[::2]
    lst_even = lst_v[1::2]
    cnt_odd = sorted(Counter(lst_odd).items(), key=lambda x: -x[1])
    cnt_even = sorted(Counter(lst_even).items(), key=lambda x :-x[1])
    o1 = cnt_odd[0]
    e1 = cnt_even[0]

    if o1[0] == e1[0]:
        o2 = cnt_odd[1] if cnt_odd[1] else (0, 0)
        e2 = cnt_even[1] if cnt_even[1] else (0, 0)
        rem_number = max(o1[1] + e2[1], o2[1] + e1[1])
    else:
        rem_number = o1[1] + e1[1]
    sum_odd = sum(t[1] for t in cnt_odd)
    sum_even = sum(t[1] for t in cnt_even)
    ans = sum_odd + sum_even - rem_number


print(ans)

Solution (Python):
from collections import Counter, OrderedDict


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


if len(set(lst_v)) == 1:
    ans = n // 2
else:
    lst_odd = [lst_v[i] for i in range(n) if i%2==0]
    lst_even = [lst_v[i] for i in range(n) if i%2!=0]
    cnt_odd = sorted(Counter(lst_odd).items(), key=lambda x: -x[1])
    cnt_even = sorted(Counter(lst_even).items(), key=lambda x :-x[1])

    if cnt_odd[0][0] == cnt_even[0][0]:
        rem_number = max(cnt_odd[0][1] + cnt_even[1][1], cnt_odd[1][1] + cnt_even[0][1])
    else:
        rem_number = cnt_odd[0][1] + cnt_even[0][1]
    sum_odd = sum(t[1] for t in cnt_odd)
    sum_even = sum(t[1] for t in cnt_even)
    ans = sum_odd + sum_even - rem_number


print(ans)

Solution (Python):
import itertools
from collections import Counter
 
N = int(input())
V = [int(x) for x in input().split()]
EV_counter = Counter(V[::2])
OD_counter = Counter(V[1::2])
 

EV_counter[-1] = 0
OD_counter[-2] = 0
 

EV = EV_counter.most_common(2)
OD = OD_counter.most_common(2)
 
answer = N
for (k1,v1), (k2,v2) in itertools.product(EV,OD):
    if k1 == k2:
        continue
    x = (N - v1 - v2)
    if answer > x:
        answer = x

print(answer)

Solution (Python):
import collections 

n = int(input())
lst = list(map(int,input().split()))
lst_mode_odd = collections.Counter(lst[::2]).most_common()
l_odd = len(lst_mode_odd)
n_odd = lst_mode_odd[0][1]
num_odd = lst_mode_odd[0][0]
lst_mode_even = collections.Counter(lst[::-2]).most_common()
l_even = len(lst_mode_even)
n_even = lst_mode_even[0][1]
num_even = lst_mode_even[0][0]
if num_odd == num_even:
    if l_odd == l_even ==1:
        print(int(len(lst)/2))
        exit()
    elif l_odd == 1:
        n_even = lst_mode_even[1][1]
    elif l_even == 1:
        n_odd = lst_mode_odd[1][1]
    else:
        res_odd = lst_mode_odd[0][1]- lst_mode_odd[1][1]
        res_even = lst_mode_even[0][1]- lst_mode_even[1][1]
        if res_odd >= res_even:
            n_even = lst_mode_even[1][1]
        else:n_odd = lst_mode_odd[1][1]
    
ans = len(lst) - n_odd -n_even
print(ans)

Solution (Python):
import itertools
from collections import Counter

N = int(input())
V = [int(x) for x in input().split()]
EV_counter = Counter(V[::2])
OD_counter = Counter(V[1::2])


EV_counter[-1] = 0
OD_counter[-2] = 0


EV = EV_counter.most_common(2)
OD = OD_counter.most_common(2)

answer = N
for (k1,v1), (k2,v2) in itertools.product(EV,OD):
  if k1 == k2:
    continue
  x = (N - v1 - v2)
  if answer > x:
    answer = x

print(answer)

Solution (Python):
from collections import Counter
n=int(input())
nums=list(map(int,input().split()))
a=set(nums)
if len(a)==1:
  print(n//2)
else:
  odd=nums[::2]
  even=nums[1::2]
  o=Counter(odd)
  e=Counter(even)
  ans=n-o.most_common()[0][1]-e.most_common()[0][1]
  if o.most_common()[0][0]==e.most_common()[0][0]:
    print(ans+min(o.most_common()[0][1]-o.most_common()[1][1],e.most_common()[0][1]-e.most_common()[1][1]))
  else:  
    print(ans)

Solution (Python):
import collections

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

if v1[0][0]!=v2[0][0]:
    ans=len(v) - v1[0][1] - v2[0][1]
else:
    ans=min(len(v) - v1[0][1] - v2[1][1],len(v) - v1[1][1] - v2[0][1])

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
tmp = []
for i in range(0, n, 2):
    tmp.append(v[i])
c = Counter(tmp)
c1 = c.most_common(2)
tmp = []
for i in range(1, n, 2):
    tmp.append(v[i])
c = Counter(tmp)
c2 = c.most_common(2)
if c1[0][0] != c2[0][0]:
    print(n - (c1[0][1] + c2[0][1]))
    exit()
else:
    c1.append((-1, 0))
    c2.append((-1, 0))
    ans = min(n-c1[0][1]-c2[1][1], n-c1[1][1]-c2[0][1])
    print(ans)
    exit()

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

map_even_elem_dict = {}
map_odd_elem_dict = {}
for i,e in enumerate(v):
    if i % 2 == 0:
        if e in map_even_elem_dict:
            map_even_elem_dict[e] += 1
        else:
            map_even_elem_dict[e] = 1
    if i % 2 == 1:
        if e in map_odd_elem_dict:
            map_odd_elem_dict[e] += 1
        else:
            map_odd_elem_dict[e] = 1

even_dict_list = []
odd_dict_list = []

for k, v in map_even_elem_dict.items():
    even_dict_list.append((v, k))
    
for k, v in map_odd_elem_dict.items():
    odd_dict_list.append((v, k))
    
even_dict_list.sort()
odd_dict_list.sort()

max_even_occurence, max_even_elem = even_dict_list[-1]
max_odd_occurence, max_odd_elem = odd_dict_list[-1]

if max_even_elem != max_odd_elem:
    print(n // 2 - max_even_occurence + n // 2 - max_odd_occurence)
else:
    if max_even_occurence > max_odd_occurence:
        second_max_odd_occurence, _ = odd_dict_list[-2]
        print(n // 2 - max_even_occurence + n // 2 - second_max_odd_occurence)
    elif max_even_occurence < max_odd_occurence:
        second_max_even_occurence, _ = even_dict_list[-2]
        print(n // 2 - second_max_even_occurence + n // 2 - max_odd_occurence)
    else:
        if max_even_occurence == n // 2:
            print(n // 2)
        else:
            second_max_even_occurence, _ = even_dict_list[-2]
            second_max_odd_occurence, _ = odd_dict_list[-2]
            print(n // 2 - max_even_occurence + n // 2 - max(second_max_even_occurence, second_max_odd_occurence))

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l1=[]
  l2=[]

  for i in range(len(l)):
    if i%2==0:
      l1.append(l[i])
    else:
      l2.append(l[i])

  l1.sort()
  l2.sort()

  a=[]
  b=[]

  p=l1[0]
  c=1
  mx=1
  for x in l1[1:]:
    if x==p:
      c+=1
    else:
      a.append([p,c])
      c=1
      p=x
  a.append([p,c])

  p=l2[0]
  c=1
  mx=1
  for x in l2[1:]:
    if x==p:
      c+=1
    else:
      b.append([p,c])
      c=1
      p=x
  b.append([p,c])

  a=sorted(a,key=lambda x:x[1],reverse=True)
  b=sorted(b,key=lambda x:x[1],reverse=True)

  if a[0][0]==b[0][0]:
    if len(a)==1 and len(b)==1:
      return n//2
    return min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1])
  return n-a[0][1]-b[0][1]

print(main())

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l1=[]
  l2=[]

  for i in range(len(l)):
    if i%2==0:
      l1.append(l[i])
    else:
      l2.append(l[i])

  l1.sort()
  l2.sort()

  a=[]
  b=[]

  p=l1[0]
  c=1
  mx=1
  for x in l1[1:]:
    if x==p:
      c+=1
    else:
      a.append([p,c])
      c=1
      p=x
  a.append([p,c])

  p=l2[0]
  c=1
  mx=1
  for x in l2[1:]:
    if x==p:
      c+=1
    else:
      b.append([p,c])
      c=1
      p=x
  b.append([p,c])

  a=sorted(a,key=lambda x:x[1],reverse=True)
  b=sorted(b,key=lambda x:x[1],reverse=True)

  if a[0][0]==b[0][0]:
    if len(a)==1 and len(b)==1:
      return n//2
    
    
    
    else:
      return min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1])
  return n-a[0][1]-b[0][1]

print(main())

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

c1 = collections.Counter(v_array[0::2])
c2 = collections.Counter(v_array[1::2])
c1_num, c1_count = c1.most_common()[0]
_, c1_second = c1.most_common()[1] if len(c1) > 1 else [0, 0]
c2_num, c2_count = c2.most_common()[0]
_, c2_second = c2.most_common()[1] if len(c2) > 1 else [0, 0]
if c1_num != c2_num:
    ans = n - (c1_count + c2_count)

else:
    ans = n - max(c1_count + c2_second, c1_second + c2_count)

print(ans)

Solution (Python):

n = int(input())
odd = {}
eve = {}

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

for i in range(n):
    
    new_v = nums[i]
    
    if (i % 2 == 0):

        if new_v in odd:
            odd[new_v] += 1

        else:
            odd[new_v] = 1

    else:

        if new_v in eve:
            eve[new_v] += 1

        else:
            eve[new_v] = 1



odd_m = max(odd , key=odd.get)
eve_m = max(eve , key=eve.get)

odd_c = odd.copy()
eve_c = eve.copy()

del odd_c[odd_m]
del eve_c[eve_m]

if len(odd_c) == 0:
    odd_mt = 0
else:
    odd_mt = max(odd_c , key=odd.get)

if len(eve_c) == 0:
    eve_mt = 0
else:
    eve_mt = max(eve_c , key=eve.get)

odd[0] = 0
eve[0] = 0


if odd_m != eve_m:
    print (n - odd[odd_m] - eve[eve_m])

elif odd[odd_m] + eve[eve_mt] > odd[odd_mt] + eve[eve_m] :
    print (n - odd[odd_m] - eve[eve_mt])

else:
    print (n - odd[odd_mt] - eve[eve_m])

Solution (Python):
def resolve():
    N = int(input())
    V = list(map(int, input().split(" ")))
    
    evens = V[::2]
    odds = V[1::2]

    import collections
    evenMosts = collections.Counter(evens).most_common()
    oddMosts = collections.Counter(odds).most_common()
    evenM = evenMosts[0]
    oddM = oddMosts[0]

    if len(evenMosts) == 1:
        if len(oddMosts) == 1:
            if evenM[0] != oddM[0]:
                print(0)
            else:
                print(evenM[1])
            return
        else:
            print(len(odds)-oddM[1])
            return
    else:
        if len(oddMosts) == 1:
            print(len(evens)-evenM[1])
            return
        else:
            if evenM[0] == oddM[0]: 
                if (len(evens)-evenMosts[1][1]+len(odds)-oddM[1]) <= (len(evens)-evenM[1] + len(odds)-oddMosts[1][1]):
                    evenM = evenMosts[1]
                else:
                    oddM = oddMosts[1]
            print((len(evens)-evenM[1])+(len(odds)-oddM[1]))
            return
    


if '__main__' == __name__:
    resolve()

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


oc = Counter(v[::2]).most_common(2)
ec = Counter(v[1::2]).most_common(2)


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

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

v1=Counter(v[::2])
v2=Counter(v[1::2])
lenv=len(v)
c1=v1.most_common()
c2=v2.most_common()

if c1[0][0]!=c2[0][0]:
    print(lenv-c1[0][1]-c2[0][1])
else:
    if c1[0][1]==c2[0][1]==len(v)//2:
        print(lenv//2)
    elif c1[0][1]==len(v)//2:
        print(lenv//2-c2[1][1])
    elif c2[0][1]==len(v)//2:
        print(lenv//2-c1[1][1])    
    else:
        print(lenv-max(c1[0][1]+c2[1][1],c1[1][1]+c2[0][1]))

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l1=[]
  l2=[]

  f=True
  for x in l:
    if f:
      f=False
      l1.append(x)
    else:
      f=True
      l2.append(x)

  l1.sort()
  l2.sort()

  l3=[]
  l4=[]

  a=l1[0]
  c=1
  for x in l1[1:]:
    if a==x:
      c+=1
    else:
      l3.append([a,c])
      a=x
      c=1
  l3.append([a,c])

  a=l2[0]
  c=1
  for x in l2[1:]:
    if a==x:
      c+=1
    else:
      l4.append([a,c])
      a=x
      c=1
  l4.append([a,c])

  l3=sorted(l3,key=lambda x:x[1],reverse=True)
  l4=sorted(l4,key=lambda x:x[1],reverse=True)

  if l3[0][0]==l4[0][0]:
    if len(l3)==1 and len(l4)==1:
      return n//2
    elif len(l3)==1:
      return n-l3[0][1]-l4[1][1]
    elif len(l4)==1:
      return n-l3[1][1]-l4[0][1]
    else:
      return min(n-l3[0][1]-l4[1][1],n-l3[1][1]-l4[0][1])
  else:
    return n-l3[0][1]-l4[0][1]

print(main())

Solution (Python):
from collections import Counter
N = int(input())
V = list(map(int,input().split()))
zero = Counter(V[::2]).most_common()
one = Counter(V[1::2]).most_common()
if zero[0][0] != one[0][0]:
    print(N-zero[0][1]-one[0][1])
else:
    if len(zero) == 1 and len(one) == 1:
        print(N//2)
    elif len(zero) == 1:
        print(N-zero[0][1]-one[1][1])
    elif len(one) == 1:
        print(N-zero[1][1]-one[0][1])
    else:
        print(min(N-zero[1][1]-one[0][1],N-zero[0][1]-one[1][1]))

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
b = []
c = []

for i, vv in enumerate(v):
    if i%2 == 0:
        b.append(vv)
    else:
        c.append(vv)

b_set = {}
c_set = {}

for bb in b:
    if not bb in b_set.keys():
        b_set[bb] = 1
    else:
        b_set[bb] += 1

for cc in c:
    if not cc in c_set.keys():
        c_set[cc] = 1
    else:
        c_set[cc] += 1

b_sorted = []
c_sorted = []

for key, value in b_set.items():
    b_sorted.append([value,key])
for key, value in c_set.items():
    c_sorted.append([value,key])

b_sorted = sorted(b_sorted, reverse=True)
b_sorted += [[0,0]]
c_sorted = sorted(c_sorted, reverse=True)
c_sorted += [[0,0]]


if b_sorted[0][1] != c_sorted[0][1]:
    ans = n - b_sorted[0][0] - c_sorted[0][0]
else:
    try1 = n - b_sorted[1][0] - c_sorted[0][0]
    try2 = n - b_sorted[0][0] - c_sorted[1][0]
    ans = min(try1,try2)

print(ans)

Solution (Python):



import sys

input = sys.stdin.readline

def main():
    N = int(input())
    S = list(map(int, input().split()))
    odd = {}
    even = {}
    for i in range(N):
        if i % 2 == 0:
            if S[i] not in even:
                even[S[i]] = 1
            else:
                even[S[i]] += 1
        else:
            if S[i] not in odd:
                odd[S[i]] = 1
            else:
                odd[S[i]] += 1

    n = 1000000000
    emk = None
    ev1 = None
    ev2 = 0
    for ek, ev in even.items():
        if emk is None:
            emk = ek
            ev1 = ev
        elif ev > ev1:
            emk = ek
            ev2 = ev1
            ev1 = ev
        elif ev > ev2:
            ev2 = ev

    omk = None
    ov1 = None
    ov2 = 0
    for ok, ov in odd.items():
        if omk is None:
            omk = ok
            ov1 = ov
        elif ov > ov1:
            omk = ok
            ov2 = ov1
            ov1 = ov
        elif ov > ov2:
            ov2 = ov

    if emk != omk:
        n = min(n, N - ev1 - ov1)
    else:
        n = min(n, N - ev1 - ov2, N - ev2 - ov1)

    print(n)

main()

Solution (Python):
n=int(input())
even=[0]*(int(n/2))
odd=[0]*(int(n/2))
inp=list(map(int,input().split()))
for i in range(n):
    if i%2==0:
        even[int(i/2)]=inp[i]
    else:
        odd[int((i-1)/2)]=inp[i]
even.sort()
odd.sort()
def count(lst):
    tmp=cnt=maxcnt=maxi=precnt=0
    for i in lst:
        if tmp==i:
            cnt+=1      
        else:
            if cnt>maxcnt:
                precnt=maxcnt;maxcnt=cnt;maxi=tmp
            else:
                precnt=max(cnt,precnt)
            cnt=1;tmp=i
    if cnt>maxcnt:
        precnt=maxcnt;maxcnt=cnt;maxi=tmp
    else:
        precnt=max(cnt,precnt)
    return maxcnt,precnt,maxi
        
        
ev,od=count(even),count(odd)
if n==2:
    if ev==od:
        print(1)
    else:
        print(0)
    
elif ev[2]!=od[2]:
    print(n-ev[0]-od[0])
else:
    a=n-ev[0]-od[1]
    b=n-od[0]-ev[1]
    print(min(a,b))

Solution (Python):
import collections as cl

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

odd_lst = [v_lst[i] for i in range(0, len(v_lst), 2)]
even_lst = [v_lst[i] for i in range(1, len(v_lst), 2)]

odd_value_dic = cl.Counter(odd_lst)
even_value_dic = cl.Counter(even_lst)

odd_value_tup_lst = sorted(odd_value_dic.items(), key=lambda x: x[1], reverse=True)
even_value_tup_lst = sorted(even_value_dic.items(), key=lambda x: x[1], reverse=True)


odds_first = odd_value_tup_lst[0][1]
evens_first = even_value_tup_lst[0][1]
ans = n - odds_first - evens_first
"""
print(odd_value_tup_lst)
print(even_value_tup_lst)
print()
"""

if odd_value_tup_lst[0][0] == even_value_tup_lst[0][0]:
    if len(odd_value_tup_lst) == len(even_value_tup_lst) == 1:
        ans = odd_value_tup_lst[0][1]
    elif len(odd_value_tup_lst) == 1:
        evens_first = even_value_tup_lst[1][1]
        ans = n - evens_first
    elif len(even_value_tup_lst) == 1:
        odds_first = odd_value_tup_lst[1][1]
        ans = n - odds_first
    elif odds_first - odd_value_tup_lst[1][1] > evens_first - even_value_tup_lst[1][1]:
        evens_first = even_value_tup_lst[1][1]
        ans = n - odds_first - evens_first
    else:
        odds_first = odd_value_tup_lst[1][1]
        ans = n - odds_first - evens_first

print(ans)

Solution (Python):
import collections

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

odd_l = []
even_l = []

if v.count(v[0]) == n:
    ans = n // 2
else:
    for i in range(0, n, 2):
        odd_l.append(v[i])
        even_l.append(v[i+1])

    odd_c = collections.Counter(odd_l)
    even_c = collections.Counter(even_l)

    odd = odd_c.most_common()[0][1]
    odd_num = odd_c.most_common()[0][0]

    even = even_c.most_common()[0][1]
    even_num = even_c.most_common()[0][0]

    if odd_num != even_num:
        ans = n - (odd + even)
    else:
        odd = odd_c.most_common()[1][1]
        even = even_c.most_common()[0][1]
        ans_change_odd = n - (odd + even)

        odd = odd_c.most_common()[0][1]
        even = even_c.most_common()[1][1]
        ans_change_even  = n - (odd + even)

        ans = min(ans_change_odd, ans_change_even)

print(ans)

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

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=II()
  l=LI()

  l1=[]
  l2=[]

  for i in range(len(l)):
    if i%2==0:
      l1.append(l[i])
    else:
      l2.append(l[i])

  l1.sort()
  l2.sort()

  a1=[l1[0],1]
  a2=[0,0]
  b1=[l2[0],1]
  b2=[0,0]

  _a=l1[0]
  c1=1
  for x in l1[1:]:
    if _a==x:
      c1+=1
    else:
      if c1>a1[1]:
        if a1[0]!=l1[0]:
          a2[0]=a1[0]
          a2[1]=a1[1]
        a1[0]=_a
        a1[1]=c1
      elif c1>a2[1]:
        if a1[0]!=_a:
          a2[0]=_a
          a2[1]=c1
      _a=x
      c1=1
  if c1>a1[1]:
    if a1[0]!=l1[0]:
      a2[0]=a1[0]
      a2[1]=a1[1]
    a1[0]=_a
    a1[1]=c1
  elif c1>a2[1]:
    if a1[0]!=_a:
      a2[0]=_a
      a2[1]=c1

  _b=l2[0]
  c2=1
  for x in l2[1:]:
    if _b==x:
      c2+=1
    else:
      if c2>b1[1]:
        if b1[0]!=l2[0]:
          b2[0]=b1[0]
          b2[1]=b1[1]
        b1[0]=_b
        b1[1]=c2
      elif c2>b2[1]:
        if b1[0]!=_b:
          b2[0]=_b
          b2[1]=c2
      _b=x
      c2=1
  if c2>b1[1]:
    if b1[0]!=l2[0]:
      b2[0]=b1[0]
      b2[1]=b1[1]
    b1[0]=_b
    b1[1]=c2
  elif c2>b2[1]:
    if b1[0]!=_b:
      b2[0]=_b
      b2[1]=c2

  if a1[0]!=b1[0]:
    return len(l1)-a1[1]+len(l2)-b1[1]
  else:
    return min(len(l1)-a1[1]+len(l2)-b2[1],len(l1)-a2[1]+len(l2)-b1[1])


print(main())

Solution (Python):
import collections

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

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

else:
    v_odd = collections.Counter(v[0::2])
    v_even = collections.Counter(v[1::2])

    v_odd = list(sorted(v_odd.items(), key = lambda x:-x[1]))
    v_even = list(sorted(v_even.items(), key = lambda x:-x[1]))

    if v_odd[0][0] == v_even[0][0]:
        if v_odd[1][1] > v_even[1][1]:
            print(n - v_odd[1][1] - v_even[0][1])
        else:
            print(n - v_odd[0][1] - v_even[1][1])
 
    else:
        print(n - v_odd[0][1] - v_even[0][1])

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())


N = int(input())
V = list(mi())

oddl = V[0::2]
evenl = V[1::2]


obuckets = [0]*(10**5 + 1)
ebuckets = [0]*(10**5 + 1)
for o in oddl:
  obuckets[o] += 1
for e in evenl:
  ebuckets[e] += 1

o1cnt = max(obuckets)
o1 = obuckets.index(o1cnt)
obuckets[o1] = 0

o2cnt = max(obuckets)
o2 = obuckets.index(o2cnt)
obuckets[o2] = 0

e1cnt = max(ebuckets)
e1 = ebuckets.index(e1cnt)
ebuckets[e1] = 0

e2cnt = max(ebuckets)
e2 = ebuckets.index(e2cnt)
ebuckets[e2] = 0

Nd2 = round(N/2) 
if o1 != e1:
  print(Nd2-o1cnt + Nd2-e1cnt)
else: print(min(Nd2-o1cnt + Nd2-e2cnt, Nd2-o2cnt + Nd2-e1cnt))

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())
l = list(map(int, input().split()))

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

leven = [x for x in l[::2]]
lodd  = [x for x in l[1::2]]

ce = collections.Counter(leven)
co = collections.Counter(lodd)
ce = sorted(ce.items(), key=lambda x:x[1])
co = sorted(co.items(), key=lambda x:x[1])

if ce[-1][0] != co[-1][0]:
	print(n - ce[-1][1] - co[-1][1])
elif ce[-2][1] > co[-2][1]:
    print(n - ce[-2][1] - co[-1][1])
else:
    print(n - ce[-1][1] - co[-2][1])

Solution (Python):
from collections import Counter

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

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

c_even = Counter(even)
c_odd = Counter(odd)

arr_even = c_even.most_common()
arr_odd = c_odd.most_common()

sum_even = sum(x[1] for x in arr_even)
sum_odd = sum(x[1] for x in arr_odd)

min_sum = sum_even - arr_even[0][1] + n // 2

for i, x in arr_even:
    for j, y in arr_odd:
        if i != j:
            cnt = sum_even - x + sum_odd - y
            min_sum = min(min_sum, cnt)
            break
        else:
            continue

print(min_sum)