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

odds = []
evens = []

for i in range(n):
  if i % 2 == 0:
    evens.append(v[i])
  else:
    odds.append(v[i])

evens_common = Counter(evens).most_common()
odds_common = Counter(odds).most_common()

if evens_common[0][0] != odds_common[0][0]:
  evens_most_count = Counter(evens).most_common()[0][1]
  odds_most_count = Counter(odds).most_common()[0][1]
  print(n - evens_most_count - odds_most_count)
else:
  if len(evens_common) == 1:
    if len(odds_common) == 1:
      print(n//2)
    else:
      print(n - odds_common[1][1])
  else:
    if len(odds_common) == 1:
      print(n - evens_common[1][1])
    else:
      res = min(n - evens_common[1][1] - odds_common[0][1], n - evens_common[0][1] - odds_common[1][1])
      print(res)

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
s1 = sorted(c1.items(), key=lambda x:x[1], reverse=True)
s2 = sorted(c2.items(), key=lambda x:x[1], reverse=True)

if len(s1) == 1 and len(s2) == 1:
    if s1[0][0] == s2[0][0]:
        ans = int(n / 2)
    else:
        ans = 0
else:
    if s1[0][0] != s2[0][0]:
        ans = n - s1[0][1] - s2[0][1]
    else:
        if s1[0][1] > s2[0][1]:
            ans = n - s1[0][1] - s2[1][1]
        elif s1[0][1] < s2[0][1]:
            ans = n - s1[1][1] - s2[0][1]
        else:
            ans = min(n - s1[0][1] - s2[1][1], n - s1[1][1] - s2[0][1])
print(ans)

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
odd = {}
even = {}
change = 0
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

if len(odd) == 1 and len(even) == 1:
    if odd == even:
        change = int(n / 2)
else:
    max_e = max(even, key=even.get)
    max_o = max(odd, key=odd.get)
    if max_e != max_o:
        change = n - even[max_e] - odd[max_o]
    else:
        if even[max_e] > even[max_o]:
            max_o2 = min(odd, key=odd.get)
            for o in odd:
                if o != max_o and odd[o] > odd[max_o2]:
                    max_o2 = o
            change = n - even[max_e] - odd[max_o2]
        elif even[max_e] == even[max_o]:
            max_o2 = min(odd, key=odd.get)
            for o in odd:
                if o != max_o and odd[o] > odd[max_o2]:
                    max_o2 = o
            max_e2 = min(even, key=even.get)
            for e in even:
                if e != max_e and even[e] > even[max_e2]:
                    max_e2 = e
            change = min(n - even[max_e] - odd[max_o2], n - odd[max_o] - even[max_e2])
        else:
            max_e2 = min(even, key=even.get)
            for e in even:
                if e != max_e and even[e] > even[max_e2]:
                    max_e2 = e
            change = n - odd[max_o] - even[max_e2]
print(change)

Solution (Python):

import numpy as np
from collections import Counter
N = input()

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

odd = t[0::2]
even = t[1::2]
rest = 0

co = Counter(odd)
ce = Counter(even)

omc = co.most_common()
emc = ce.most_common()

if omc[0][0] == emc[0][0]:
    if len(omc) < 2 and len(emc) < 2:       
        rest = len(even)
    elif len(omc) < 2:
        rest = len(even)
    elif len(emc) < 2:
        rest = len(odd)
    else:
        or1 = len(odd) - co.most_common()[0][1]
        or2 = len(odd) - co.most_common()[1][1]
        er1 = len(even) - ce.most_common()[0][1]
        er2 = len(even) - ce.most_common()[1][1]

        if or1 + er2 > or2 + er1:
            rest = or2 + er1
        else:
            rest = or1 + er2
else:
    rest = len(odd) - co.most_common()[0][1] + len(even) - ce.most_common()[0][1]


print(rest)

Solution (Python):

import numpy as np
from collections import Counter
N = input()
t = np.array(map(int, raw_input().split()))

odd = t[0::2]
even = t[1::2]
rest = 0

co = Counter(odd)
ce = Counter(even)

omc = co.most_common()
emc = ce.most_common()

if omc[0][0] == emc[0][0]:
    if len(omc) < 2 and len(emc) < 2:       
        rest = len(even)
    elif len(omc) < 2:
        rest = len(even)
    elif len(emc) < 2:
        rest = len(odd)
    else:
        or1 = len(odd) - co.most_common()[0][1]
        or2 = len(odd) - co.most_common()[1][1]
        er1 = len(even) - ce.most_common()[0][1]
        er2 = len(even) - ce.most_common()[1][1]

        if or1 + er2 > or2 + er1:
            rest = or2 + er1
        else:
            rest = or1 + er2
else:
    rest = len(odd) - co.most_common()[0][1] + len(even) - ce.most_common()[0][1]


print rest

Solution (Python):
from collections import Counter

n = int(input())
vvv = list(map(int, input().split()))
cnt1 = Counter(vvv[0::2])
cnt2 = Counter(vvv[1::2])
mc1 = cnt1.most_common(2)
mc2 = cnt2.most_common(2)
if mc1[0][0] == mc2[0][0]:
    sc1 = mc1[1][1] if len(mc1) > 1 else 0
    sc2 = mc2[1][1] if len(mc2) > 1 else 0
    print(min(n - mc1[0][1] - sc2, n - sc1 - mc2[0][1]))
else:
    print(n - mc1[0][1] - mc2[0][1])

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
d1 = {}
d2 = {}

for i in range(0, n, 2):
    if v[i] in d1.keys():
        d1[v[i]] += 1
    else:
        d1[v[i]] = 1
for i in range(1, n, 2):
    if v[i] in d2.keys():
        d2[v[i]] += 1
    else:
        d2[v[i]] = 1


def keys_values(d):
    fk, fv, sk, sv = 0, 0, 0, 0
    for k in d:
        if d[k] > fv:
            sk, sv = fk, fv
            fk, fv = k, d[k]
        elif d[k] > sv:
            sk, sv = k, d[k]
    return fk, fv, sk, sv


ak, av, bk, bv = keys_values(d1)
ck, cv, dk, dv = keys_values(d2)
if ak != ck:
    print(n-av-cv)
else:
    print(min((n-av-dv), n-bv-cv))

Solution (Python):
from collections import Counter
c = [Counter(), Counter()]
n = input()
a = map(int, raw_input().split())
for i in range(n):
	c[i & 1][a[i]] += 1
p = [(0, 0)]
q = [(0, 0)]
for i in c[0]:
	p.append((c[0][i], i))
for i in c[1]:
	q.append((c[1][i], i))
p.sort()
q.sort()
if p[-1][1] == q[-1][1]:
	print n - max(p[-1][0] + q[-2][0], p[-2][0] + q[-1][0])
else:
	print n - p[-1][0] - q[-1][0]

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
s1 = sorted(c1.items(), key=lambda x: x[1], reverse=True)
s2 = sorted(c2.items(), key=lambda x: x[1], reverse=True)
if s1[0][0] != s2[0][0]:
    print(n - s1[0][1] - s2[0][1])
else:
    if len(s1) == 1 and len(s1) == 1:
        ans = min(n - s1[0][1], n - s2[0][1])
    elif len(s1) == 1:
        ans = n - s1[0][1] - s2[1][1]
    elif len(s2) == 1:
        ans = n - s1[1][1] - s2[0][1]
    else:
        ans = min(n - s1[0][1] - s2[1][1], n - s1[1][1] - s2[0][1])
    print(ans)

Solution (Python):
maxn=10**5+10
n=int(input())
b=[0]*maxn
c=[0]*maxn
a=input().split()

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

max1=max(b)
maxp=b.index(max1)
del b[maxp]
max2=max(b)

ans=0
for i in range(0,maxn):
    ans=max(ans,c[i]+(max2 if i==maxp else max1))

print(n-ans)

Solution (Python):
maxn=10**5+10
n=int(input())
a=[None]*(n+10)
b=[0]*maxn
c=[0]*maxn
a[1:n+1]=input().split()

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

max1=max2=maxp=0
for i in range(1,maxn):
    if b[i]>=max1:
        max2=max1
        maxp=i
        max1=b[i]
    elif b[i]>=max2:
        max2=b[i]

ans=n
for i in range(1,maxn):
    res=((n+1)//2-c[i])
    if i==maxp:
        res+=n//2-max2
    else:
        res+=n//2-max1
    ans=min(ans,res)

print(ans)

Solution (Python):
import collections

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

a_odd=list([int(a[i]) for i in range(n) if i%2==1])
a_even=list([int(a[i]) for i in range(n) if i%2==0])

ca_odd=collections.Counter(a_odd)
ca_even=collections.Counter(a_even)

def count_change(a_sublist, i):
    return len([num for num in a_sublist if num!=i])

loop_set_a_odd=set ([i[0] for i in ca_odd.most_common()[0:min(len(ca_odd),2)]])
loop_set_a_even=set( [ i[0] for i in ca_even.most_common()[0:min(len(ca_even),2)]])

temp=n
for i in loop_set_a_odd:
    for j in loop_set_a_even:
        if i!=j:
            c=count_change(a_odd,i)+count_change(a_even,j)
            if temp>c:
                temp=c

if temp==n:
    print(len(a_odd))
else:
    print(temp)

Solution (Python):
iipt=lambda:int(input())
miipt=lambda:map(int,input().split(" "))
o=[0]*112345
e=[0]*112345
n=iipt()
A=miipt()
for i,a in enumerate(A):
    if i%2:
        o[a]+=1
    else:
        e[a]+=1
om=-1,0
om2=-1,0
em=-1,0
em2=-1,0
for i,v in enumerate(o):
    if v>=om[1]:
        om2=om
        om=i,v
    elif v>=om2[1]:
        om2=i,v
for i,v in enumerate(e):
    if v>=em[1]:
        em2=em
        em=i,v
    elif v>=em2[1]:
        em2=i,v
if om[0]==em[0]:
    print(min(n-om2[1]-em[1],n-om[1]-em2[1]))
else:
    print(n-om[1]-em[1])

Solution (Python):
import collections
import numpy as np

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


npv = np.array( v, dtype=np.int32)

npv_dic = {}
npv_dic['even'] = npv[0::2]
npv_dic['odd']  = npv[1::2]






dict0 = collections.Counter(npv_dic['even'])
dict1 = collections.Counter(npv_dic['odd'])

list0 = list(dict0.items())
list1 = list(dict1.items())

list0.sort(key= lambda x:x[1], reverse=True)
list1.sort(key= lambda x:x[1], reverse=True)




if list0[0][0] == list1[0][0]:
    if (list0[0][1] == list1[0][1]) and \
        (list0.__len__() > 1) and (list0.__len__() > 1):
        if list0[1][1] > list1[1][1]:
            del list0[0]
        else:
            del list1[0]
    elif list0[0][1] > list1[0][1]:
        del list1[0]
    else:
        del list0[0]



if list0.__len__() != 0:
    change0 = n//2 - list0[0][1]
else:
    change0 = n//2
if list1.__len__() != 0:
    change1 = n//2 - list1[0][1]
else:
    change1 = n//2


print(change0 + change1)

Solution (Python):
import collections
import numpy as np

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


npv = np.array( v, dtype=np.int32)

npv_dic = {}
npv_dic['even'] = npv[0::2]
npv_dic['odd']  = npv[1::2]






dict0 = collections.Counter(npv_dic['even'])
dict1 = collections.Counter(npv_dic['odd'])

list0 = list(dict0.items())
list1 = list(dict1.items())

list0.sort(key= lambda x:x[1], reverse=True)
list1.sort(key= lambda x:x[1], reverse=True)




if list0[0][0] == list1[0][0]:
    if (list0[0][1] == list1[0][1]) and \
        (list0.__len__() > 1) and (list0.__len__() > 1):
        if list0[1][1] > list1[1][1]:
            del list0[0]
        else:
            del list1[0]
    elif list0[0][1] > list1[0][1]:
        del list1[0]
    else:
        del list0[0]



if list0.__len__() != 0:
    change0 = n//2 - list0[0][1]
else:
    change0 = n//2
change1 = n//2 - list1[0][1]


print(change0 + change1)

Solution (Python):
from collections import Counter
import sys
N=int(input())
v=[int(i) for i in input().split()]
A=[]
B=[]
for i in range(N):
    if i%2==0:
        A.append(v[i])
    else:
        B.append(v[i])
S=Counter(A).most_common(2)+[(0,0)]
T=Counter(B).most_common(2)+[(0,0)]
if S[0][0]!=T[0][0]:
    print(N-S[0][1]-T[0][1])
    sys.exit()
a=S[0][1]+T[1][1]
b=S[1][1]+T[0][1]
c=max(a,b)
print(N-c)

Solution (Python):



def get_line():
    return input()


def get_tokens():
    return get_line().split()


def get_ints():
    return [int(_) for _ in get_tokens()]


from collections import defaultdict


def main():
    n, = get_ints()
    v = get_ints()

    tot = [0, 0]
    cnt = [defaultdict(int), defaultdict(int)]

    for i in range(n):
        tot[i % 2] += 1
        cnt[i % 2][v[i]] += 1

    p = [[], []]
    for r in [0, 1]:
        p[r] = [(v, k) for k, v in cnt[r].items()] + [(0, -1 - r)]
        p[r].sort()
        p[r] = p[r][-2:]

    ans = n

    for x in p[0]:
        for y in p[1]:
            if x[1] != y[1]:
                ans = min(ans, n - x[0] - y[0])

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter


def main():
    n = int(input())
    v = [int(i) for i in input().split()]
    ans = 0
    odd = Counter(v[1::2])
    even = Counter(v[::2])
    odd_mosts = odd.most_common(2)
    even_mosts = even.most_common(2)
    if odd_mosts[0][0] == even_mosts[0][0]:
        if len(odd) == len(even) == 1:
            ans = n//2
        else:
            ans_sel = []
            ans_sel.append(n//2-odd_mosts[0][1]+n//2-even_mosts[1][1])
            ans_sel.append(n//2-odd_mosts[1][1]+n//2-even_mosts[0][1])
            ans = min(ans_sel)
    else:
        ans+=(n//2-odd_mosts[0][1])
        ans+=(n//2-even_mosts[0][1])
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict

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

v_odd = []
v_even = []

for i in range(n//2):
    v_odd.append(v[i*2])
    v_even.append(v[i*2+1])

d_odd = defaultdict(int)
d_even = defaultdict(int)

for x in v_odd:
    d_odd[x] += 1
for x in v_even:
    d_even[x] += 1

l_odd = list(d_odd.values())
l_even = list(d_even.values())
item_odd = list(d_odd)
item_even = list(d_even)

max_odd = max(l_odd)
max_even = max(l_even)
fin_max = max_odd + max_even
max_odd_l, max_even_l = [], []

for i,x in enumerate(l_odd):
    if x == max_odd:
        max_odd_l.append(i)

for i,x in enumerate(l_even):
    if x == max_even:
        max_even_l.append(i)

if len(max_odd_l) == 1 and len(max_even_l) == 1:
    if item_odd[max_odd_l[0]] == item_even[max_even_l[0]]:
        
        l_odd.pop(max_odd_l[0])
        l_even.pop(max_even_l[0])
        second_odd, second_even = 0, 0
        if l_odd:
            second_odd = max(l_odd)
        else:
            second_odd = 0
        if l_even:
            second_even = max(l_even)
        else:
            second_even = 0
        fin_max = max(max_odd+second_even, max_even+second_odd)

print(n - fin_max)

Solution (Python):
from collections import Counter


def main():
    r"""
    数列 a1,a2,...,anが以下の条件を満たすとき、 /\/\/\/ と呼ぶ

        各 i=1,2...,n-2 について、ai=ai+2
        数列に現れる数はちょうど 2種類偶数長の数列

    v1,v2,...,vnが与えられます
    要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。
    書き換える要素の数は最小でいくつになるか求めてください。

    2 <= n <= 10^5, nは偶数
    1 <= vi <= 10^5, viは整数
    """
    n = int(input())
    *v, = map(int, input().split())

    ans = f(n, v)
    assert ans == simple(n, v)
    print(ans)


def simple(n, v):
    
    
    c1 = Counter(v[::2]).most_common() + [(0, 0)]
    c2 = Counter(v[1::2]).most_common() + [(0, 0)]

    if c1[0][0] == c2[0][0]:
        n_no_change = max(c1[0][1] + c2[1][1],
                          c1[1][1] + c2[0][1])
        return n - n_no_change
    else:
        return n - c1[0][1] - c2[0][1]

def f(n, v):
    """
    3 1 3 2:
        3種類
        a1=a3, a2 != a4
    """
    ans = float("inf")
    v_idx_even = []
    v_idx_odd = []
    for i, x in enumerate(v):
        if i % 2 == 0:
            v_idx_even.append(x)
        else:
            v_idx_odd.append(x)

    ve = Counter(v_idx_even)
    vo = Counter(v_idx_odd)

    if len(ve) == 1 and len(vo) == 1:
        
        ans = 0
        if ve.most_common()[0][0] == vo.most_common()[0][0]:
            ans = n // 2

    elif len(ve) == 1 or len(vo) == 1:
        
        idx = 0
        if ve.most_common()[0][0] == vo.most_common()[0][0]:
            idx = 1
        if len(ve) == 1:
            ans = n // 2 - vo.most_common()[idx][1]
        else:
            ans = n // 2 - ve.most_common()[idx][1]

    else:
        
        if ve.most_common()[0][0] != vo.most_common()[0][0]:
            ans = n - ve.most_common()[0][1] - vo.most_common()[0][1]
        else:
            ans = n - \
                max(ve.most_common()[0][1] + vo.most_common()[1][1],
                    ve.most_common()[1][1] + vo.most_common()[0][1])

    return ans


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
w=sorted(a for a in v[0::2])
x=sorted(a for a in v[1::2])
a=[[0,i]for i in range(10**5+1)]
b=[[0,i]for i in range(10**5+1)]
for t in w:
    a[t][0]+=1
for t in x:
    b[t][0]+=1
c=sorted(a)
d=sorted(b)
e=c[len(c)-1][0]
i=c[len(c)-1][1]
f=d[len(d)-1][0]
g=c[len(c)-1][0]
h=d[len(d)-1][0]
for t in range(len(c)):
    if i!=d[len(d)-1][1]:break
    e=c[len(c)-t-1][0]
    i=c[len(c)-t-1][1]
i=d[len(d)-1][1]
for t in range(len(d)):
    if i!=c[len(c)-1][1]:break
    g=d[len(d)-t-1][0]
    i=d[len(d)-t-1][1]
print(min(n-e-f,n-g-h))

Solution (Python):
n=int(input())
*v,=map(int,input().split())
a=[[0,i]for i in range(10**5+1)]
b=[[0,i]for i in range(10**5+1)]
for t,u in zip(sorted(v[::2]),sorted(v[1::2])):a[t][0]+=1;b[u][0]+=1
a.sort(reverse=1)
b.sort(reverse=1)
print(n-a[0][0]-[max(a[1][0],b[1][0]),b[0][0]][a[0][1]!=b[0][1]])

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

v1 = V[0::2]
v2 = V[1::2]

c1 = Counter(v1).most_common()
c2 = Counter(v2).most_common()


c1.append((0,0))
c2.append((0,0))

if c1[0][0]==c2[0][0]:
    print(min(N-(c1[0][1]+c2[1][1]), N-(c1[1][1]+c2[0][1])))
else:
    print(N- (c1[0][1]+c2[0][1]))

Solution (Python):
from collections import Counter
from itertools import takewhile

n = int(input())
vvv = list(map(int, input().split()))
cnt1 = Counter(vvv[0::2])
cnt2 = Counter(vvv[1::2])
mc1 = cnt1.most_common()
mc2 = cnt2.most_common()
mcs1 = list(takewhile(lambda x: x[1] == mc1[0][1], mc1))
mcs2 = list(takewhile(lambda x: x[1] == mc2[0][1], mc2))
if len(mcs1) == len(mcs2) and mcs1[0][0] == mcs2[0][0]:
    if len(mc1) > 1:
        if len(mc2) > 1:
            print(min(n - mc1[0][1] - mc2[1][1], n - mc1[1][1] - mc2[0][1]))
        else:
            print(min(n - mc1[0][1], n - mc1[1][1] - mc2[0][1]))
    else:
        if len(mc2) > 1:
            print(min(n - mc1[0][1] - mc2[1][1], n - mc2[0][1]))
        else:
            print(min(n - mc1[0][1], n - mc2[0][1]))
else:
    print(n - mc1[0][1] - mc2[0][1])

Solution (Python):
from copy import *
n=int(input())
arr=list(map(int,input().split()))
arr1=[]
arr2=[]
for i in range(1,100001):
	arr1.append([0,i])
	arr2.append([0,i])

for i in range(0,n,2):
	arr1[arr[i]-1][0]+=1


for i in range(1,n,2):
	arr2[arr[i]-1][0]+=1
arr1.sort(reverse=True)
arr2.sort(reverse=True)

if(arr1[0][1]==arr2[0][1]):
	print(min(n-arr1[0][0]-arr2[1][0],n-arr1[1][0]-arr2[0][0]))	
else:
	print(n-arr1[0][0]-arr2[0][0])

Solution (Python):
def solv(arr):
    cnt = [[0, i] for i in range(100000+1)]
    for x in arr:
        cnt[x][0] += 1
    cnt.sort()
    cnt.reverse()
    return cnt


n = int(input())
v = [int(x) for x in input().split()]
even = []
odd = []
for i in range(len(v)):
    if i % 2 == 0:
        even.append(v[i])
    else:
        odd.append(v[i])
cnt1 = solv(even)
cnt2 = solv(odd)
ans = min(n-cnt1[0][0]-cnt2[1][0], n-cnt1[1][0]-cnt2[0][0]
          ) if cnt1[0][1] == cnt2[0][1] else n - cnt1[0][0] - cnt2[0][0]
print(ans)

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

from collections import Counter
N = int(input())
V = list(map(int, input().split()))




def func(l, aa):
    counter = Counter(l)
    if counter[aa] == 0:
        c, count = counter.most_common()[0]
    else:
        c, count = counter.most_common()[1]
    
    return (c, len(l) - count)


if len(set(V)) == 1:
    print(N // 2)
else:
    c, count = func(V[::2], -1)
    c2, count2 = func(V[1::2], c)
    a = count + count2
    c2, count2 = func(V[1::2], -1)
    c, count = func(V[::2], c2)
    print(min(a, count + count2))

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

odd = Counter([v[i] for i in range(1, n, 2)])
even = Counter([v[i] for i in range(0, n, 2)])

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

Solution (Python):


from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

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

cnt1 = [0] * 110000
cnt2 = [0] * 110000

for i in range(0, N, 2):
    cnt1[v[i]] += 1
    cnt2[v[i + 1]] += 1

v1, v2 = [], []
for i in range(110000):
    v1.append((cnt1[i], i))
    v2.append((cnt2[i], i))

v1.sort(reverse = True)
v2.sort(reverse = True)

if v1[0][1] != v2[0][1]:
    print N - v1[0][0] - v2[0][0]
else:
    print N - max(v1[1][0] + v2[0][0], v1[0][0] + v2[1][0])

Solution (Python):
from collections import Counter
n = int(input())
V = list(map(int, input().split()))
c1 = Counter(V[::2])
c2 = Counter(V[1::2])
c1[0] = 0
c2[0] = 0
(x, cx), (_, cxx) = c1.most_common(2)
(y, cy), (_, cyy) = c2.most_common(2)
if x == y:
    print(n - max(cx + cyy, cy + cxx))
else:
    print(n - cx - cy)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c1 = Counter(A[::2])
c2 = Counter(A[1::2])
c1[0] = 0
c2[0] = 0
c1m = max(c1.items(), key=lambda x:x[1])
c2m = max(c2.items(), key=lambda x:x[1])
c1c2 = max(c for k,c in c2.items() if c1m[0]!=k)
c2c1 = max(c for k,c in c1.items() if c2m[0]!=k)
print(min(N - c1m[1] - c1c2, N - c2m[1] - c2c1))

Solution (Python):
from collections import Counter as C
n = int(input())
v = [int(a) for a in input().split()]

a=C(v[::2])
b=C(v[1::2])
a[0]=b[0]=0
a=a.most_common()
b=b.most_common()
if a[0][0] != b[0][0]:
    print (n-a[0][1]-b[0][1])
else:
    print (min(n-a[1][1]-b[0][1],n-a[0][1]-b[1][1]))

Solution (Python):


def main():
    n = int(input())
    vn = list(map(int, input().split()))
    even = count(vn, n, True)
    odd = count(vn, n, False)
    e1k, e1v, e2k, e2v = largest(even)
    o1k, o1v, o2k, o2v = largest(odd)
    res = solve(e1k, e1v, e2k, e2v, o1k, o1v, o2k, o2v, n)
    print(res)

def solve(e1k, e1v, e2k, e2v, o1k, o1v, o2k, o2v, n):
    if e1k != o1k:
        return n - e1v - o1v
    return min(n - e1v - o2v, n - e2v - o1v)

def count(vn, n, is_even):
    di = {}
    st = 0 if is_even else 1
    for i in range(st, n, 2):
        v = vn[i]
        if v in di:
            di[v] += 1
        else:
            di[v] = 1
    return di

def largest(di):
    li_tu = []
    for k in di:
        tu = (k, di[k])
        li_tu.append(tu)
    li_tu = sorted(li_tu, reverse=True, key=lambda x: x[1])
    assert len(li_tu) >= 1
    lg_key = li_tu[0][0]
    lg_val = li_tu[0][1]
    if len(li_tu) == 1:
        sc_key = 0
        sc_val = 0
    else:
        sc_key = li_tu[1][0]
        sc_val = li_tu[1][1]
    return lg_key, lg_val, sc_key, sc_val

main()

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

eve = {}
odd = {}

for i in range(len(vs)):
    if i % 2 == 0:
        if vs[i] in eve:
            eve[vs[i]] += 1
        else:
            eve[vs[i]] = 1
    else:
        if vs[i] in odd:
            odd[vs[i]] += 1
        else:
            odd[vs[i]] = 1

es = sorted(eve.items(), key=lambda x: -x[1])
os = sorted(odd.items(), key=lambda x: -x[1])

if es[0][0] == os[0][0]:
    if es[0][1] > os[0][1]:
        del es[0]
        if len(os) > 1 :
            del os[1]
    elif es[0][1] < os[0][1]:
        del os[0]
        if len(es) > 1 :
            del es[1]
    else:
        if len(es) == 1 and len(os) == 1:
            del os[0]
        elif len(es) == 1 and len(os) != 1:
            del es[0]
            del os[1]
        elif len(es) != 1 and len(os) == 1:
            del es[1]
            del os[0]
        else:
            if es[1][1] < os[1][1]:
                del es[0]
                del os[1]
            else:
                del es[1]
                del os[0]
else:
    del os[0]
    del es[0]

trans = 0

for i in range(len(es)):
    trans += es[i][1]
for i in range(len(os)):
    trans += os[i][1]

print(trans)

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

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

even = Counter(a[::2])
odd = Counter(a[1::2])

es = even.most_common(2)
os = odd.most_common(2)

es = es + [(0,0)]
os = os + [(0,0)]

if es[0][0] != os[0][0]:
    print((n//2-es[0][1]) + (n//2-os[0][1]))
else:
    print(min((n//2-es[1][1]) + (n//2-os[0][1]),
              (n//2-es[0][1]) + (n//2-os[1][1])))

Solution (Python):
N=int(input())
v=[int(i) for i in input().split()]
if N==2:
    if v[0]==v[1]:
        print(1)
        exit()
    else:
        print(0)
        exit()
A=dict()
B=dict()
L=0
R=0
def inc(D,k):
    if k in D:
        D[k]+=1
    else:
        D[k]=1
for i in range(N):
    if i%2==0:
        L+=1
        inc(A,v[i])
    else:
        R+=1
        inc(B,v[i])
X=[(L,-1)]
Y=[(R,-2)]
for i in A:
    X.append((L-A[i],i))
for i in B:
    Y.append((R-B[i],i))
X.sort(reverse=True)
Y.sort(reverse=True)
if X[-1][1]!=Y[-1][1]:
    print(X[-1][0]+Y[-1][0])
else:
    vl=X[-1][0]+Y[-2][0]
    vr=X[-2][0]+Y[-1][0]
    print(min(vl,vr))

Solution (Python):
from collections import Counter
n = int(input().strip())
vs = [int(i) for i in input().split(' ')]
vs1 = vs[::2]
vs2 = vs[1::2]
a = Counter(vs1).most_common()
b = Counter(vs2).most_common()

if a[0][0] != b[0][0]:
    print(n - a[0][1] - b[0][1])
else:
    candidates = []
    if len(a) != 1:
        candidates.append(n - a[1][1] - b[0][1])
    if len(b) != 1:
        candidates.append(n - a[0][1] - b[1][1])
    if len(candidates) != 0:
        print(min(candidates))
    else:
        print(n//2)

Solution (Python):
from collections import Counter
n = int(input().strip())
vs = [int(i) for i in input().split(' ')]
vs1 = vs[::2]
vs2 = vs[1::2]
a = Counter(vs1).most_common()
b = Counter(vs2).most_common()

if a[0][0] != b[0][0]:
    print(n - a[0][1] - b[0][1])
else:
    candidates = []
    if len(a) != 1:
        candidates.append(n - a[1][1] - b[0][1])
    if len(b) != 1:
        candidates.append(n - a[0][1] - b[1][1])
    if len(candidates) != 0:
        print(min(candidates))
    else:
        print(n//2)

Solution (Python):
from collections import Counter

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

A = V[::2]
B = V[1::2]

resA = Counter(A).most_common()
resB = Counter(B).most_common()

if resA[0][0] == resB[0][0]:

    ans1 = sum([num for x, num in resA[1:]]) + resB[0][1] + sum([num for x, num in resB[2:]])
    ans2 = sum([num for x, num in resB[1:]]) + resA[0][1] + sum([num for x, num in resA[2:]])
    print(min(ans1, ans2))

else:
    if len(resA) == 1 and len(resB) == 1:
        print(0)
    else:
        sumA = sum([num for x, num in resA[1:]])
        sumB = sum([num for x, num in resB[1:]])
        print(sumA + sumB)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
l1 = [li for i, li in enumerate(l) if i % 2 == 0]
l2 = [li for i, li in enumerate(l) if i % 2 == 1]
def cnt(l):
    d = {}
    for li in l:
        if li in d:
            d[li] += 1
        else:
            d[li] = 1
    d = [(li, cnt) for li, cnt in d.items()]
    return sorted(d, key=lambda di: di[1], reverse=True)

k1 = cnt(l1)[:2]
k2 = cnt(l2)[:2]
ans = 10000000
if k1[0][0] != k2[0][0]:
    ans = n - k1[0][1] - k2[0][1]
if len(k1) == 2:
    ans = min(ans, n - k1[1][1] - k2[0][1])
if len(k2) == 2:
    ans = min(ans, n - k1[0][1] - k2[1][1])
if ans == 10000000:
    ans = n - max(k1[0][1], k2[0][1])
print(ans)

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

v_e_cnt = [0 for i in range(10**6)]
v_o_cnt = [0 for i in range(10**6)]
for x in range(n):
	if x % 2 == 0:
		v_e_cnt[v[x]] += 1
	else:
		v_o_cnt[v[x]] += 1

max_e = [(0,0),(0,0)]
max_o = [(0,0),(0,0)]
for i in range(10**5+1):
	if max_e[1][0] < v_e_cnt[i]:
		if max_e[0][0] < v_e_cnt[i]:
			max_e[1] = max_e[0]
			max_e[0] = (v_e_cnt[i], i)
		else:
			max_e[1] = (v_e_cnt[i], i)
	if max_o[1][0] < v_o_cnt[i]:
		if max_o[0][0] < v_o_cnt[i]:
			max_o[1] = max_o[0]
			max_o[0] = (v_o_cnt[i], i)
		else:
			max_o[1] = (v_o_cnt[i], i)

ans = n - max_e[0][0] - max_o[0][0]
if max_e[0][1] == max_o[0][1]:
	ans = n - max(max_e[0][0] + max_o[1][0], max_e[1][0] + max_o[0][0])

print(ans)

Solution (Python):
from collections import Counter
import numpy


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

even = a[0::2]
odd= a[1::2]
even_counter = Counter(even)
odd_counter = Counter(odd)


c = even_counter.most_common()[0][0]
d = odd_counter.most_common()[0][0]

cnt = 0
if even_counter.most_common()[0][0] == odd_counter.most_common()[0][0]:
	if len(even_counter.most_common())==1 and len(odd_counter.most_common())==1:
		print(int(n/2))
		quit()
	elif len(even_counter.most_common())!=1 and len(odd_counter.most_common())==1:
		c = even_counter.most_common()[1][0]
	elif len(even_counter.most_common())==1 and len(odd_counter.most_common())!=1:
		d = odd_counter.most_common()[1][0]
	else:
		if len(even_counter.most_common())<len(odd_counter.most_common()):
			c = even_counter.most_common()[1][0]
		else:
			d  = odd_counter.most_common()[1][0]
            
    	
for i in range(int(n/2)):
	if a[i*2] != c:
		cnt = cnt+1
	if a[i*2+1] != d:
		cnt = cnt+1

print(cnt)