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


def m():
    N = int(input())
    V = [int(i) for i in input().split()]
    vodds = V[0::2]
    vevens = V[1::2]

    odds_commons = Counter(vodds).most_common()
    even_commons = Counter(vevens).most_common()

    odds_top = odds_commons[0]
    evens_top = even_commons[0]
    if odds_top[0] != evens_top[0]:
        return N - odds_top[1] - evens_top[1]
    else:
        if len(odds_commons) > 1 and len(even_commons) > 1:
            return min(
                N - odds_commons[1][1] - even_commons[0][1],
                N - even_commons[1][1] - odds_commons[0][1]
            )
        elif len(odds_commons) > 1:
            return N - odds_commons[1][1] - even_commons[0][1]
        elif len(even_commons) > 1:
            return N - even_commons[1][1] - odds_commons[0][1]
        else:
            return N // 2


print(m())

Solution (Python):

"""
Created on Fri May 10 23:15:55 2019

@author: Yamazaki Kenichi
"""

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

T = [[0 for i in range(10**5+1)], [0 for i in range(10**5+1)]]
counta = 0
for c in A:
    T[counta%2][c] += 1
    counta += 1

tmp = [[0]*4, [0]*4]
for i in range(10**5+1):

    for k in range(2):
        if T[k][i] > tmp[k][0]:
            tmp[k][2], tmp[k][3] = tmp[k][0], tmp[k][1]
            tmp[k][0], tmp[k][1] = T[k][i], i
        elif T[k][i] > tmp[k][2]:
            tmp[k][2], tmp[k][3] = T[k][i], i

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

