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):
MAX_V = 10 ** 5


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

    odd, even = [0] * (MAX_V+1), [0] * (MAX_V+1)
    for i in range(n):
        if i % 2:
            odd[v[i]] += 1
        else:
            even[v[i]] += 1

    no, ne = [i for i in range(MAX_V+1)], [i for i in range(MAX_V+1)]
    no.sort(key=lambda val: odd[val], reverse=True)
    ne.sort(key=lambda val: even[val], reverse=True)

    if no[0] == ne[0]:
        print(min(n-odd[no[0]]-even[ne[1]], n-even[ne[0]]-odd[no[1]]))
    else:
        print(n-odd[no[0]]-even[ne[0]])


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

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

evens = Counter(v[::2])
odds = Counter(v[1::2])

evens[0] = 0  
odds[0] = 0

keep = 0
for even in evens.most_common(2):
    for odd in odds.most_common(2):
        if even[0] != odd[0]:
            keep = max(keep, even[1] + odd[1])

print(n - keep)

Solution (Python):

from collections import Counter

n=int(raw_input())
v=map(int,raw_input().split())
a,b=[],[]
for i in xrange(0,n,2):
 a.append(v[i])
 b.append(v[i+1])
acnt=Counter(a)
bcnt=Counter(b)
x=acnt.most_common()[0][0]
y=bcnt.most_common()[0][0]
if x!=y:
 res=n-acnt.most_common()[0][1]-bcnt.most_common()[0][1]
else:
 if acnt.most_common()[0][1]==n/2:
  res=n-bcnt.most_common()[0][1]
 elif bcnt.most_common()[0][1]==n/2:
  res=n-acnt.most_common()[0][1]
 else:
  res=min(n-acnt.most_common()[0][1]-bcnt.most_common()[1][1],n-bcnt.most_common()[0][1]-acnt.most_common()[1][1])
print res

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

cnt_arr = [dict() for _ in range(2)]

for i in range(n):
    cnt_arr[i % 2][v[i]] = cnt_arr[i % 2].get(v[i], 0) + 1

v_even = sorted(list(cnt_arr[0].items()), key=lambda x: x[1], reverse=True)[:2]  
v_odd = sorted(list(cnt_arr[1].items()), key=lambda x: x[1], reverse=True)[:2]  

keep = 0
flg = False
for even in v_even:  
    for odd in v_odd:  
        if even[0] != odd[0]:
            flg = True
            keep = max(keep, even[1] + odd[1])

ans = n - keep if flg else n // 2
print(ans)

Solution (Python):
import numpy as np

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



if np.unique(v).size == 1:
    print(int(n/2))
else:
    
    vo = v[::2]
    ve = v[1::2]
    
    vof = np.bincount(vo).argmax()
    vef = np.bincount(ve).argmax()

    if vof == vef:
        if sum(vo == vof) > sum(ve == vef):
            vef = np.bincount(ve[ve!=vef]).argmax()
        elif sum(ve == vef) > sum(vo == vof):
            vof = np.bincount(vo[vo!=vof]).argmax()
        else :
            vof2 = np.bincount(vo[vo!=vof]).argmax()
            vef2 = np.bincount(ve[ve!=vef]).argmax()
            if (sum(vo == vof) + sum(ve == vef2)) > (sum(ve == vef) + sum(vo == vof2)):
                vef = vef2
            else:
                vof = vof2
    
    
    vonf = sum(vo != vof)
    venf = sum(ve != vef)
    
    print(vonf+venf)

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

from collections import Counter
import operator
def f():
    a = Counter(A[::2]).most_common(2)
    b = Counter(A[1::2]).most_common(2)
    ac, bc = a[0][1], b[0][1]
    ret = n - (ac + bc)
    if a[0][0] == b[0][0]:
        bc_2 = b[1][1] if len(b) != 1 else 0
        ac_2 = a[1][1] if len(a) != 1 else 0
        ret = n - max(ac + bc_2, ac_2 + bc)
    return ret
print(f())

Solution (Python):


from collections import Counter


n = int(input())
v = list(map(int, input().split()))
odd = Counter(v[0::2]).most_common(2) + [(0, 0)]
even = Counter(v[1::2]).most_common(2) + [(0, 0)]

