Problem:
 Score : 300 points    Problem Statement A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:   For each i = 1,2,..., n-2 , a_i = a_{i+2} .  Exactly two different numbers appear in the sequence.   You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.      Constraints  2 \leq n \leq 10^5  n is even.  1 \leq v_i \leq 10^5  v_i is an integer.         Input Input is given from Standard Input in the following format:  n  v_1  v_2  ...  v_n       Output Print the minimum number of elements that needs to be replaced.        Sample Input 1 4
3 1 3 2      Sample Output 1 1  The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1 .       Sample Input 2 6
105 119 105 119 105 119      Sample Output 2 0  The sequence 105,119,105,119,105,119 is /\/\/\/.       Sample Input 3 4
1 1 1 1      Sample Output 3 2  The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.

Solution (Python):
from collections import Counter
n = int(input())
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 and len(emode) == 1:
        print(n//2)
    elif len(omode) == 1 and len(emode) != 1:
        print(n//2-emode[1][1])
    elif len(emode) == 1 and len(omode) != 1:
        print(n//2-omode[1][1])
    else:
        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
n = int(input())
v = list(map(int, input().split()))
ve = v[0::2]
vo = v[1::2]
edict = sorted(Counter(ve).items(), key=lambda x: x[1], reverse=True)[:2]
odict = sorted(Counter(vo).items(), key=lambda x: x[1], reverse=True)[:2]
ans = 10 ** 6
if len(edict) == 1 and len(odict) == 1 and edict[0][0] == odict[0][0]:
    ans = n // 2
else:
    for e in edict:
        for o in odict:
            if e[0] == o[0]:
                continue
            ans = min(ans, len(ve) - e[1] + len(vo) - o[1])
print(ans)

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

l=[v[i] for i in range(n) if i%2==0]
r=[v[i] for i in range(n) if i%2]

l.sort()
r.sort()

count=1
countl1=0
countl2=0

for i in range(1,len(l)):
    if l[i]==l[i-1]: count+=1
    else:
        if count>=countl1:
            countl1,countl2=count,countl1
            charl=l[i-1]
        elif count>countl2:
            countl2=count
        count=1
        
if count>=countl1:
    countl1,countl2=count,countl1
    charl=l[-1]
elif count>countl2:
    countl2=count 


count=1
countr1=0
countr2=0

for i in range(1,len(r)):
    if r[i]==r[i-1]: count+=1
    else:
        if count>=countr1:
            countr1,countr2=count,countr1
            charr=r[i-1]
        elif count>countr2:
            countr2=count
        count=1

if count>=countr1:
    countr1,countr2=count,countr1
    charr=r[-1]
elif count>countr2:
    countr2=count 
        
if charl==charr:
    print(n-max(countl1+countr2,countl2+countr1))
else: print(n-countl1-countr1)

Solution (Python):
N = int(input())
v = list(map(int, input().split()))
from collections import Counter
ai = v[::2]
bi = v[1::2]
an = Counter(ai).most_common(2)
bn = Counter(bi).most_common(2)

if(an[0][0] == bn[0][0]):
    if(len(an)==1):
        print(int(N/2))
    else:
        print(N - an[0][1] - max(an[1][1], bn[1][1]))
else:
    print(N - an[0][1] - bn[0][1])

Solution (Python):
n = int(input())

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

v_odd = {}
v_even = {}

for i in range(n):
    if i % 2 == 0:
        v = vs[i]
        if v in v_even:
            v_even[v] += 1
        else:
            v_even[v] = 1
    else:
        v = vs[i]
        if v in v_odd:
            v_odd[v] += 1
        else:
            v_odd[v] = 1

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

if odd_sort[0][0] == even_sort[0][0]:
    if len(odd_sort) >= 2:
        oddnext = odd_sort[1][1]
        if len(even_sort) >= 2:
            evennext = even_sort[1][1]
            ans = min(n-oddnext-even_sort[0][1], n-odd_sort[0][1]-evennext)
        else:
            ans = min(n-oddnext-even_sort[0][1], n-odd_sort[0][1])
    else:
        if len(even_sort) >= 2:
            evennext = even_sort[1][1]
            ans = min(n-odd_sort[0][1]-evennext, n-even_sort[0][1])
        else:
            ans = n // 2


else:
    ans = n - odd_sort[0][1] - even_sort[0][1]

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A1 = [0] * (10 ** 5 + 10)
A2 = [0] * (10 ** 5 + 10)

for n, a in enumerate(A):
    if n % 2 == 0:
        A1[a] += 1
    else:
        A2[a] += 1

c1 = max(A1)
c2 = max(A2)

s1 = A1.index(c1)
s2 = A2.index(c2)

if s1 != s2:
    print(N - c1 - c2)
else:
    A1.sort()
    A2.sort()
    print(N - max(A1[-1] + A2[-2], A1[-2] + A2[-1]))

Solution (Python):
from collections import Counter

n = int(input())
v_list = tuple([int(elem) for elem in input().split(' ')])
v_list_odd = v_list[::2]
v_list_even = v_list[1::2]
ctr_odd = Counter(v_list_odd)
ctr_even = Counter(v_list_even)


most_commons_odd = ctr_odd.most_common()
most_commons_even = ctr_even.most_common()
if len(most_commons_odd) == 1 and len(most_commons_even) == 1 \
and most_commons_odd[0][0] == most_commons_even[0][0]:
    print(len(v_list_even))
    exit(0)

odd_cand = []
even_cand = []
distinct_num = set()
i = 0
while len(distinct_num) < 2:
    try:
        odd_elem = most_commons_odd[i]
        distinct_num.add(odd_elem[0])
        odd_cand.append(odd_elem)
    except:
        pass
    try:
        even_elem = most_commons_even[i]
        distinct_num.add(even_elem[0])
        even_cand.append(even_elem)
    except:
        pass
    i += 1

min_cost = 2**32 - 1
len_allodds = len(v_list_odd)
len_allevens = len(v_list_even)
for odd_elem in odd_cand:
    for even_elem in even_cand:
        if odd_elem[0] == even_elem[0]:
            continue
        else:
            min_cost = min(min_cost, \
            (len_allodds - odd_elem[1]) + (len_allevens - even_elem[1]))
print(min_cost)

Solution (Python):
n = int(input())
list_v = list((map(int, input().split())))
list_e = list_v[::2]
list_o = list_v[1::2]
dict_e = {}
dict_o = {}
for number in set(list_e):
    dict_e[number] = 0
for i in range(0,int(n/2)):
    dict_e[list_e[i]] += 1
for number in set(list_o):
    dict_o[number] = 0
for i in range(0,int(n/2)):
    dict_o[list_o[i]] += 1
e_max = 0
o_max = 0
for key in dict_e.keys():
    if dict_e[key] > e_max:
        e_max = dict_e[key]
        e_key = key

for key in dict_o.keys():
    if dict_o[key] > o_max:
        o_max = dict_o[key]
        o_key = key
ans = o_max + e_max
if e_key == o_key:
    e_max2 = 0
    for key in dict_e.keys():
        if dict_e[key] > e_max2 and key != o_key:
            e_max2 = dict_e[key]
            e_key2 = key
    o_max2 = 0
    for key in dict_o.keys():
        if dict_o[key] > o_max2 and key != e_key:
            o_max2 = dict_o[key]
            o_key2 = key
    ans = max(e_max + o_max2, e_max2 + o_max)

print(n - ans)

Solution (Python):

import collections


def main():
    n = int(input())
    xs = [int(a) for a in input().split()]

    xa = [xs[i] for i in range(0, n, 2)]
    xb = [xs[i] for i in range(1, n, 2)]

    ca = collections.Counter(xa)
    cb = collections.Counter(xb)

    ma, mb = ca.most_common(2), cb.most_common(2)
    val_a, count_a = ma[0]
    val_b, count_b = mb[0]

    if val_a != val_b:
        p = len(xa) - count_a + len(xb) - count_b
        print(p)
        return
    if len(ma) == 1:
        if len(mb) == 1:
            print(len(xa))
            return
        val_b, count_b = mb[1]
        print(len(xb) - count_b)
        return
    if len(mb) == 1:
        val_b, count_b = ma[1]
        print(len(xb) - count_b)
        return
    val_a2, count_a2 = ma[1]
    val_b2, count_b2 = mb[1]
    p1 = len(xb) - count_b + len(xa) - count_a2
    p2 = len(xb) - count_b2 + len(xa) - count_a
    print(min(p1, p2))
    return


if __name__ == '__main__':
    main()

Solution (Python):
import collections

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

vodd = [v[2*i] for i in range(int(n/2))]
veven = [v[2*i+1] for i in range(int(n/2))]

codd = collections.Counter(vodd)
ceven = collections.Counter(veven)

aodd = codd.most_common()[0][0]
aeven = ceven.most_common()[0][0]

nodd = codd.most_common()[0][1]
neven = ceven.most_common()[0][1]

if aodd != aeven:
    print(n-nodd-neven)
else:
    if len(codd) == 1:
        if len(ceven) == 1:
            print(n-nodd)
        else:
            meven = ceven.most_common()[1][1]
            print(n-nodd-meven)
    elif len(ceven) == 1:
        modd = codd.most_common()[1][1]
        print(n-modd-neven)
    else:
        modd = codd.most_common()[1][1]
        meven = ceven.most_common()[1][1]
        print(min(n-nodd-meven,n-modd-neven))

Solution (Python):
import collections

def inputN(typ=str):
    return map(typ, raw_input().split())


N = inputN(int)[0]
v = inputN(int)

col0 = collections.Counter(v[::2])
col1 = collections.Counter(v[1::2])
X0 = col0.most_common()
X1 = col1.most_common()



if X0[0][0] == X1[0][0]:
    if len(X0) == 1 and len(X1) == 1:
        k0 = X0[0][1]
        k1 = 0
    elif len(X0) == 1:
        k0 = X0[0][1]
        k1 = X1[1][1]
    elif len(X1) == 1:
        k0 = X0[1][1]
        k1 = X1[0][1]
    elif X0[1][1] >= X1[1][1]:
        k0 = X0[1][1]
        k1 = X1[0][1]
    elif X0[1][1] < X1[1][1]:
        k0 = X0[0][1]
        k1 = X1[1][1]
else:
    k0 = X0[0][1]
    k1 = X1[0][1]

print N - k0 - k1

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
v1 = [v[2 * i] for i in range(0, n // 2)]
v2 = [v[2 * i + 1] for i in range(0, n // 2)]

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

mc1 = c1.most_common()
mc2 = c2.most_common()
if mc1[0][0] != mc2[0][0]:
    print(n - (mc1[0][1] + mc2[0][1]))
else:
    if len(mc1) == 1 and len(mc2) == 1:
        print(n // 2)
    elif len(mc1) == 1 or len(mc2) == 1:
        print(n // 2 - mc2[1][1] if len(mc1) == 1 else n // 2 - mc1[1][1])
    else:
        if (mc1[0][1] + mc2[1][1]) >= (mc1[1][1] + mc2[0][1]):
            print(n - (mc1[0][1] + mc2[1][1]))
        else:
            print(n - (mc1[1][1] + mc2[0][1]))

Solution (Python):
import collections
n = int(int(input())/2)
a = list(map(int,input().split()))
o = []
e = []
for i in range(n):
  o.append(a[i*2])
  e.append(a[i*2+1])
o_c = collections.Counter(o)
e_c = collections.Counter(e)
o_most = o_c.most_common()[0][0]
o_num = o_c.most_common()[0][1]
e_most = e_c.most_common()[0][0]
e_num = e_c.most_common()[0][1]
ans = 0
if(o_most == e_most and o_num + e_num == n*2):
  ans = n
elif(o_most != e_most and o_num == n and e_num == n):
  ans = 0
else:
  if(o_most == e_most):
    if(len(o_c.most_common()) == 1):
      e_num = e_c.most_common()[1][1]
    elif(len(e_c.most_common()) == 1):
      o_num = o_c.most_common()[1][1]
    else:
      e_t = e_c.most_common()[1][1]
      o_t = o_c.most_common()[1][1]
      if(o_num - o_t <= e_num - e_t):
        o_num = o_t
      else:
        e_num = e_t
  ans = n*2 - o_num - e_num
print(ans)

Solution (Python):
import collections
def inpl(): return list(map(int, input().split()))
n = int(input())
v = inpl()
even,odd=[],[]
for i in range(len(v)):
    if i%2 == 0:
        even.append(v[i])
    else:
        odd.append(v[i])

o = collections.Counter(odd)
e = collections.Counter(even)

omax,emax,ocan,ecan = 0,0,[],[]
for k,v in o.items():
    if v > omax:
        omax = v
        ocan = [k]
    elif v == omax:
        ocan.append(k)
for k,v in e.items():
    if v > emax:
        emax = v
        ecan = [k]
    elif v == emax:
        ecan.append(k)    
end = 0        
for i in ecan:
    for j in ocan:
        if i!=j:
            
            ans = n-(omax+emax)
            end = 1
            break
    if end == 1:
        break
else:
    esec,osec = 0,0
    for k,v in e.items():
        if v >= emax:
            continue
        esec = max(esec,v)
    for k,v in o.items():
        if v >= omax:
            continue
        osec = max(osec,v)
    ans = min(n-(esec+omax),n-(emax+osec))
print(ans)

Solution (Python):
from collections import defaultdict

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

e = defaultdict(int)
o = defaultdict(int)

for i in range(0, len(v), 2):
    e[v[i]] += 1

for i in range(1, len(v), 2):
    o[v[i]] += 1

f = False
if len(e.keys()) == 1:
    o = sorted(o.items(), key=lambda x: x[1], reverse=True)
    for k, v in o:
        if k == list(e.keys())[0]:
            continue
        f = True
        print(n // 2 - v)
        break
    if not f:
        print(n // 2)
elif len(o.keys()) == 1:
    e = sorted(e.items(), key=lambda x: x[1], reverse=True)
    for k, v in e:
        if k == list(o.keys())[0]:
            continue
        f = True
        print(n // 2 - v)
        break
    if not f:
        print(n // 2)
else:
    e = sorted(e.items(), key=lambda x: x[1], reverse=True)
    o = sorted(o.items(), key=lambda x: x[1], reverse=True)

    if e[0][0] != o[0][0]:
        print(n // 2 - e[0][1] +  n // 2 - o[0][1])
    else:
        c1 = n // 2 - e[0][1] + n // 2 - o[1][1]
        c2 = n // 2 - e[1][1] + n // 2 - o[0][1]
        print(min(c1, c2))

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):



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

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

    if nc[0] == n // 2 and ne[0] == n // 2:
        
        print(n//2)
    else:
        if nc[0] == ne[0]:
            print(min(n-odd[nc[0]]-even[ne[1]], n-even[ne[0]]-odd[nc[1]]))
        else:
            print(n-odd[nc[0]]-even[ne[0]])


if __name__ == '__main__':
    main()

Solution (Python):
import collections

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

vo = [v[i] for i in range(n) if i % 2 == 0]
ve = [v[i] for i in range(n) if i % 2 == 1]

count_vo = collections.Counter(vo).most_common()
count_ve = collections.Counter(ve).most_common()

res = 200001

if count_vo[0][0] != count_ve[0][0]:
    print(n-count_vo[0][1]-count_ve[0][1])
elif len(count_vo) == 1 and len(count_ve) == 1:
    print(n//2)
elif len(count_vo) == 1:
    print(n//2-count_ve[1][1])
elif len(count_ve) == 1:
    print(n//2-count_vo[1][1])
else:
    if count_vo[1][1] >= count_ve[1][1]:
        print(n-count_vo[1][1]-count_ve[0][1])
    else:
        print(n - count_vo[0][1] - count_ve[1][1])

Solution (Python):
from collections import Counter

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

v1 = []
v2 = []

for i, v in enumerate(V):
    if i % 2 == 0:
       v1.append(v)
    else:
        v2.append(v)

v1c = Counter(v1).most_common()
v2c = Counter(v2).most_common()

k1, v1 = v1c[0][0], v1c[0][1]
k2, v2 = v2c[0][0], v2c[0][1]

if k1 == k2:
    ans -= v1
    m = 0
    if len(v1c) >= 2:
        m = max(m, v1c[1][1])
    if len(v2c) >= 2:
        m = max(m, v2c[1][1])
    ans -= m
else:
    ans -= v1 + v2

print(ans)

Solution (Python):
import collections as c
n = int(input())
v = list(map(int, input().split()))
v_odd  = []
v_even = []
for i in range(n):
    if i % 2 == 0: v_even.append(v[i])
    else: v_odd.append(v[i])
od_counter = c.Counter(v_odd)
ev_counter = c.Counter(v_even)
odmode = od_counter.most_common()
evmode = ev_counter.most_common()

if odmode[0][0] != evmode[0][0]:
    total = len(v) - odmode[0][1] - evmode[0][1]
    print(total)
else:
    if len(odmode) == 1:
        if len(evmode) == 1:
            print(min(len(v_odd), len(v_even)))
        else:
            print(len(v_even) - evmode[1][1])
    elif len(evmode) == 1:
        print(len(v_odd) - odmode[1][1])
    else:
        odc = len(v) - odmode[0][1] - evmode[1][1]
        evc = len(v) - evmode[0][1] - odmode[1][1]
        print(min(odc, evc))

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

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

d0 = dict()
for x in v0:
    d0[x] = d0.get(x, 0) + 1

d1 = dict()
for x in v1:
    d1[x] = d1.get(x, 0) + 1

L0 = [(k, v) for k, v in d0.items()]
L0 = sorted(L0, key=lambda x: x[1], reverse=True)

L1 = [(k, v) for k, v in d1.items()]
L1 = sorted(L1, key=lambda x: x[1], reverse=True)

half_n = n // 2
ans = -1
if L0[0][0] != L1[0][0]:
    ans = (half_n - L0[0][1]) + (half_n - L1[0][1])
else:
    if len(L0) > 1 and len(L1) > 1:
        if L0[1][1] >= L1[1][1]:
            ans = (half_n - L0[1][1]) + (half_n - L1[0][1])
        else:
            ans = (half_n - L0[0][1]) + (half_n - L1[1][1])
    else:
        if len(L0) == 1 and len(L1) > 1:
            ans = (half_n - L1[1][1])
        elif len(L0) > 1 and len(L1) == 1:
            ans = (half_n - L1[0][1])
        else:
            ans = (half_n)
print(ans)

Solution (Python):

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

odd = [0] * (10 ** 5)
even = [0] * (10 ** 5)
for i, vi in enumerate(v):
    if i % 2: even[vi - 1] += 1
    else: odd[vi - 1] += 1

max_o = max_e = 0
imax_o = imax_e = 0
sub_o = sub_e = 0
for i, (valo, vale) in enumerate(zip(odd, even)):
    
    if valo > max_o:
        sub_o = max_o
        max_o = valo
        imax_o = i + 1
    elif valo > sub_o: sub_o = valo
    
    if vale > max_e:
        max_e = vale
        imax_e = i + 1
    elif vale > sub_e: sub_e = vale

if imax_o == imax_e: print(min(n - max_o - sub_e, n - sub_o - max_e))
else: print(n - max_o - max_e)

Solution (Python):
n=int(input())
even={}
odd={}
for i,x in enumerate(list(map(int,input().split()))):
    if i%2==0:
        if even.get(x,0)==0:
            even[x]=1
        else:
            even[x]+=1
    else:
        if odd.get(x,0)==0:
            odd[x]=1
        else:
            odd[x]+=1

even=sorted(even.items(),key=lambda x:x[1])
odd=sorted(odd.items(),key=lambda x:x[1])
ans=0
if even[-1][0]==odd[-1][0]:
    if len(even)==1 and len(odd)==1:
        ans=n//2
    elif even[-1][1]>odd[-1][1]:
        ans=n-even[-1][1]-odd[-2][1]
    elif even[-1][1]<odd[-1][1]:
        ans=n-even[-2][1]-odd[-1][1]
    else:
        if even[-2][1]>odd[-2][1]:
            ans=n-even[-2][1]-odd[-1][1]
        else:
            ans=n-even[-1][1]-odd[-2][1]
else:
    ans=n-even[-1][1]-odd[-1][1]
print(ans)

Solution (Python):
import collections


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

V0 = [V[i] for i in range(len(V)) if i % 2 == 0]
V1 = [V[i] for i in range(len(V)) if i % 2 == 1]

c0 = collections.Counter(V0)
c1 = collections.Counter(V1)

R0 = (n // 2) + (n % 2) - c0.most_common()[0][1]

if c0.most_common()[0] != c1.most_common()[0]:
    R0 += (n // 2) - c1.most_common()[0][1]
else:
    try:
        R0 += (n // 2) - c1.most_common()[1][1]
    except:
        R0 += (n // 2)

R1 = (n // 2) + (n % 2) - c1.most_common()[0][1]

if c0.most_common()[0] != c0.most_common()[0]:
    R1 += (n // 2) - c0.most_common()[0][1]
else:
    try:
        R1 += (n // 2) - c0.most_common()[1][1]
    except:
        R1 += (n // 2)

print(min(R0, R1))

Solution (Python):
N = int(input())
V = [int(_) for _ in input().split()]

odd = {}
even = {}
for i in range(N):
    if i%2==0:
        if V[i] in even:
            even[V[i]] += 1
        else:
            even[V[i]] = 1
    else:
        if V[i] in odd:
            odd[V[i]] += 1
        else:
            odd[V[i]] = 1
maxEven, maxOdd = max(even.values()), max(odd.values())
if max(even, key=even.get) != max(odd, key=odd.get):
    print(N-maxEven-maxOdd)
else:
    even[max(even, key=even.get)] = 0
    odd[max(odd, key=odd.get)] = 0
    maxEven2, maxOdd2 = max(even.values()), max(odd.values())
    if maxEven2 >= maxOdd2:
        if len(even) > 1:
            print(N-maxEven2-maxOdd)
        else:
            print(N-maxOdd)
    else:
        if len(odd) > 1:
            print(N-maxEven-maxOdd2)
        else:
            print(N-maxEven)

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

ans = 0
even = v[::2]
nums_e = {}
for e in even:
    if not e in nums_e.keys():
        nums_e[e] = 1
    else:
        nums_e[e] += 1

e_sorted = []
for key, value in nums_e.items():
    e_sorted.append([value, key])
e_sorted = sorted(e_sorted, reverse = True) + [[0, 0-1]]
        

odd = v[1::2]
nums_o = {}
for o in odd:
    if not o in nums_o.keys():
        nums_o[o] = 1
    else:
        nums_o[o] += 1
        
o_sorted = []
for key, value in nums_o.items():
    o_sorted.append([value, key])
o_sorted = sorted(o_sorted, reverse = True) + [[-1, 0]]

if e_sorted[0][1] != o_sorted[0][1]:
    print(n - e_sorted[0][0] - o_sorted[0][0])
else:
    ans1 = n - e_sorted[1][0] - o_sorted[0][0]
    ans2 = n - e_sorted[0][0] - o_sorted[1][0]
    print(min(ans1, ans2))

Solution (Python):
n = input()
a = map(int, raw_input().strip().split())
eve = {}
odd = {}
for i in xrange(0, n, 2):
    try: eve[a[i]] += 1
    except: eve[a[i]] = 1
for i in xrange(1, n, 2):
    try: odd[a[i]] += 1
    except: odd[a[i]] = 1
    
em1 = em2 = om1 = om2 = 0
xe1 = xe2 = xo1 = xo2 = 0
for k in eve:
    if eve[k] > em1:
        em2 = em1
        xe2 = xe1
        em1 = eve[k]
        xe1 = k
    elif eve[k] > em2:
        em2 = eve[k]
        xe2 = k
    
for k in odd:
    if odd[k] > om1:
        om2 = om1
        xo2 = xo1
        om1 = odd[k]
        xo1 = k
    elif odd[k] > om2:
        om2 = odd[k]
        xo2 = k

if xe1 != xo1:
    print n - em1 - om1
else:
    t = n // 2
    if em1 > om1: ans = n - em1 - om2
    elif em1 < om1: ans = n - om1 - em2
    else:
        ans = t - em1
        ans += min(t - em2, t - om2)
    print ans

Solution (Python):
import collections

def counter_top(c, exclude):
  for a in c.most_common():
    if a[0] != exclude:
      return a
  return (object(), 0)

def conv_seq(seq, exclude=None):
  c = collections.Counter(seq)
  mc = counter_top(c, exclude)
  return sum(c.values()) - mc[1], mc[0]

input()
vals = list(map(int, input().split()))
s1, a = conv_seq(vals[::2])
s2, b = conv_seq(vals[1::2])
if a != b:
  print(s1 + s2)
else:
  s1_new, _ = conv_seq(vals[::2], exclude=b)
  s2_new, _ = conv_seq(vals[1::2], exclude=a)
  print(min(s1_new + s2, s1 + s2_new))