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):
'''input
4
1 1 1 1
'''
N = int(input())

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

lyg = {}
nel = {}

for i in range(N):
	if i & 1:
		if sk[i] in nel:
			nel[sk[i]] += 1
		else:
			nel[sk[i]] = 1
	else:
		if sk[i] in lyg:
			lyg[sk[i]] += 1
		else:
			lyg[sk[i]] = 1


nel = sorted(nel.items(), key=lambda kv: kv[1]);
lyg = sorted(lyg.items(), key=lambda kv: kv[1]);

nel.reverse();
lyg.reverse();

nel.append((-12, 0))
lyg.append((-12, 0))

if nel[0][0] != lyg[0][0]:
	ats = (N+1)//2 - nel[0][1] + N//2 - lyg[0][1];
else:
	if N <= 3:
		ats = 1
	else:
		ats = min((N+1)//2 - nel[0][1] + N//2 - lyg[1][1], (N+1)//2 - nel[1][1] + N//2 - lyg[0][1])

print(ats)

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

odd = {}
even = {}

for i in range(len(v)):
    if i % 2 == 1:
        if v[i] in odd:
            odd[v[i]] += 1
        else:
            odd[v[i]] = 1
    else:
        if v[i] in even:
            even[v[i]] += 1
        else:
            even[v[i]] = 1


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


def count_rewrite(odd, even):
    ans = 0
    for i in range(len(v)):
        if i % 2:
            if v[i] != odd:
                ans += 1
        else:
            if v[i] != even:
                ans += 1
    return ans


ans = 1000002

if odd_sorted[0][0] == even_sorted[0][0]:
    
    if len(odd.keys()) > 1 and len(even.keys()) > 1:
        ans = min(ans, count_rewrite(odd_sorted[0][0], even_sorted[1][0]))
        ans = min(ans, count_rewrite(odd_sorted[1][0], even_sorted[0][0]))
    
    elif len(odd.keys()) == 1 and len(even.keys()) == 1:
        ans = min(ans, count_rewrite(-1, even_sorted[0][0]))
    
    elif len(odd.keys()):
        ans = min(ans, count_rewrite(odd_sorted[0][0], even_sorted[1][0]))
    
    else: 
        ans = min(ans, count_rewrite(odd_sorted[1][0], even_sorted[0][0]))

else:
    ans = min(ans, count_rewrite(odd_sorted[0][0], even_sorted[0][0]))


print(ans)

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

odd = {}
even = {}

for i in range(len(v)):
    if i % 2 == 1:
        if v[i] in odd:
            odd[v[i]] += 1
        else:
            odd[v[i]] = 1
    else:
        if v[i] in even:
            even[v[i]] += 1
        else:
            even[v[i]] = 1


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





if odd_sorted[0][0] == even_sorted[0][0]:
    
    if len(odd.keys()) > 1 and len(even.keys()) > 1:
        
        if odd_sorted[0][1] > even_sorted[0][1]:
            ans_odd = odd_sorted[0][0]
            ans_even = even_sorted[1][0]
        elif odd_sorted[0][1] < even_sorted[0][1]:
            ans_odd = odd_sorted[1][0]
            ans_even = even_sorted[0][0]
        else:
            
            if odd_sorted[1][1] >= even_sorted[1][1]:
                ans_odd = odd_sorted[1][0]
                ans_even = even_sorted[0][0]
            elif odd_sorted[1][1] < even_sorted[1][1]:
                ans_odd = odd_sorted[0][0]
                ans_even = even_sorted[1][0]

    
    elif len(odd.keys()) == 1 and len(even.keys()) == 1:
        ans_odd = -1
        ans_even = even_sorted[0][0]
    
    elif len(odd.keys()):
        ans_odd = odd_sorted[0][0]
        ans_even = even_sorted[1][0]
    
    else: 
        ans_odd = odd_sorted[1][0]
        ans_even = even_sorted[0][0]

else:
    ans_odd = odd_sorted[0][0]
    ans_even = even_sorted[0][0]

ans = 0
for i in range(len(v)):
    if i % 2:
        if v[i] != ans_odd:
            ans += 1
    else:
        if v[i] != ans_even:
            ans += 1



print(ans)

Solution (Python):

import string
import sys
from collections import Counter
from itertools import chain, dropwhile, takewhile


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in read(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    n = readi()
    v = readi(n)
    l1 = v[::2]
    l2 = v[1::2]

    mc1 = Counter(l1).most_common()
    mc2 = Counter(l2).most_common()
    if mc1[0][0] != mc2[0][0]:
        print((n // 2 - mc1[0][1]) + (n // 2 - mc2[0][1]))
    else:
        if len(mc1) > 1 and len(mc2) == 1:
            print((n // 2 - mc1[1][1]) + (n // 2 - mc2[0][1]))
        elif len(mc1) == 1 and len(mc2) > 1:
            print((n // 2 - mc1[0][1]) + (n // 2 - mc2[1][1]))
        elif len(mc1) > 1 and len(mc2) > 1:
            print(
                min(
                    (n // 2 - mc1[1][1]) + (n // 2 - mc2[0][1]),
                    (n // 2 - mc1[0][1]) + (n // 2 - mc2[1][1]),
                )
            )
        else:
            print(n // 2)


if __name__ == "__main__":
    main()

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

dict1 = {}
dict2 = {}
flag = 1
for v in v_list:
  if flag > 0:
    if v in dict1:
      dict1[v] = dict1[v] + 1
    else:
      dict1[v] = 1
  else:
    if v in dict2:
      dict2[v] = dict2[v] + 1
    else:
      dict2[v] = 1
  flag = -1 * flag
list1 = list(dict1.items())
list2 = list(dict2.items())
list1_value = [t[0] for t in list1]
list1_num = [t[1] for t in list1]
list2_value = [t[0] for t in list2]
list2_num = [t[1] for t in list2]
list1_num_max = max(list1_num)
list2_num_max = max(list2_num)
if list1_value[list1_num.index(list1_num_max)] != list2_value[list2_num.index(list2_num_max)]:
  print(n - list1_num_max - list2_num_max)
else:
  ind1 = list1_num.index(list1_num_max)
  del list1_value[ind1]
  del list1_num[ind1]
  ind2 = list2_num.index(list2_num_max)
  del list2_value[ind2]
  del list2_num[ind2]
  list1_num_max_2nd = max(list1_num) if len(list1_num) > 0 else 0
  list2_num_max_2nd = max(list2_num) if len(list2_num) > 0 else 0
  if list1_num_max_2nd * list2_num_max_2nd > 0:
    print(min(n - list1_num_max - list2_num_max_2nd, 
             n- list2_num_max - list1_num_max_2nd))
  else:
    print(int(n/2))

Solution (Python):
N = int(input())
li=[int(it) for it in input().split()]
lia=li[::2]
lib=li[1::2]

import collections
ca = list(collections.Counter(lia).items())
cb = list(collections.Counter(lib).items())
na = len(lia)
nb = len(lib)
ca.sort(key=lambda x:-x[1])
cb.sort(key=lambda x:-x[1])
s = 0
if ( ca[0][0] != cb[0][0] ):
  s += na - ca[0][1]
  s += nb - cb[0][1]
else:
  if ( ca[0][1] > cb[0][1]   ):
    s += na - ca[0][1]
    if ( len(cb)>1 ):
      s += nb - cb[1][1]
    else:
      s += nb
  elif (ca[0][1] < cb[0][1]) :
    s += nb - cb[0][1]
    if ( len(ca)>1 ):
      s += na - ca[1][1]
    else:
      s += na
  else:
    p1 = cb[0][1]
    p2 = ca[0][1]
    if (len(ca)>1):
      p1+=ca[1][1]
    if (len(cb)>1):
      p2+=cb[1][1]
    s += na + nb - max(p1,p2)
    
print (s)

Solution (Python):
def basket_count(arr):
    basket = []
    tmp = arr[0]
    cnt_ele = 0
    for ele in arr:
        if ele == tmp:
            cnt_ele += 1
        else:
            basket.append([tmp, cnt_ele])
            
            tmp = ele
            cnt_ele = 1
    basket.append([tmp, cnt_ele])
    return basket

def solve():
    n = int(raw_input())
    v = [int(_) for _ in raw_input().split()]
    v0 = []
    v1 = []
    for i in range(n):
        if i % 2 == 0:
            v0.append(v[i])
        else:
            v1.append(v[i])
    v0.sort()
    v1.sort()
    bask_v0 = basket_count(v0)
    bask_v0.sort(reverse = True, key = lambda x: x[1])
    bask_v1 = basket_count(v1)
    bask_v1.sort(reverse = True, key = lambda x: x[1])
    if bask_v0[0][0] != bask_v1[0][0]:
        ret = n - (bask_v0[0][1] + bask_v1[0][1])
    elif len(bask_v1) <= 1:
        if len(bask_v0) > 1:
            ret = n - (bask_v0[1][1] + bask_v1[0][1])
        else:
            ret = n - bask_v0[0][1]
    else: 
        if len(bask_v0) <= 1:
            ret = n - (bask_v0[0][1] + bask_v1[1][1])
        else:
            ret = n - max(bask_v0[0][1] + bask_v1[1][1], \
                          bask_v0[1][1] + bask_v1[0][1])
    print str(ret)

if __name__ == '__main__':
    solve()

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

v_dict = [{} for _ in range(2)]
for i in range(n):
    if i % 2 == 0:
        if v[i] in v_dict[0]:
            v_dict[0][v[i]] += 1
        else:
            v_dict[0][v[i]] = 1
    else:
        if v[i] in v_dict[1]:
            v_dict[1][v[i]] += 1
        else:
            v_dict[1][v[i]] = 1

evens = sorted([(key, val) for key, val in v_dict[0].items()], key=lambda comb: comb[1])
odds = sorted([(key, val) for key, val in v_dict[1].items()], key=lambda comb: comb[1])

ans = 0
for _, val in evens[:-1]:
    ans += val
for _, val in odds[:-1]:
    ans += val
if evens[-1][0] == odds[-1][0]:
    if len(evens) > 1 and len(odds) > 1:
        if evens[-2][1] < odds[-2][1]:
            ans += odds[-1][1] - odds[-2][1]
        else:
            ans += evens[-1][1] - evens[-2][1]
    elif len(evens) > 1:
        ans += evens[-1][1] - evens[-2][1]
    elif len(odds) > 1:
        ans += odds[-1][1] - odds[-2][1]
    else:
        ans = n // 2

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a1 = {'emp':0}
a2 = {'emp':0}

for i in range(0,n,2):
    
    if str(a[i]) in a1.keys():
        a1[str(a[i])] += 1
    else :
        a1[str(a[i])] = 1
    if str(a[i+1]) in a2.keys():
        a2[str(a[i+1])] += 1
    else :
        a2[str(a[i+1])] = 1


a1 = sorted(a1.items(), key=lambda x: -x[1])
a2 = sorted(a2.items(), key=lambda x: -x[1])


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

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

Solution (Python):
from collections import Counter

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


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

e1,e2 = e.most_common(2)
o1,o2 = o.most_common(2)

if e1[0] != o1[0]:
    print(n - (e1[1] + o1[1]))
else:
    print(n - max(e1[1]+o2[1],e2[1]+o1[1]))

Solution (Python):
import numpy as np
n=int(input())
V=[int(v) for v in input().split()]

M=max(V)
count_odd=np.array([0 for i in range(M+1)])
count_even=np.array([0 for i in range(M+1)])

for i in range(len(V)):
	if(i%2==0):
		count_even[V[i]]+=1
	if(i%2==1):
		count_odd[V[i]]+=1

if(np.argmax(count_odd)!=np.argmax(count_even)):
	print(n-max(count_odd)-max(count_even))
else:
	count_odd.sort()
	count_even.sort()
	print(min(n-count_odd[-1]-count_even[-2],n-count_odd[-2]-count_even[-1]))

Solution (Python):

import sys
from collections import Counter
INF = float("inf")


def solve(n: int, v: "List[int]"):
    c0 = Counter(v[0::2])
    c1 = Counter(v[1::2])

    
    
    c0[0] = 0
    c1[0] = 0

    mc0 = c0.most_common(2)
    mc1 = c1.most_common(2)

    v0, v1 = -INF, -INF

    if mc0[0][0] == mc1[0][0]:
        if mc0[0][1] + mc1[1][1] < mc0[1][1] + mc1[0][1]:
            v0 = mc0[1][1]
            v1 = mc1[0][1]
        else:
            v0 = mc0[0][1]
            v1 = mc1[1][1]
    else:
        v0 = mc0[0][1]
        v1 = mc1[0][1]

    print(n - v0-v1)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    v = [int(next(tokens)) for _ in range(n)]  
    solve(n, v)


if __name__ == '__main__':
    main()

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

v1, v2 = defaultdict(int), defaultdict(int)
for i, vv in enumerate(v):
    if i%2 == 0:
        v1[vv] += 1
    else:
        v2[vv] += 1
v1 = sorted([(c, vv) for vv, c in v1.items()], reverse = True)
v2 = sorted([(c, vv) for vv, c in v2.items()], reverse = True)

if v1[0][1] == v2[0][1]:
    if len(v1) == 1 and len(v2) == 1:
        ans = n//2
    elif v1[1][0] > v2[1][0]:
        ans = n - v1[1][0] - v2[0][0]
    else:
        ans = n - v1[0][0] - v2[1][0]
else:
    ans = n - v1[0][0] - v2[0][0]
print(ans)

Solution (Python):
from collections import defaultdict

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

evens = defaultdict(int)
odds = defaultdict(int)

for i in range(n):
    if i % 2 == 0:
        evens[vs[i]] += 1
    else:
        odds[vs[i]] += 1

evens = sorted(list(evens.items()), key=lambda x: x[1], reverse=True)
evens.append((0, 0))
odds = sorted(list(odds.items()), key=lambda x: x[1], reverse=True)
odds.append((0, 0))

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

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
v_even = [ele for i, ele in enumerate(v) if i%2==0]
v_odd  = [ele for i, ele in enumerate(v) if i%2==1]
counter_even = Counter(v_even).most_common(2)
counter_odd  = Counter(v_odd).most_common(2)

if counter_even[0][0] != counter_odd[0][0]:
    print(n - counter_even[0][1] - counter_odd[0][1])
else:
    if len(counter_even) > 1 and len(counter_odd) > 1:
        if counter_even[0][1] > counter_odd[0][1]:
            print(n - counter_even[0][1] - counter_odd[1][1])
        elif counter_even[0][1] < counter_odd[0][1]:
            print(n - counter_odd[0][1] - counter_even)
        else:
            if counter_even[1][1] > counter_odd[1][1]:
                print(n - counter_odd[0][1] - counter_even[1][1])
            else:
                print(n - counter_even[0][1] - counter_odd[1][1])

    elif len(counter_even) == 1 and len(counter_odd) > 1:
        print(int(n/2) - counter_odd[1][1])
    elif len(counter_even) > 1 and len(counter_odd) == 1:
        print(int(n/2) - counter_even[1][1])
    else:
        print(int(n/2))

Solution (Python):
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])


def search_mode(list):
    dict = {}
    mode = 0
    for l in list:
        if l in dict.keys():
            dict[l] += 1
            if mode < dict[l]:
                mode = dict[l]
        else:
            dict[l] = 1
    dict = sorted(dict.items(), key=lambda x: -x[1])
    return dict


even_dict = search_mode(even)
odd_dict = search_mode(odd)

if len(even_dict) == 1 and len(odd_dict) == 1:
    if even_dict[0][0] == odd_dict[0][0]:
        print(n // 2)
    else:
        print(0)
elif len(even_dict) == 1:
    if even_dict[0][0] == odd_dict[0][0]:
        print(len(odd) - odd_dict[1][1])
    else:
        print(len(odd) - odd_dict[0][1])
elif len(odd_dict) == 1:
    if odd_dict[0][0] == even_dict[0][0]:
        print(len(even) - even_dict[1][1])
    else:
        print(len(even) - even_dict[0][1])
elif even_dict[0][0] == odd_dict[0][0]:
    eo01 = n - even_dict[0][1] - odd_dict[1][1]
    eo10 = n - even_dict[1][1] - odd_dict[0][1]
    max_count = min(eo01, eo10)
    print(max_count)
else:
    print(n - even_dict[0][1] - odd_dict[0][1])

Solution (Python):
import collections
n = int(input())
v = [int(i) for i in input().split()]
v_even = [v[2*i] for i in range(int(n/2))]
v_odd = [v[2*i-1] for i in range(int(n/2))]
c_even = collections.Counter(v_even)
c_odd = collections.Counter(v_odd)
if(c_even.most_common()[0][0]!=c_odd.most_common()[0][0]):
    print(n - c_even.most_common()[0][1] - c_odd.most_common()[0][1])
elif(len(collections.Counter(v))==1):
    print(int(n/2))
else:
    if(c_even.most_common()[0][1]>c_odd.most_common()[0][1]):
        print(n-c_even.most_common()[0][1] - c_odd.most_common()[1][1])
    elif(c_even.most_common()[0][1]<c_odd.most_common()[0][1]):
        print(n - c_odd.most_common()[0][1] - c_even.most_common()[1][1])
    else:
        print(n - c_odd.most_common()[0][1] - max(c_odd.most_common()[1][1],c_even.most_common()[1][1]))

Solution (Python):
import collections

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

c1 = collections.Counter(v[::2]).most_common()
c2 = collections.Counter(v[1::2]).most_common()

if c1[0][0] != c2[0][0]:
  ans = n - c1[0][1] - c2[0][1]
elif len(c1) >=2 and len(c2) >= 2:
  if c1[1][1] > c2[1][1]:
    ans = n - c1[1][1] - c2[0][1]
  else:
    ans = n - c1[0][1] - c2[1][1]
elif len(c1) >= 2 and len(c2) == 1:
  ans = n - c1[0][1]
elif len(c1) == 1 and len(c2) >= 2:
  ans = n - c2[0][1]
else:
  ans = n - c1[0][1]

print(ans)

Solution (Python):
def get_top2_dict(dict1):
  numlist=tuple(dict1.items())
  best=[(0,0),(0,0)]
  for x in numlist:
    if x[1]>=best[0][1]:
      best[1]=best[0]
      best[0]=x
    elif x[1]>=best[1][1]:
      best[1]=x
  return best

n=int(input())
numlist=[int(x) for x in input().split()]
even=0
odd=1
evenlist={}
oddlist={}
while even<n:
  try:
    evenlist[numlist[even]]
  except:
    evenlist[numlist[even]]=0
  evenlist[numlist[even]]+=1
  even+=2

while odd<n:
  try:
    oddlist[numlist[odd]]
  except:
    oddlist[numlist[odd]]=0
  oddlist[numlist[odd]]+=1
  odd+=2

besteven=get_top2_dict(evenlist)
bestodd=get_top2_dict(oddlist)

if besteven[0][0]!=bestodd[0][0]:
  print(n-besteven[0][1]-bestodd[0][1])
elif besteven[1][1]+bestodd[0][1]>besteven[0][1]+bestodd[1][1]:
  print(n-besteven[1][1]-bestodd[0][1])
else:
  print(n-besteven[0][1]-bestodd[1][1])

Solution (Python):

from collections import Counter
N = int(input())
l = list(map(int,input().split()))
if len(set(l)) > 1:
  o, e = [], []
  for i in range(N):
    if i % 2==0:
      e.append(l[i])
    else:
      o.append(l[i])
  oc, oe = Counter(o).most_common(2), Counter(e).most_common(2)
  print(len(l) - oc[0][1] - oe[0][1] if oc[0][0] != oe[0][0] else len(l) - max(oc[0][1] + oe[1][1], oc[1][1] + oe[0][1]))

else:
  print(len(l) // 2)

Solution (Python):
import collections
n = int(input())
v = list(map(int,input().split()))
od = [0]
ev = [0]
for i in range(n):
    if i % 2 == 0:
        od.append(v[i])
    else:
        ev.append(v[i])
        
o1, o2 = collections.Counter(od).most_common(2)
e1, e2 = collections.Counter(ev).most_common(2)
if o1[0] == e1[0]:
    if o1[1] + e1[1] == n:
        print(n//2)
        exit()
    print(n - max(o1[1] + e2[1], o2[1] + e1[1]))
else:
    print(n - (o1[1] + e1[1]))

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
e=Counter(a[::2]);e[0]=0
o=Counter(a[1::2]);o[0]=0
e1,e2=e.most_common(2)
o1,o2=o.most_common(2)
if e1[0]!=o1[0]:
    print(n-(e1[1]+o1[1]))
else:
    print(n-max(e1[1]+o2[1],e2[1]+o1[1]))

Solution (Python):
from collections import*
n,*a=map(int,open(0).read().split())
odd =Counter([v for k,v in enumerate(a) if k%2==0]).most_common()
even=Counter([v for k,v in enumerate(a) if k%2==1]).most_common()


if len(odd)==len(even)==1:
    if odd[0][0]==even[0][0]:
        print(len(a)//2)
    else:
        print(0)
elif odd[0][0]!=even[0][0]:
    print(sum(t for(s,t)in odd[1:])+sum(t for(s,t)in even[1:]))
else:
    a=odd[0][1]+sum(t for(s,t)in odd[2:])+sum(t for(s,t)in even[1:])
    b=even[0][1]+sum(t for(s,t)in even[2:])+sum(t for(s,t)in odd[1:])
    print(min(a,b))

Solution (Python):
""" AtCoder """

import collections

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

aa = collections.Counter(a)
bb = collections.Counter(b)

ans = aa.most_common()[0][1] + bb.most_common()[0][1]

if aa.most_common()[0][0] == bb.most_common()[0][0]:
    if len(aa.most_common()) == 1:
        ans = aa.most_common()[0][1]
    elif len(bb.most_common()) == 1:
        ans = bb.most_common()[0][1]
    else:
        ans = max(aa.most_common()[1][1] + bb.most_common()[0][1], aa.most_common()[0][1] + bb.most_common()[1][1])

print(len(a) + len(b) - ans)

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

v_even = defaultdict(int)
v_odd = defaultdict(int)

for k in range(n//2):
  v_even[V[2*k]] += 1
  v_odd[V[2*k + 1]] += 1

even_max = 0
even_max2 = 0
for k, v in v_even.items():
  if v > even_max:
    even_max2 = even_max
    even_max = v
    even_num = k
  else:
    even_max2 = max(even_max2, v)

odd_max = 0
odd_max2 = 0
for k, v in v_odd.items():
  if v > odd_max:
    odd_max2 = odd_max
    odd_max = v
    odd_num = k
  else:
    odd_max2 = max(odd_max2, v)

if  even_num != odd_num:
  print(n - even_max - odd_max)
else:
  print(n - max(even_max + odd_max2, even_max2 + odd_max))

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
a=v[0::2]
b=v[1::2]
c=dict()
d=dict()

for i in a:
  if i in c:
    c[i]+=1
  else:
    c[i]=1
for j in b:
  if j in d:
    d[j]+=1
  else:
    d[j]=1

e=sorted([[w,v] for v,w in c.items()],reverse=True)
f=sorted([[w,v] for v,w in d.items()],reverse=True)

if len(set(a))==len(set(b))==1 and e[0][1]==f[0][1] and e[0][0]==f[0][0]:
  print(min(len(a),len(b)))
elif e[0][1]!=f[0][1]:
  print(n-e[0][0]-f[0][0])
elif e[0][0]>f[0][0]:
  print(n-e[0][0]-f[1][0])
elif e[0][0]<f[0][0]:
  print(n-e[1][0]-f[0][0])
elif e[0][0]==f[0][0] and e[0][1]==f[0][1]:
  if e[1][0]>f[1][0]:
    print(n-e[1][0]-f[0][0])
  else:
    print(n-e[0][0]-f[1][0])

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


def A():
    return


def B():
    return


def C():
    n = I()
    v = LI()
    d = [defaultdict(int) for i in range(2)]
    for i in range(n):
        d[i%2][v[i]] += 1
    if len(d[0].keys()) == len(d[1].keys()) == 1:
        if d[0].keys() == d[1].keys():
            ans = n//2
        else:
            d = [list(d[i].values()) for i in range(2)]
            ans = sum(d[0])-max(d[0])+sum(d[1])-max(d[1])
    else:
        d = [sorted(list(d[i].items()),key = lambda x:-x[1]) for i in range(2)]
        if d[0][0][0] != d[1][0][0]:
            ans = -d[0][0][1]-d[1][0][1]
            for i in range(len(d[0])):
                ans += d[0][i][1]
            for i in range(len(d[1])):
                ans += d[1][i][1]
        else:
            ans = -d[0][0][1]-d[1][1][1]
            for i in range(len(d[0])):
                ans += d[0][i][1]
            for i in range(len(d[1])):
                ans += d[1][i][1]
            ans2 = -d[0][1][1]-d[1][0][1]
            for i in range(len(d[0])):
                ans2 += d[0][i][1]
            for i in range(len(d[1])):
                ans2 += d[1][i][1]
            ans = min(ans,ans2)
    print(ans)

def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    C()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007


def A():
    return


def B():
    return


def C():
    n = II()
    v = LI()
    d1 = defaultdict(int)
    d0 = defaultdict(int)
    for num, a in enumerate(v):
        if num % 2:
            d1[a] += 1
        else:
            d0[a] += 1
    A = list(d0.items())
    A.sort(key = lambda x: x[1], reverse = True)
    A = A[:2]
    A.append((0,0))
    B = list(d1.items())
    B.sort(key = lambda x: x[1], reverse = True)
    B = B[:2]
    B.append((0, 0))
    a = n // 2
    b = (n + 1) // 2
    if A[0][0] == B[0][0]:
        ans = min(a - A[0][1] + b - B[1][1], a - A[1][1] + b - B[0][1])
        print(ans)
    else:
        
        A = A[0][1]
        B = B[0][1]
        print(a+b-A-B)
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    C()

Solution (Python):
from collections import Counter

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

if len(set(odd)) == len(set(even)) == 1 and set(odd) == set(even):
    print(n//2)
else:
    o = Counter(odd)
    e = Counter(even)
    mode_odd = o.most_common(2)
    mode_even = e.most_common(2)
    if mode_odd[0][0] != mode_even[0][0]:
        cnt = n - mode_odd[0][1] - mode_even[0][1]
    else:
        if mode_odd[0][1] == mode_even[0][1]:
            cnt = n - max(mode_odd[1][1], mode_even[1][1]) - mode_odd[0][1]
        elif mode_odd[0][1] > mode_even[0][1]:
            cnt = n - mode_odd[0][1] - mode_even[1][1]
        else:
            cnt = n - mode_even[0][1] - mode_odd[1][1]
    print(cnt)

Solution (Python):
def read():
    return raw_input()


def write(message):
    import sys
    print message
    sys.stdout.flush()


if __name__ == '__main__':
    n = int(read())
    v = map(int, read().split())
    from collections import Counter
    counts_odd = Counter(v[::2])
    counts_even = Counter(v[1::2])
    co = counts_odd.most_common(2) + [(0, 0)]
    ce = counts_even.most_common(2) + [(0, 0)]

    ok = None
    if co[0][0] == ce[0][0]:
        ok = max(co[0][1] + ce[1][1], co[1][1] + ce[0][1])
    else:
        ok = co[0][1] + ce[0][1]
    write(n - ok)

Solution (Python):
from collections import defaultdict
n = int(input())
A = [int(x) for x in input().split()]
even = A[0::2]
odd = A[1::2]
EC = defaultdict(int)
EC[0] = 0
OC = defaultdict(int)
OC[0] = 0
for e in even:
  EC[e] += 1
for o in odd:
  OC[o] += 1
E = sorted([[v, k] for k, v in EC.items()], reverse=True)
O = sorted([[v, k] for k, v in OC.items()], reverse=True)
if E[0][1] != O[0][1]:
  print(n - E[0][0] - O[0][0])
elif E[1][0] >= O[1][0]:
  print(n - E[1][0] - O[0][0])
else:
  print(n - E[0][0] - O[1][0])

Solution (Python):
from collections import Counter
n = int(input())
el = [int(i) for i in input().split()]
odd_l = Counter(el[::2])
even_l = Counter(el[1::2])
a1, b1 = odd_l.most_common(1)[0]
a2, b2 = even_l.most_common(1)[0]
if a1 != a2:
    ans = n - b1 - b2
else:
    if len(odd_l) > 1:
        b3 = odd_l.most_common(2)[1][1]
    else:
        b3 = 0
    if len(even_l) > 1:
        b4 = even_l.most_common(2)[1][1]
    else:
        b4 = 0
    ans = min(n - b1 - b4, n - b3 - b2)
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
element = [int(i) for i in input().split()]
ans = 0
odd_l = Counter(element[::2])
even_l = Counter(element[1::2])
a1,b1= odd_l.most_common(1)[0]
a2,b2 = even_l.most_common(1)[0]
if a1 != a2:
    ans = n - b1 - b2
else:
    if len(odd_l) > 1:
        b3 = odd_l.most_common(2)[1][1]
    else:
        b3=0
    if len(even_l) > 1:
        b4 = even_l.most_common(2)[1][1]
    else:
        b4 = 0
    ans = min(n-b1-b4,n-b3-b2)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
a = []
b = []
for i in range(n):
    if i % 2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])
 
a = Counter(a)
amc = a.most_common()
b = Counter(b)
bmc = b.most_common()
amc.append((0,0))
bmc.append((0,0))
rewrite = 0
 
if amc[0][0] == bmc[0][0]:
    rewrite = max(amc[0][1]+bmc[1][1],amc[1][1]+bmc[0][1])
else:
    rewrite = amc[0][1]+bmc[0][1]
print(n-rewrite)

Solution (Python):
from collections import Counter

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


Counter_evens = Counter(vlist[::2])
Counter_odds = Counter(vlist[1::2])



top2_even = Counter_evens.most_common(2)  

E_most_common = top2_even[0][0]
Emnum = top2_even[0][1]

if len(top2_even) == 2:
    E_2nd_common = top2_even[1][0]
    E2num = top2_even[1][1]
else:
    E_2nd_common = 'foo'
    E2num = 0


top2_odd = Counter_odds.most_common(2)

O_most_common = top2_odd[0][0]
Omnum = top2_odd[0][1]

if len(top2_odd) == 2:
    O_2nd_common = top2_odd[1][0]
    O2num = top2_odd[1][1]
else:
    O_2nd_common = 'foo'
    O2num = 0


if E_most_common == O_most_common:  
    
    

    
    x = len(vlist[::2]) - Emnum + len(vlist[1::2]) - O2num
    
    y = len(vlist[::2]) - E2num + len(vlist[1::2]) - Omnum

    print(min(x, y))
else:
    
    
    print(len(vlist[::2]) - Emnum + len(vlist[1::2]) - Omnum)