n_half = int(n / 2)

if (len(odd) == 1 and len(even) == 1) and odd[0][0] == even[0][0]:
    ans = n_half
elif odd[0][0] == even[0][0]:
    ans = min(n_half - odd[0][1] + n_half - even[1][1],\
            n_half - odd[1][1] + n_half - even[0][1])
else:
    ans = n_half - odd[0][1] + n_half - even[0][1]

print(ans)

Solution (Python):
import sys

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

odddict = {}
evendict = {}
for i,vi in enumerate(v):
    if i % 2 == 0: 
        if vi in evendict.keys():
            evendict[vi] += 1
        else:
            evendict[vi] = 1
    else:
        if vi in odddict.keys():
            odddict[vi] += 1
        else:
            odddict[vi] = 1
            
odd = sorted(odddict.items(), key=lambda x:x[1], reverse=True)
even = sorted(evendict.items(), key=lambda x:x[1], reverse=True)

if odd == even and len(odd)==1:
    print(n // 2)
    sys.exit()

i, j = 0,0
while odd[i] == even[j]:
    o_dif = odd[i+1][1] - odd[i][1]
    e_dif = even[j+1][1] - even[j][1]
    if o_dif >= e_dif:
        i += 1
    else:
        j += 1
  
print(n - odd[i][1] - even[j][1])

Solution (Python):
import itertools

n = int(input())
v = [int(w) for w in input().split()]
assert len(v) == n

def elem_count(ls):
    '''Return the list of (num of elem, elem).'''
    ls.sort()
    ls = itertools.groupby(ls)
    cs = [(len(list(s)), e) for e, s in ls]
    cs.sort(reverse=True)
    return cs

e = [v[i] for i in range(0, n, 2)]
o = [v[i] for i in range(1, n, 2)]

e = elem_count(e)
o = elem_count(o)

candidate = []
if e[0][1] != o[0][1]:
    candidate.append(e[0][0] + o[0][0])
if len(e) > 1:
    candidate.append(e[1][0] + o[0][0])
if len(o) > 1:
    candidate.append(e[0][0] + o[1][0])
if len(e) == len(o) == 1:
    candidate.append(e[0][0])

print(n - max(candidate))

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

a = []
b = []

a_dic = {}
b_dic = {}

for i in range(n):
    if i % 2 == 0:
        if v[i] in a_dic.keys():
            a_dic[v[i]] += 1
        else:
            a_dic[v[i]] = 1
    else:
        if v[i] in b_dic.keys():
            b_dic[v[i]] += 1
        else:
            b_dic[v[i]] = 1

max_a = 0
max_b = 0

max_a_ind = 0
max_b_ind = 0
 
for i, val in a_dic.items():
    if val > max_a:
        max_a = val
        max_a_ind = i

for i, val in b_dic.items():
    if val > max_b:
        max_b = val
        max_b_ind = i

n_2 = int(n / 2)

ans = (n_2 - max_a) + (n_2 - max_b)

if (len(a_dic) == 1 and len(b_dic) == 1) and a_dic.keys() ==  b_dic.keys():
    print(n_2)

elif max_a_ind == max_b_ind:
    list_a = sorted(list(a_dic.values()), reverse=True)
    list_b = sorted(list(b_dic.values()), reverse=True)
    if list_a[0] > list_b[0]:
        ans = n_2 - list_a[0] + n_2 - list_b[1]
    elif list_a[0] < list_b[0]:
        ans = n_2 - list_a[1] + n_2 - list_b[0]
    else:
        ans = n_2 - list_a[0] + n_2 - max(list_a[1], list_b[1])
    print(ans)

else:
    print(ans)

Solution (Python):
from collections import Counter

n = int(input())
v = [int(i) for i in input().split()]
v1 = Counter(v[::2])
v2 = Counter(v[1::2])
v1mc = v1.most_common()
v2mc = v2.most_common()
if(v1mc[0][0] == v2mc[0][0]):
    if(len(v1mc) == 1 and len(v2mc) == 1):
        print(int(n/2))
    elif(len(v1mc) == 1):
        print(n - (v1mc[0][1]+v2mc[1][1]))
    elif(len(v2mc) == 1):
        print(n - (v2mc[0][1]+v1mc[1][1]))
    else:
        print(n - max(v1mc[0][1]+v2mc[1][1], v2mc[0][1]+v1mc[1][1]))
else:
    print(n - (v1mc[0][1]+v2mc[0][1]))

Solution (Python):
import sys
from collections import Counter
Input = sys.stdin.readline

n = int(Input())
v = list(map(int, Input().split()))
mi = float("inf")
count1 = 0
count2 = 0

v1 = v[0::2]
v1_count = Counter(v1)
v1_count = v1_count.most_common()
count1 += len(v1) - v1_count[0][1]

v2 = v[1::2]
v2_count = Counter(v2)
v2_count = v2_count.most_common()
count2 += len(v2) - v2_count[0][1]

if v1_count[0][0] != v2_count[0][0]:
    mi = count1 + count2
else:
    lv2 = len(v2)
    for k, i in v2_count[1:]:
        result = count1 + lv2 - i
        if mi > result:
            mi = result
    else:
        if mi > count1 + lv2:
            mi = count1 + lv2

    lv1 = len(v1)
    for k, i in v1_count[1:]:
        result = count2 + lv1 - i
        if mi > result:
            mi = result
    else:
        if mi > count2 + lv1:
            mi = count2 + lv1

print(mi)

Solution (Python):
n = int(input())
L = list(map(int,input().split()))
A = []
B = []
Q = [0,0]
R = [0,0]
S = [0,0]
T = [0,0]
J = 1
K = 1
for i in range(n):
  if (i%2 == 0):
    A.append(L[i])
  else:
    B.append(L[i])
A.sort()
B.sort()
A.append(-1)
B.append(-1)
for j in range(1,len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J > Q[0]):
      Q[1] = Q[0]
      del Q[0]
      Q.insert(0,J)
      R[1] = R[0]
      del R[0]
      R.insert(0,A[j-1])
      j += J
      J = 1
    elif (Q[0] >= J > Q[1]):
      del Q[1]
      Q.append(J)
      del R[1]
      R.append(A[j-1])
      j += J
      J = 1
    else:
      j += J
      J = 1
for k in range(1,len(B)):
  if (B[k-1] == B[k]):
    K += 1
  else:
    if (K > S[0]):
      S[1] = S[0]
      del S[0]
      S.insert(0,K)
      T[1] = T[0]
      del T[0]
      T.insert(0,B[k-1])
      k += K
      K = 1
    elif (S[0] >= K > S[1]):
      del S[1]
      S.append(K)
      del T[1]
      T.append(B[k-1])
      k += K
      K = 1
    else:
      k += K
      K = 1
if (R[0] != T[0]):
  print(n-Q[0]-S[0])
else:
  print(n-max(S[0]+Q[1],S[1]+Q[0]))

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
e_counter = Counter(e)
o_counter = Counter(o)
e_most = e_counter.most_common()
o_most = o_counter.most_common()
E1 = e_most[0][0]
E2 = E1
if len(e_most) > 1:
    E2 = e_most[1][0]
O1 = o_most[0][0]
O2 = O1
if len(o_most) > 1:
    O2 = o_most[1][0]
e_cnt = n // 2 - e.count(E1)
o_cnt = n // 2 - o.count(O1)
if e_cnt == 0 and o_cnt == 0:
    if e[0] == o[0]:
        print(n // 2)
    else:
        print(0)
else:
    if E1 != O1:
        print(e_cnt + o_cnt)
    else:
        if E1 == O2:
            e_cnt = n // 2 - e.count(E2)
            print(e_cnt + o_cnt)
        elif E2 == O1:
            o_cnt = n // 2 - o.count(O2)
            print(e_cnt + o_cnt)
        else:
            cnt1 = n // 2 - e.count(E2) + o_cnt
            cnt2 = e_cnt + n // 2 - o.count(O2)
            print(min(cnt1, cnt2))

Solution (Python):

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



odd = []
even = []

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

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





if c_odd.most_common()[0][0] != c_even.most_common()[0][0] :
    
    print(N - c_odd.most_common()[0][1] - c_even.most_common()[0][1])
    exit()



if c_odd.most_common()[0][0] == c_even.most_common()[0][0] :

    
    if len(c_odd.most_common()) == 1 and len(c_even.most_common()) == 1:
        print(N//2)

    
    elif len(c_odd.most_common()) == 1:
        print(N//2 - c_even.most_common()[1][1])
    
    elif len(c_even.most_common()) == 1:
        print(N//2 - c_odd.most_common()[1][1])
    
    else:
        ans = N - max(c_odd.most_common()[0][1]+c_even.most_common()[1][1], c_odd.most_common()[1][1]+c_even.most_common()[0][1] )
        print(ans)

'''
        
        temp_odd_retire = N//2 - c_odd.most_common()[1][1] 
        temp_even_retire = N//2 - c_even.most_common()[1][1] 
        

        
        if temp_odd_retire < temp_even_retire:
            print(temp_odd_retire + N//2 - c_even.most_common()[0][1])
        
        else:
            print(temp_even_retire + N//2 - c_odd.most_common()[0][1])
        exit()
'''

Solution (Python):

import sys

def get_sorted_num(v):
	num_v = {}
	for v_ in v:
		if v_ not in num_v:
			num_v[v_]  = 1
		else:
			num_v[v_] += 1
	sorted_num_v = sorted(num_v.items(), key=lambda x:x[1])
	return sorted_num_v

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

if len(get_sorted_num(v)) == 1:
	print n / 2
	sys.exit()

sorted_num_odd = get_sorted_num(v[0::2])
sorted_num_even = get_sorted_num(v[1::2])

odd_1st_k, odd_1st_v = sorted_num_odd[-1]
even_1st_k, even_1st_v = sorted_num_even[-1]

	
if odd_1st_k == even_1st_k:
	if len(sorted_num_odd) == 1:
		print len(v[0::2]) - odd_1st_v + len(v[1::2]) - even_2nd_v
	elif len(sorted_num_even) == 1:
		print len(v[0::2]) - odd_2nd_v + len(v[1::2]) - even_1st_v
	else:
		odd_2nd_k, odd_2nd_v = sorted_num_odd[-2]
		even_2nd_k, even_2nd_v = sorted_num_even[-2]
		if odd_2nd_v > even_2nd_v:
			print len(v[0::2]) - odd_2nd_v + len(v[1::2]) - even_1st_v
		else:
			print len(v[0::2]) - odd_1st_v + len(v[1::2]) - even_2nd_v
else:
	print len(v[0::2]) - odd_1st_v + len(v[1::2]) - even_1st_v

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

eo = [{}, {}]

for i in range(len(V_list)):
    v = V_list[i]

    tmp = (i + 1) % 2
    eo[tmp][v] = eo[tmp].get(v, 0) + 1


eomax = [max(eo[i].values()) for i in range(2)]
maxkv = [[(k, v) for k, v in eo[i].items() if v == eomax[i]] for i in range(2)]

for ke, ve in maxkv[0]:
    flag = False
    for ko, vo in maxkv[1]:
        if(ke != ko):
            ans = n - ve - vo
            flag = True
            break
    if(flag is True):
        break
else:
    sec = [0, 0]
    for i in range(2):
        for v in eo[i].values():
            if(v >= eomax[i]):
                continue
            sec[i] = max(sec[i], v)
    ans = min(n - eomax[0] - sec[1], n - eomax[1] - sec[0])
    
print(ans)

Solution (Python):
from collections import Counter

def fParse(iN,aV):
    oV0 = Counter(aV[0::2]).most_common(2)
    oV1 = Counter(aV[1::2]).most_common(2)
    oV0 += [(0,0)]
    oV1 += [(0,0)]

    if oV0[0][0] != oV1[0][0] :
        return iN - oV0[0][1] - oV1[0][1]
    else:
        return iN - max(oV0[0][1],oV1[0][1]) - max(oV0[1][1],oV1[1][1])

if __name__ == "__main__":
    iN = int(input())
    aV = [int(_) for _ in input().split()]
    print(fParse(iN,aV))

Solution (Python):
from collections import Counter

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

oV0 = Counter(aV[0::2]).most_common(2)
oV1 = Counter(aV[1::2]).most_common(2)
oV0 += [(0,0)]
oV1 += [(0,0)]

if oV0[0][0] != oV1[0][0] :
    print(iN - oV0[0][1] - oV1[0][1])
else:
    print(iN - max(oV0[0][1],oV1[0][1]) - max(oV0[1][1],oV1[1][1]))

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

Solution (Python):
from collections import Counter

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

oV0 = Counter(aV[0::2]).most_common()
oV1 = Counter(aV[1::2]).most_common()
oV0 += [(0,0)]
oV1 += [(0,0)]

if oV0[0][0] != oV1[0][0] :
    print(iN - oV0[0][1] - oV1[0][1])
else:
    print(iN - max(oV0[0][1],oV1[0][1]) - max(oV0[1][1],oV1[1][1]))

Solution (Python):
from collections import Counter

N = int(input())

index = 0
even_numbers = []
odd_numbers = []

for i in input().split():
    if index % 2 == 0:
        even_numbers.append(int(i))
    else:
        odd_numbers.append(int(i))
    index += 1

even = Counter(even_numbers).most_common(2)
odd = Counter(odd_numbers).most_common(2)

if even[0][0] == odd[0][0]:
    if len(even) == 1:
        print(N//2)
    else:
        print(N - even[0][1] - max(even[1][1], odd[1][1]))
else:
    print(N - even[0][1] - odd[0][1])

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
a = [0 for i in range(10**6)]
b = [0 for i in range(10**6)]
a_i = 0
b_i = 0
i = 0
for e in l:
    if i%2 == 0:
        a[e]+=1
        if(a[a_i]<=a[e]):
            a_i=e
    else:
        b[e]+=1
        if(b[b_i]<=b[e]):
            b_i=e
    i+=1
a.sort()
a.reverse()
b.sort()
b.reverse()
if a_i != b_i:
    print(n-a[0]-b[0])
else:
    print(n-max(a[0]+b[1],a[1]+b[0]))

Solution (Python):



import collections

n = int(input())
v = [int(i) for i in input().split()]
INF = 10 ** 6

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

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

c1 = collections.Counter(v1)
c1[INF] = 0
c2 = collections.Counter(v2)
c2[INF] = 0

sc1 = sorted(c1.items(), key=lambda x: x[1], reverse=True)
a1, b1 = sc1[0][0], sc1[1][0]
sc2 = sorted(c2.items(), key=lambda x: x[1], reverse=True)
a2, b2 = sc2[0][0], sc2[1][0]

total = sum(c1.values()) + sum(c2.values())
if a1 == a2:
    ans = min(total - c1[a1] - c2[b2], total - c1[b1] - c2[a2])
else:
    ans = total - c1[a1] - c2[a2]

print(ans)

Solution (Python):
from collections import Counter


def solve(V):
    n = len(V)
    odd_max = Counter(V[1::2]).most_common(2)
    even_max = Counter(V[::2]).most_common(2)

    if odd_max[0][0] != even_max[0][0]:
        return n - odd_max[0][1] - even_max[0][1]
    elif  len(odd_max) == 1 and len(even_max) == 1:
        return n // 2
    elif len(odd_max) != 1 and len(even_max) == 1:
        return n - odd_max[1][1] - even_max[0][1]
    elif len(odd_max) == 1 and len(even_max) != 1:
        return n - odd_max[0][1] - even_max[1][1]
    else:
        return n - max(even_max[0][1] + odd_max[1][1],
                       even_max[1][1] + odd_max[0][1])

if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))

Solution (Python):
from collections import Counter
n = int(input())
v = [int(_) for _ in input().split()]
v1 = []
v2 = []
for i in range(n):
    if i % 2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])
v_count = Counter(v)
v1_count = Counter(v1)
v2_count = Counter(v2)


v1_comm = v1_count.most_common(1)
v2_comm = v2_count.most_common(1)
sols = []


if len(v_count) == 1:
    print(n//2)
else:
    key1 = v1_comm[0][1]
    
    
    if v1_comm[0][0] == v2_comm[0][0]:
        
        v2_comm = v2_count.most_common(2)
        key2 = v2_comm[1][1]
    else:
        key2 = v2_comm[0][1]
    sols.append(n-key1-key2)
    key1 = v2_comm[0][1]
    if v1_comm[0][0] == v2_comm[0][0]:
        v1_comm = v1_count.most_common(2)
        key2 = v1_comm[1][1]
    else:
        key2 = v1_comm[0][1]
    sols.append(n-key1-key2)
    print(min(sols))

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

from collections import Counter
import operator
def f():
    a = Counter(A[::2]).most_common(2)
    b = Counter(A[1::2]).most_common(2)
    ac, bc = a[0][1], b[0][1]
    ret = n - (ac + bc)
    if a[0][0] == b[0][0]:
        bc_2 = b[1][1] if len(b) != 1 else 0
        ac_2 = a[1][1] if len(a) != 1 else 0
        ret = n - max(ac + bc_2, ac_2 + bc)
    return ret
print(f())

Solution (Python):
from collections import Counter

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

"""
まずは偶数番目、奇数番目をカウントする
次に数を調べる
2個目から先を足す
"""



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



if odd[0][0] != even[0][0]:
	answer = n - odd[0][1] - even[0][1]

else:
	if len(odd) == 1 and len(even) >1:
		answer = n - even[0][1]
	elif len(even) == 1 and len(odd) >1:
		answer = n - odd[0][1]
	elif len(even) == 1 and len(odd) ==1:
		answer = n - even[0][1]
	else:		
		if odd[0][1] > even[0][1]:
			answer = n - odd[0][1] - even[1][1]
		elif odd[0][1] < even[0][1]:
			answer = n - even[0][1] - odd[1][1]
		else:
			if odd[1][1] > even[1][1]:
				answer = n - even[0][1] - odd[1][1]
			elif odd[1][1] < even[1][1]:
				answer = n - odd[0][1] - even[1][1]
			else:
				answer = n - odd[0][1] - even[1][1]
		
print(answer)

"""
半分waになってしまった...なにがいけなかったんだろう
"""

Solution (Python):
import collections

n = int(input())
v = list(map(int,input().split(" ")))
e,o = [],[]
e = v[::2]
o = v[1::2]

ec = collections.Counter(e).most_common(2)
oc = collections.Counter(o).most_common(2)

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

Solution (Python):

from collections import Counter
from operator import itemgetter
def solve():
    input()
    V = list(map(int, input().split()))
    l = sorted(list(Counter(V[::2]).items())+[(0,0)], key=itemgetter(1), reverse=True)
    u = sorted(list(Counter(V[1::2]).items())+[(0,0)], key=itemgetter(1), reverse=True)
    res = sum(map(itemgetter(1), l+u)) - (max(l[0][1]+u[1][1], l[1][1]+u[0][1]) if l[0][0]==u[0][0] else (l[0][1]+u[0][1]))
    return str(res)

if __name__ == '__main__':
    print(solve())

Solution (Python):
from collections import Counter


def solve(V):
    n = len(V)
    ac = Counter(V[::2]).most_common(2)
    bc = Counter(V[1::2]).most_common(2)

    if ac[0][0] != bc[0][0]:
        return n - ac[0][1] - bc[0][1]
    else:
        if len(ac) == 1 and len(bc) == 1:
            return n // 2
        elif len(ac) != 1 and len(bc) == 1:
            return n - ac[1][1] - bc[0][1]
        elif len(ac) == 1 and len(bc) != 1:
            return n - ac[0][1] - bc[1][1]
        else:
            return n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int,input().split()))
oddA = A[0::2]
evenA = A[1::2]

oc = Counter(oddA)
omode = oc.most_common()
ec = Counter(evenA)
emode = ec.most_common()
if omode[0][0] != emode[0][0]:
    print(n-omode[0][1]-emode[0][1])
else:
    if len(omode) == 1:
        omode.append((0, 0))
    if len(emode) == 1:
        emode.append((0, 0))
    a = n-omode[0][1]-emode[1][1]
    b = n-omode[1][1]-omode[0][1]
    print(min(a, b))

Solution (Python):
from collections import Counter


def solve(V):
    n = len(V)
    ac = Counter(V[::2]).most_common(2)
    bc = Counter(V[1::2]).most_common(2)

    if ac[0][0] != bc[0][0]:
        return n - ac[0][1] - bc[0][1]
    else:
        if len(bc) == 1 or len(ac) == 1:
            return n // 2
        else:
            return n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))

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