Solution (Python):
import collections
n=int(input())
v=[int(i) for i in input().split()]
A=[]
B=[]
for i in range(n//2):
    A.append(v[2*i])
    B.append(v[2*i+1])
    
a=collections.Counter(A)
b=collections.Counter(B)
aa=a.most_common()
bb=b.most_common()


if len(a)==len(b)==1 and aa[0][0]!=bb[0][0]:
    print(0)
elif len(a)==len(b)==1 and aa[0][0]==bb[0][0]:
    print(n//2)
else:
    if aa[0][0]!=bb[0][0]:
        count=n-aa[0][1]-bb[0][1]
        print(count)
    else:
        print(min(
            n-aa[0][1]-bb[1][1],
            n-aa[1][1]-bb[0][1]
        ))

Solution (Python):
import heapq

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

evens = [(0, 0)]*(10**5+1)
odds = [(0, 0)]*(10**5+1)
for i in range(N):
    if (i+1) % 2 == 0:
        evens[V[i]] = (V[i], evens[V[i]][1] + 1)
    else:
        odds[V[i]] = (V[i], odds[V[i]][1] + 1)

evens_top_two = heapq.nlargest(2, evens, key=lambda x: x[1])
odds_top_two = heapq.nlargest(2, odds, key=lambda x: x[1])

if evens_top_two[0][0] != odds_top_two[0][0]:
    print(N - evens_top_two[0][1] - odds_top_two[0][1])
else:
    print(min(N - evens_top_two[0][1] - odds_top_two[1][1],
              N - evens_top_two[1][1] - odds_top_two[0][1]))

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

evens = [(0, 0)]*(10**5+1)
odds = [(0, 0)]*(10**5+1)
for i in range(N):
    if (i+1) % 2 == 0:
        evens[V[i]] = (V[i], evens[V[i]][1] + 1)
    else:
        odds[V[i]] = (V[i], odds[V[i]][1] + 1)

evens.sort(key=lambda x: x[1], reverse=True)
odds.sort(key=lambda x: x[1], reverse=True)

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

Solution (Python):
from collections import defaultdict

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

vsd1 = defaultdict(int)
for i in range(0, n, 2):
    vsd1[vs[i]] += 1

vsd2 = defaultdict(int)
for i in range(1, n, 2):
    vsd2[vs[i]] += 1

vsc1 = []
for k, v in vsd1.items():
    vsc1.append((k, v))

vsc2 = []
for k, v in vsd2.items():
    vsc2.append((k, v))

vsc1.append((-1, 0))
vsc2.append((-1, 0))
vsc1 = sorted(vsc1, key=lambda x: x[1], reverse=True)
vsc2 = sorted(vsc2, key=lambda x: x[1], reverse=True)

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

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

dic1, dic2 = dict(), dict()


for i, x in enumerate(lst):
    dic = dic1 if  i%2 == 0 else dic2
    if x not in dic.keys():
        dic[x] = 1
    else:
        dic[x] += 1

dic1 =sorted(dic1.items(), key = lambda x:x[1])[::-1]
dic2 =sorted(dic2.items(), key = lambda x:x[1])[::-1]





if dic1[0][0] != dic2[0][0]:
    print (N-dic1[0][1]-dic2[0][1])
elif len(dic1) == 1 and len(dic2) == 1:
    print (N//2)
elif len(dic1) == 1:
    print (N-dic1[0][1]-dic2[1][1])
elif len(dic2) == 1:
    print (N-dic1[1][1]-dic2[0][1])
else:
    print (min(N-dic1[0][1]-dic2[1][1], N-dic1[1][1]-dic2[0][1]))

Solution (Python):
N=int(input())
V=list(map(int,input().split()))
o={0:0}
e={0:0}
n=1
for i,v in enumerate(V):
    if n:
        if v in o.keys():
            o[v]+=1
        else:
            o[v]=1
    else:
        if v in e.keys():
            e[v]+=1
        else:
            e[v]=1
    n=1-n
O=sorted(o.items(),key=lambda x:-x[1])
E=sorted(e.items(),key=lambda x:-x[1])
if O[0][0]==E[0][0]:
    m=max(O[0][1]+E[1][1],E[0][1]+O[1][1])
else:
    m=O[0][1]+E[0][1]
print(N-m)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
dic1,dic2=dict(),dict()
for i,x in enumerate(a):
    dic = dic1 if i%2==0 else dic2
    if x not in dic.keys():
        dic[x]=1
    else:
        dic[x]+=1
dic1=sorted(dic1.items(),key=lambda x:x[1])[::-1]
dic2=sorted(dic2.items(),key=lambda x:x[1])[::-1]

if dic1[0][0]!=dic2[0][0]:
    print(n-dic1[0][1]-dic2[0][1])
elif len(dic1)==1 and len(dic2)==1:
    print(n//2)
elif len(dic1)==1:
    print(n-dic1[0][1]-dic2[1][1])
elif len(dic2)==1:
    print(n-dic2[0][1]-dic1[1][1])
else:
    print(n-max(dic1[0][1]+dic2[1][1], dic2[0][1]+dic1[1][1]))

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v_odd = v[::2]
v_even = v[1::2]
c_odd = Counter(v_odd)
c_even = Counter(v_even)
ans = len(v)
for c_o, c_e in zip(c_odd.most_common(), c_even.most_common()):
    if c_o == c_e:
        continue
    else:
        ans -= max(c_o[1], c_e[1])
        ans -= min(c_odd.most_common()[0][1], c_even.most_common()[0][1])
        break
else:
    ans -= c_odd.most_common()[0][1]
    if len(c_even.most_common()[1:]) > 0:
        ans -= c_even.most_common()[1][1]

print(ans)

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

cnts = [collections.Counter(v[::2]), collections.Counter(v[1::2])]

hs = [[], []]
for i in range(2):
    for k, c in cnts[i].items():
        heapq.heappush(hs[i], (-c, k))
h0 = heapq.heappop(hs[0])
h1 = heapq.heappop(hs[1])
if h0[1] == h1[1]:
    if not hs[0] and not hs[1]:
        print(n//2)
    elif not hs[0]:
        print(n+h1[0])
    elif not hs[1]:
        print(n+h0[0])
    else:
        n0 = heapq.heappop(hs[0])
        n1 = heapq.heappop(hs[1])
        print(n + min(h0[0]+n1[0], n0[0]+h1[0]))
else:
    print(n+(h0[0]+h1[0]))

Solution (Python):
import collections
n = int(input())
v = list(map(int,input().split()))
a = v[0::2]
b = v[1::2]
a = collections.Counter(a)
a = a.most_common()
b = collections.Counter(b)
b = b.most_common()
c = n//2
if a[0][0] != b[0][0]:
    ans = c-a[0][1] + c-b[0][1]
    print(ans)
else: 
    if len(a) == 1:
        tmpa = 0
    else:
        tmpa = a[1][1]
    if len(b) == 1:
        tmpb = 0
    else:
        tmpb = b[1][1]
    ans1 = c-tmpa + c-b[0][1]
    ans2 = c-a[0][1] + c-tmpb
    print(min(ans1,ans2))

Solution (Python):
import numpy as np
from collections import Counter

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

c_odd = Counter(vlist[0::2])
c_even = Counter(vlist[1::2])

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

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

Solution (Python):
from collections import Counter

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

set_e, set_o = set(even), set(odd)
E, O = Counter(even), Counter(odd)
ce, co = E.most_common(), O.most_common()
e1, o1 = ce[0][0], co[0][0]

if e1 != o1:
    a, b = ce[0][1], co[0][1]
    print(n-a-b)
    exit()
if len(set_o) == 1 and len(set_e) == 1:
    print(len(even))
    exit()
if len(set_o) == 1:
    a = ce[1][1]
    print(len(even)-a)
    exit()
if len(set_e) == 1:
    a = co[1][1]
    print(len(odd)-a)
    exit()

e2, o2 = ce[1][0], co[1][0]
ce1, co1 = ce[0][1], co[0][1]
ce2, co2 = ce[1][1], co[1][1]

print(min(n-ce1-co2, n-ce2-co1))

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
v_odd = v[0::2]
v_even = v[1::2]
ans = 0
c_odd = Counter(v_odd)
c_even = Counter(v_even)
v_o, c_o = zip(*c_odd.most_common())
v_e, c_e = zip(*c_even.most_common())
if len(c_o) == 1:
    odd1 = 0
else:
    odd1 = c_o[1]
if len(c_e) == 1:
    even1 = 0
else:
    even1 = c_e[1]
if not v_o[0] == v_e[0]:
    print(sum(c_o) - c_o[0] + sum(c_e) - c_e[0])
else:
    ans = min(sum(c_o) - c_o[0] + sum(c_e) - even1, sum(c_o) - odd1 + sum(c_e) - c_e[0])
    print(ans)

Solution (Python):
n = int(input())
V = list(map(int, input().split()))
E = {}
O = {}
now = 1
for i, v in enumerate(V):
    if now:
        if v in E.keys():
            E[v] += 1
        else:
            E[v] = 1
    else:
        if v in O.keys():
            O[v] += 1
        else:
            O[v] = 1
    now = 1 - now
E = sorted(E.items(), key=lambda x: -x[1])
O = sorted(O.items(), key=lambda x: -x[1])
if E[0][0] != O[0][0]:
    print(n - E[0][1] - O[0][1])
else:
    if len(E) == 1 and len(O) == 1:
        print(E[0][1])
    elif len(E) == 1:
        print(n-E[0][1]-O[1][1])
    elif len(O) == 1:
        print(n-E[1][1]-O[0][1])
    else:
        print(min(n-E[0][1]-O[1][1], n-E[1][1]-O[0][1]))

Solution (Python):
n = int(input())
V = list(map(int, input().split()))
E = {}
O = {}
n = 1
for i, v in enumerate(V):
    if n:
        if v in E.keys():
            E[v] += 1
        else:
            E[v] = 1
    else:
        if v in O.keys():
            O[v] += 1
        else:
            O[v] = 1
    n = 1 - n
E = sorted(E.items(), key=lambda x: -x[1])
O = sorted(O.items(), key=lambda x: -x[1])
if E[0][0] != O[0][0]:
    ans = sum([x[1] for x in E])-E[0][1]
    ans += sum([x[1] for x in O])-O[0][1]
    print(ans)
else:
    if len(E) == 1 and len(O) == 1:
        print(E[0][1])
    elif len(E) == 1:
        ans = sum([x[1] for x in E])-E[0][1]
        ans += sum([x[1] for x in O])-O[1][1]
        print(ans)
    elif len(O) == 1:
        ans = sum([x[1] for x in E])-E[1][1]
        ans += sum([x[1] for x in O])-O[0][1]
        print(ans)
    else:
        ans1 = sum([x[1] for x in E])-E[0][1]
        ans1 += sum([x[1] for x in O])-O[1][1]
        ans2 = sum([x[1] for x in E])-E[1][1]
        ans2 += sum([x[1] for x in O])-O[0][1]
        print(min(ans1, ans2))

Solution (Python):

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

evn = {}
odd = {}
for i in range(n):
    
    if i%2==0:
        candi = lista[i]
        if candi not in evn:
            evn[candi] = 1
        else:
            evn[candi] += 1
    else:
        candi = lista[i]
        if candi not in odd:
            odd[candi] = 1
        else:
            odd[candi] += 1
        
maxevnkey1 = 0
maxevnval1 = 0
maxevnkey2 = 0
maxevnval2 = 0

for key in evn:
    val = evn[key]
    if val>maxevnval2:
        if val>=maxevnval1:
            maxevnkey2,maxevnval2 = maxevnkey1,maxevnval1
            maxevnkey1,maxevnval1 = key,val
        else:
            maxevnkey2,maxevnval2 = key,val

maxoddkey1 = 0
maxoddval1= 0
maxoddkey2 = 0
maxoddval2= 0

for key in odd:
    val = odd[key]
    if val>maxoddval2:
        if val>=maxoddval1:
            maxoddkey2,maxoddval2 = maxoddkey1,maxoddval1
            maxoddkey1,maxoddval1 = key,val
        else:
            maxoddkey2,maxoddval2 = key,val
            
ans = 0
if maxevnkey1!=maxoddkey1:
    ans = n-maxevnval1-maxoddval1
else:
    temp = max(maxevnval1+maxoddval2,maxevnval2+maxoddval1)
    ans = n-temp
print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
V = [int(a) for a in input().split(" ")]
arr1,arr2 = V[::2], V[1:][::2]
dic1,dic2 = defaultdict(lambda: 0), defaultdict(lambda: 0)
for v1, v2 in zip(arr1, arr2):
    dic1[v1] += 1
    dic2[v2] += 1
rank1 = sorted(dic1.items(), key=lambda t: t[1])[::-1]
rank2 = sorted(dic2.items(), key=lambda t: t[1])[::-1]
if rank1[0][0] == rank2[0][0]:
    if rank1[0][1] == rank2[0][1]:
        nadd1 = rank1[1][1] if len(rank1)>=2 else 0
        nadd2 = rank2[1][1] if len(rank2)>=2 else 0
        print(N-rank1[0][1]-max(nadd1, nadd2))
    else:
        rank1, rank2 = rank1, rank2 if rank1[0][0]>rank2[0][0] else rank2, rank1
        nadd = rank2[1][1] if len(rank2)>=2 else 0
        print(N-rank1[0][1]-nadd)
else:
    print(N-(rank1[0][1]+rank2[0][1]))

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

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

Solution (Python):
from collections import defaultdict
from operator import itemgetter
import sys
input = sys.stdin.readline

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

a = defaultdict(int)
b = defaultdict(int)
a[0] = 0
b[0] = 0

for i in range(n):
    if i % 2 == 0:
        a[v[i]] += 1
    else:
        b[v[i]] += 1

a_sorted = sorted(a.items(), key=itemgetter(1), reverse=True)
b_sorted = sorted(b.items(), key=itemgetter(1), reverse=True)
if a_sorted[0][0] == b_sorted[0][0]:
    c1 = n/2 - a_sorted[0][1]
    c1 += n/2 - b_sorted[1][1]
    c2 = n/2 - b_sorted[0][1]
    c2 += n/2 - a_sorted[1][1]
    c = min(c1, c2)
else:
    c = n/2 - a_sorted[0][1]
    c += n/2 - b_sorted[0][1]
print(int(c))

Solution (Python):


from bisect import bisect_left as binl
from copy import copy, deepcopy

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance





def make_1st_2nd_list(countlist):
    max_v_list = []
    max_v_list_2nd = []
    max_count = -1
    max_count_2nd = -1

    for i, count in enumerate(countlist):
        if count > max_count:
            max_count_2nd = max_count
            max_v_list_2nd = max_v_list
            max_count = count
            max_v_list = [i]
        elif count == max_count:
            max_v_list.append(i)
        elif count > max_count_2nd:
            max_count_2nd = count
            max_v_list_2nd = [i]
        elif count == max_count_2nd:
            max_v_list_2nd.append(i)

    return (max_v_list, max_v_list_2nd)


def main():
    n = intin()
    vlist = intina()

    countlist0 = [0] * (10**5 + 1)
    countlist1 = [0] * (10**5 + 1)
    for i, v in enumerate(vlist):
        if i % 2 == 0:
            countlist0[v] += 1
        else:
            countlist1[v] += 1

    max_v_list0, max_v_list_2nd0 = make_1st_2nd_list(countlist0)
    max_v_list1, max_v_list_2nd1 = make_1st_2nd_list(countlist1)

    if len(max_v_list0) == 1 and len(max_v_list1) == 1 and \
       max_v_list0[0] == max_v_list1[0]:
        if not max_v_list_2nd0 and not max_v_list_2nd1:
            print(n // 2)
        elif not max_v_list_2nd0:
            print(n - countlist0[max_v_list0[0]]
                  - countlist1[max_v_list_2nd1[0]])
        elif not max_v_list_2nd1:
            print(n - countlist0[max_v_list_2nd0[0]]
                  - countlist1[max_v_list1[0]])
        else:
            c0 = countlist0[max_v_list0[0]]
            c1 = countlist1[max_v_list1[0]]

            ans1 = n - countlist0[max_v_list0[0]] \
                  - countlist1[max_v_list_2nd1[0]]
            ans2 = n - countlist0[max_v_list_2nd0[0]] \
                  - countlist1[max_v_list1[0]]
            print(min(ans1, ans2))

        return

    print(n - countlist0[max_v_list0[0]]
          - countlist1[max_v_list1[0]])


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline

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

m = [{}, {}]
vm = [[(0, 0), (0, 0)], [(0, 0), (0, 0)]]

for i in range(N):
    if m[i % 2].get(L[i]) != None:
        m[i % 2][L[i]] += 1
    else:
        m[i % 2][L[i]] = 1

for i in range(N):
    k = L[i]
    v = m[i % 2][k]
    t1 = vm[i % 2][0]
    t2 = vm[i % 2][1]
    
    if t1[1] < v:
        vm[i % 2][1] = [t1[0], t1[1]]
        vm[i % 2][0] = [k, v]
    elif t2[1] < v and t1[0] != k:
        vm[i % 2][1] = [k, v]
        
f1 = vm[0][0]
f2 = vm[0][1]
s1 = vm[1][0]
s2 = vm[1][1]

p = 0
if f1[0] != s1[0]:
    p = N - f1[1] - s1[1]
else:
    p = N - max([f1[1] + s2[1], f2[1] + s1[1]])
    
print(p)

Solution (Python):
import collections
n=int(input())
v=list(map(int,input().split()))
v0=[]
v1=[]
for i in range(n//2):
    v0.append(v[2*i])
    v1.append(v[2*i+1])
if collections.Counter(v0).most_common()[0][0] == collections.Counter(v1).most_common()[0][0]:
    if collections.Counter(v0).most_common()[0][1] == len(v0):
        if collections.Counter(v1).most_common()[0][1] == len(v1):
            print(len(v0))
        else:
            print(len(v1)-collections.Counter(v1).most_common()[1][1])
    else:
        if collections.Counter(v1).most_common()[0][1] == len(v1):
            print(len(v0)-collections.Counter(v0).most_common()[0][1])
        else:
            print(min(len(v)-collections.Counter(v0).most_common()[1][1]-collections.Counter(v1).most_common()[0][1],\
                     len(v)-collections.Counter(v0).most_common()[0][1]-collections.Counter(v1).most_common()[1][1]))
else:
    print(len(v)-collections.Counter(v0).most_common()[0][1]-collections.Counter(v1).most_common()[0][1])

Solution (Python):
import collections

n=int(input())
a=[int(x) for x in input().split()]
evn=[]
odd=[]

def ct(lrg,sml):
    for lst in [lrg,sml]:
        if len(lst)==1:
            lst.append((0,0))
    if lrg[0][0]==sml[0][0]:
        return min(n-lrg[1][1]-sml[0][1],n-lrg[0][1]-sml[1][1])
    else:
        return n-lrg[0][1]-sml[0][1]

for i in range(len(a)):
    if i%2:
        evn.append(a[i])
    else:
        odd.append(a[i])
        
cevn=collections.Counter(evn).most_common()
codd=collections.Counter(odd).most_common()

if cevn[0][1]>codd[0][1]:
    ans = ct(cevn,codd)
else:
    ans = ct(codd,cevn)
    
print(ans)

Solution (Python):
n=int(input())
v_list=list(map(int,input().split()))
even=1
e_dict={}
o_dict={}
for i in v_list:
    if even==1:
        if i in e_dict:
            e_dict[i]=e_dict[i]+1
        else:
            e_dict[i]=1
        even=0
    else:
        if i in o_dict:
            o_dict[i]=o_dict[i]+1
        else:
            o_dict[i]=1
        even=1
max_e=max(e_dict,key=e_dict.get)
max_o=max(o_dict,key=o_dict.get)
if max_e==max_o:
    max1e=max(e_dict.values())
    max1o=max(o_dict.values())
    e_dict.pop(max_e)
    o_dict.pop(max_o)
    if e_dict=={}:
        max2e=0
    else:
        max2e=max(e_dict.values())
    if o_dict=={}:
        max2o=0
    else:
        max2o=max(o_dict.values())
    answer=min(n-max1e-max2o,n-max1o-max2e)
    print(answer)
else:
    answer=n-max(e_dict.values())-max(o_dict.values())
    print(answer)

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
from collections import Counter
even=[]
odd=[]
for i in range(n):
    if i%2==0:
        even.append(v[i])
    else:
        odd.append(v[i])
E=Counter(even).most_common()
O=Counter(odd).most_common()
E.append([0,0])
O.append([0,0])
if E[0][0]!=O[0][0]:
    print(n-(E[0][1]+O[0][1]))
else:
    print(min(n-(E[1][1]+O[0][1]),n-(E[0][1]+O[1][1])))

Solution (Python):
import numpy as np
from copy import deepcopy
import math
import itertools
from collections import Counter

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

V_odd = [V[i] for i in range(N) if i % 2 == 1]
V_even = [V[i] for i in range(N) if i % 2 == 0]


char_common_odd_1 = Counter(V_odd).most_common(2)[0][0]
n_common_odd_1 = Counter(V_odd).most_common(2)[0][1]
char_common_even_1 = Counter(V_even).most_common(2)[0][0]
n_common_even_1 = Counter(V_even).most_common(2)[0][1]


if char_common_odd_1 == char_common_even_1: 
  if (n_common_odd_1 == N/2) and (n_common_even_1 == N/2): 
    ans = N/2
  elif (n_common_odd_1 == N/2): 
    n_common_even_2 = Counter(V_even).most_common(2)[1][1]
    ans = N/2 - n_common_even_2
  elif (n_common_even_1 == N/2): 
    n_common_odd_2 = Counter(V_odd).most_common(2)[1][1]
    ans = N/2 - n_common_odd_2
  else: 
    n_common_odd_2 = Counter(V_odd).most_common(2)[1][1]
    n_common_even_2 = Counter(V_even).most_common(2)[1][1]
    var_odd1_even2 = N - n_common_odd_1 - n_common_even_2
    var_odd2_even1 = N - n_common_odd_2 - n_common_even_1
    ans = min(var_odd1_even2, var_odd2_even1)
else: 
  ans = N - n_common_odd_1 - n_common_even_1
  
print(int(ans))

Solution (Python):
import re
n = int(input())
vs = list(map(int, input().split()))
edic = {}
odic = {}

for i in range(n):
    item = vs[i]
    if i % 2 == 0:
        if item in edic:
            edic[item] += 1
        else:
            edic[item] = 1
    else:
        if item in odic:
            odic[item] += 1
        else:
            odic[item] = 1

elist = sorted(edic.items(), key=lambda x: -x[1])
olist = sorted(odic.items(), key=lambda x: -x[1])

if elist[0][0] != olist[0][0]:
    print(len(vs) - elist[0][1] - olist[0][1])
else:
    ogain = egain = 0
    if len(elist) >= 2:
        egain = elist[1][1]
    if len(olist) >= 2:
        ogain = olist[1][1]
    print(min(len(vs) - elist[0][1] - ogain, len(vs) - olist[0][1] - egain ))

Solution (Python):
import sys
import collections
input = sys.stdin.readline

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

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

c_even = collections.Counter(v_even)
c_odd = collections.Counter(v_odd)

most_even = c_even.most_common(2)
most_odd = c_odd.most_common(2)

if most_even[0][0] != most_odd[0][0]:
    print(n - most_even[0][1] - most_odd[0][1])
elif len(most_even) == len(most_odd) == 1:
    print(int(n/2))
else:
    if most_even[0][1] > most_odd[0][1]:
        print(n - most_even[0][1] - most_odd[1][1])
    elif most_even[0][1] < most_odd[0][1]:
        print(n - most_odd[0][1] - most_even[1][1])
    else:
        print(n - most_even[0][1] - max(most_even[1][1], most_odd[1][1]))

Solution (Python):
from collections import Counter

n = int(input())
v = input().split()

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

if len(set(v)) == 1:
    print(len(v) // 2)
elif c1[0][0] != c2[0][0]:
    print(n - c1[0][1] - c2[0][1])
else:
    print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))

Solution (Python):

import collections


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

odd_c = collections.Counter(odd).most_common()
even_c = collections.Counter(even).most_common()

if odd_c[0][0] != even_c[0][0]:
    ans = len(v) - odd_c[0][1] - even_c[0][1]
elif len(odd_c) == 1 and len(even_c) == 1:
    ans = odd_c[0][1]
elif len(odd_c) == 1:
    ans = len(v)//2 - even_c[1][1]
elif len(even_c) == 1:
    ans = len(v)//2 - odd_c[1][1]
else:
    e = len(v) - odd_c[0][1] - even_c[1][1]
    o = len(v) - even_c[0][1] - odd_c[1][1]
    ans = e if e < o else o
print(ans)

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

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


dict_odd = {}
dict_even = {}

for i in range(n):
  
  if i %2 == 0:
    dict_odd[a[i]] = dict_odd.get(a[i], 0) + 1
  else:
    dict_even[a[i]] = dict_even.get(a[i], 0) + 1
    


v_odd_sorted = sorted(dict_odd.values())
v_even_sorted = sorted(dict_even.values())

odd_sorted = sorted(dict_odd.items(), key=lambda x : x[1])
even_sorted = sorted(dict_even.items(), key=lambda x : x[1])


ans = 0

if len(set(a)) == 1:
  ans = sum(v_odd_sorted)
  
else:
  
  if odd_sorted[-1][0] == even_sorted[-1][0]:
    comp1 = ans = sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-2]) + v_even_sorted[-1]
    comp2 = ans = sum(v_even_sorted[:-1]) + sum(v_odd_sorted[:-2]) + v_odd_sorted[-1]
    ans = min([comp1, comp2])
    """
    if odd_sorted[-1][1] >= even_sorted[-1][1]:
      
      ans = sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-2]) + v_even_sorted[-1]
    else:
      
      ans = sum(v_even_sorted[:-1]) + sum(v_odd_sorted[:-2]) + v_odd_sorted[-1]
      """
  else:
    ans = sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-1])
print(ans)

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

n = int(input())
a = list(map(int, input().split()))
even = defaultdict(int)
odd = defaultdict(int)
for i in range(n):
    if i % 2 == 0:
        even[a[i]] += 1
    else:
        odd[a[i]] += 1
x = sorted(even.items(), reverse=True, key=lambda t:t[1])
y = sorted(odd.items(), reverse=True, key=lambda t:t[1])
even_index = 0
odd_index = 0
if x[0][0] == y[0][0]:
    if x[0][1] > y[0][1]:
        even_index = 0
        odd_index = 1
    elif x[0][1] < y[0][1]:
        odd_index = 0
        even_index = 1
    else:
        if len(x) > 1:
            print(n - x[0][1] - max(x[1][1], y[1][1]))
        else:
            print(n // 2)
        exit()
            
else:
    even_index = 0
    odd_index = 0
print(n - x[even_index][1] - y[odd_index][1])

Solution (Python):
import collections
n = int(input())
v = list(map(int, input().split()))
c_odd  = collections.Counter(v[::2])
c_even = collections.Counter(v[1::2])
odd    = c_odd.most_common()[:2]
even   = c_even.most_common()[:2]
if (len(odd) == 1) & (len(even) == 1):
	if odd[0][0] == even[0][0]:
		ans = odd[0][1]
	else:
		ans = 0
elif len(odd) == 1:
	if odd[0][0] == even[0][0]:
		ans = n - odd[0][1] - even[1][1]
	else:
		ans = n - odd[0][1] - even[0][1]
elif len(even) == 1:
	if odd[0][0] == even[0][0]:
		ans = n - odd[1][1] - even[0][1]
	else:
		ans = n - odd[0][1] - even[0][1]
else:
	if odd[0][0] == even[0][0]:
		ans = min(n - odd[0][1] - even[1][1], n - odd[1][1] - even[0][1])
	else:
		ans = n - odd[0][1] - even[0][1]
print(ans)

Solution (Python):
import collections
n=int(input())
V=[int(i) for i in input().split()]
if len(set(V))==1:
  print(n//2)
else:
  O,E=[],[]
  for i in range(n//2):
    O.append(V[2*i])
    E.append(V[2*i+1])
  cO=collections.Counter(O).most_common()
  cE=collections.Counter(E).most_common()
  if cO[0][0]!=cE[0][0]:
    print(n-cO[0][1]-cE[0][1])
  else:
    print(min(n-cO[0][1]-cE[1][1],n-cO[1][1]-cE[0][1]))

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
 
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
m1 = c1.most_common()
m2 = c2.most_common()
t2 = n//2
t1 = n - t2
 
if len(m1) == len(m2) == 1:
    print(n//2 if m1[0][0] == m2[0][0] else 0)
elif len(m1) == 1:
    if m1[0][0] != m2[0][0]:
        print(t1 - m2[0][1])
    else:
        print(t1 - m2[1][1])
elif len(m2) == 1:
    if m1[0][0] != m2[0][0]:
        print(t2 - m1[0][1])
    else:
        print(t2 - m1[1][1])
else:
    if m1[0][0] != m2[0][0]:
        print(n - m1[0][1] - m2[0][1])
    else:
        ans = n - m1[1][1] - m2[1][1]
        if m1[0][0] != m2[1][0]:
            ans = min(ans, n - m1[0][1] - m2[1][1])
        if m1[1][0] != m2[0][0]:
            ans = min(ans, n - m1[1][1] - m2[0][1])
        print(ans)

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

import numpy as np
odd  =np.array(v)[1::2]
even =np.array(v)[0::2]
odd_count = np.bincount(odd)
odd_mode = np.argmax(odd_count)
even_count = np.bincount(even)
even_mode = np.argmax(even_count)

ans = 0
if odd_mode!=even_mode:
    ans += len(odd) - odd_count.max()
    ans += len(even) - even_count.max()
    print(ans)
else:
    odd_max = odd_count.max()
    odd_result=list(odd_count)
    odd_result.remove(odd_max)
    
    even_max = even_count.max()
    even_result=list(even_count)
    even_result.remove(even_max)
    
    ans1 = len(odd) - odd_count.max()
    ans1 += len(even) - np.array(even_result).max()
    
    ans2 = len(even) - even_count.max()
    ans2 += len(odd) - np.array(odd_result).max()
    print(min(ans1,ans2))

Solution (Python):
import sys
from collections import Counter

sys.setrecursionlimit(10000)
INF = float('inf')

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

v1 = Counter(V[::2]).most_common(2)
v2 = Counter(V[1::2]).most_common(2)


if v1[0][0] != v2[0][0]:
    ans = N - (v1[0][1] + v2[0][1])
else:
    ans = N - v1[0][1]
    if len(v1) >= 2:
        ans = min(ans, N - (v1[1][1] + v2[0][1]))
    if len(v2) >= 2:
        ans = min(ans, N - (v1[0][1] + v2[1][1]))
print(ans)