Solution (Python):
def c_zigzag(N, V):
    from collections import Counter
    count_seq_even = Counter(V[::2])  
    count_seq_odd = Counter(V[1::2])  

    count_seq_even_s = sorted(count_seq_even.items(), key=lambda x: x[1], reverse=True)
    count_seq_odd_s = sorted(count_seq_odd.items(), key=lambda x: x[1], reverse=True)

    
    
    
    
    seq_even_select = [count_seq_even_s[k][0] for k in range(min(2, len(count_seq_even)))]
    seq_odd_select = [count_seq_odd_s[k][0] for k in range(min(2, len(count_seq_odd)))]

    ans = float('inf')
    
    
    
    if len(seq_even_select) == 1 and len(seq_odd_select) == 1 and seq_even_select[0] == seq_odd_select[0]:
        return N // 2

    for e in seq_even_select:
        for o in seq_odd_select:
            if e == o:
                continue
            ans = min(ans, N - count_seq_even[e] - count_seq_odd[o])
    return ans

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

Solution (Python):
import math

class xx:
    val = 0
    num = 0

    def __init__(self,v,n):
        self.val,self.num = v,n

while True:
    try:
        n = eval(input().strip())

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

        one = {}
        two = {}
        for i in range(0,n,2):
            if arr[i] in one.keys():
                one[arr[i]] = one[arr[i]] + 1
            else:
                one[arr[i]] = 1

        for i in range(1,n,2):
            if arr[i] in two.keys():
                two[arr[i]] = two[arr[i]] + 1
            else:
                two[arr[i]] = 1

        
        
        one = sorted(one.items(),key=lambda x:x[1],reverse=True)
        two = sorted(two.items(), key=lambda x: x[1], reverse=True)
        
        

        if one[0][0] != two[0][0]:
            sum = n // 2 - one[0][1]
            sum += n // 2 - two[0][1]
            print(sum)
        elif one[0][0] == two[0][0] and one[0][1] == two[0][1] and one[0][1] == n // 2:
            print(n // 2)
        elif one[0][0] == two[0][0]:
            len1 = len(one)
            len2 = len(two)

            if len1 >= 2 and len2 >= 2:
                sum = n // 2 - one[0][1]
                sum += n // 2 - two[1][1]

                sum2 = n // 2 - one[1][1]
                sum2 += n // 2 - two[0][1]

                print(min(sum,sum2))
            elif len1 == 1 and len2 >= 2:
                sum = n // 2 - one[0][1]
                sum += n // 2 - two[1][1]
                print(sum)
            elif len1 >= 2 and len2 == 1:
                sum = n // 2 - one[1][1]
                sum += n // 2 - two[0][1]
                print(sum)
    except:
        break

Solution (Python):
from collections import Counter


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

"""数字が1種類の場合は半分を書き換える必要が確定"""
if len(set(v)) == 1:
    print(len(v) // 2)
    exit()

"""一番多く出現する2つの数字を探す"""
max_hit = 0
for odd_val, odd_hit in Counter(v[1::2]).most_common(2):
    for even_val, even_hit in Counter(v[::2]).most_common(2):
        if odd_val == even_val:
            continue  
        if odd_hit + even_hit > max_hit:
            max_hit = odd_hit + even_hit

"""一致していない要素が書き換え必要回数"""
print(len(v) - max_hit)
exit()

Solution (Python):
from collections import Counter as c
n=int(input())
*l,=map(int,input().split())

ca=sorted(c(l[1::2]).items(),key=lambda x:x[1])[::-1]
cb=sorted(c(l[0::2]).items(),key=lambda x:x[1])[::-1]

v1=sum([i[1] for i in ca])
v2=sum([i[1] for i in cb])

a1=ca[0][0]
for i in cb:
  if a1==i[0]:continue
  b=i[1]
  break
else:
  b=0
ans1=v2-b+v1-ca[0][1]

a1=cb[0][0]
for i in ca:
  if a1==i[0]:continue
  b=i[1]
  break
else:
  b=0
ans2=v1-b+v2-cb[0][1]

print(min(ans1,ans2))

Solution (Python):
import collections
 
n = int(input())
v = [int(i) for i in input().split()]
 
v1 = [v[i] for i in range(0,n,2)]
v2 = [v[i] for i in range(1,n,2)]
 
count1 = collections.Counter(v1).most_common(2)
count2 = collections.Counter(v2).most_common(2)

if count1[0][0] != count2[0][0]:
    res = len(v1) - count1[0][1] + len(v2) - count2[0][1]
    print(res)
else:
    if len(count1) == 1:
        print(len(v1))
    else:
        res1 = len(v1) - count1[0][1] + len(v2) - count2[1][1]
        res2 = len(v1) - count1[1][1] + len(v2) - count2[0][1]
        print(min(res1,res2))

Solution (Python):
import operator

n=int(input().strip())
lst=input().split(' ')
map(int, lst)

d1 = {}
d2 = {}

for i in range(len(lst)):
    if i % 2 == 0:
        if lst[i] in d1:
            d1[lst[i]] += 1
        else:
            d1[lst[i]] = 1
    else:
        if lst[i] in d2:
            d2[lst[i]] += 1
        else:
            d2[lst[i]] = 1

sd1 = sorted(d1.values(), reverse=True)
sd2 = sorted(d2.values(), reverse=True)
key1 = max(d1.items(), key=operator.itemgetter(1))[0]
key2 = max(d2.items(), key=operator.itemgetter(1))[0]

if(key1 == key2):

    v11 = sd1[0]
    if(len(d1) == 1):
        v12 = 0
    else:
        v12 = sd1[1]

    v21 = sd2[0]
    if(len(d2) == 1):
        v22 = 0
    else:
        v22 = sd2[1]

    print(min(n-v11-v22, n-v12-v21))

else:
    print(n-sd1[0]-sd2[0])

Solution (Python):
from collections import Counter

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

"""数字が1種類の場合は半分を書き換える必要が確定"""
if len(set(v)) == 1:
    print(len(v) // 2)
    exit()

"""要素出現数を集計"""
odd_count = Counter(v[1::2])
even_count = Counter(v[::2])

"""一番多く出現する2つの数字を探す"""
max_hit = 0
odd = None
even = None
for odd_val, odd_hit in odd_count.most_common(2):
    for even_val, even_hit in even_count.most_common(2):
        if odd_val == even_val:
            continue  
        if odd_hit + even_hit > max_hit:
            max_hit = odd_hit + even_hit
            odd = odd_val
            even = even_val

"""一致していない要素が書き換え必要回数"""
print(len(v) - max_hit)

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

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

Solution (Python):

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

D1 = {}
D2 = {}

for i in range(N):
    if i % 2 == 0 :
        if V[i] in D1 :
            D1[V[i]] += 1
        else:
            D1[V[i]] = 1
    else:
        if V[i] in D2 :
            D2[V[i]] += 1
        else:
            D2[V[i]] = 1

maxD1 = max(D1.values())
maxD2 = max(D2.values())

if max(D1, key=D1.get) != max(D2, key=D2.get):
    print(N-maxD1-maxD2)
else:
    D1[max(D1, key=D1.get)] = 0
    D2[max(D2, key=D2.get)] = 0
    maxD12 = max(D1.values())
    maxD22 = max(D2.values())
    if maxD12 >= maxD22 :
        if len(D1) > 1 :
            print(N-maxD12-maxD2)
        else :
            print(N-maxD2)
    else :
        if len(D2) > 1 :
            print(N-maxD1-maxD22)
        else :
            print(N-maxD2)

Solution (Python):
from collections import Counter

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

"""数字が1種類の場合は半分を書き換える必要が確定"""
if len(set(v)) == 1:
    print(len(v) // 2)
    exit()

"""要素出現数を集計"""
odd_count = Counter(v[1::2])
even_count = Counter(v[::2])

"""一番多く出現する2つの数字を探す"""
max_hit = 0
odd = None
even = None
for odd_val, odd_hit in odd_count.most_common(5):
    
    
    for even_val, even_hit in even_count.most_common(5):
        
        
        if odd_val == even_val:
            continue  
        if odd_hit + even_hit > max_hit:
            max_hit = odd_hit + even_hit
            odd = odd_val
            even = even_val

"""一致していない要素が書き換え必要回数"""
print(len(v) - max_hit)

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

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