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

odds = v[1::2]
evens = v[::2]
o = Counter(odds)
e = Counter(evens)
omx, *ol = sorted(o.items(), reverse=True, key=lambda x: x[1])
emx, *el = sorted(e.items(), reverse=True, key=lambda x: x[1])

if omx[0] != emx[0]:
    ans = n - omx[1] - emx[1]
else:
    if ol:
        ol = ol[0]
    else:
        ol = (0, 0)

    if el:
        el = el[0]
    else:
        el = (0, 0)

    a = n - omx[1] - el[1]
    b = n - emx[1] - ol[1]
    ans = min(a, b)

print(ans)

Solution (Python):
n, *v = map(int, open(0).read().split())

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

a.sort(key=lambda x:-x[1])
b.sort(key=lambda x:-x[1])

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

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
s1,s2=[],[]
for i in range(n):
  if i%2==0:
    s1.append(v[i])
  else:
    s2.append(v[i])
c1=Counter(s1)
c2=Counter(s2)
d1=c1.most_common()
d2=c2.most_common()
if d1[0][0]!=d2[0][0]:
  print(n-d1[0][1]-d2[0][1])
else:
  if len(d1)>1 and len(d2)>1:
    print(min(n-d1[0][1]-d2[1][1],n-d1[1][1]-d2[0][1]))
  elif len(d1)==1 and len(d2)==1:
    print(n//2)
  elif len(d1)==1:
    print(n//2-d2[0][1])
  else:
    print(n//2-d1[0][1])

Solution (Python):
from collections import Counter
N = int(input())
a = list(map(int,input().split()))
E = []
O = []
for k in range(N):
    if k%2 == 0:
        E.append(a[k])
    else:
        O.append(a[k])
e = Counter(E).most_common()
o = Counter(O).most_common()

if e[0][0] != o[0][0]:
    print(N-e[0][1]-o[0][1])
else:
    if len(e) >= 2 and len(o) >= 2:
        print(N-e[0][1]-max(e[1][1],o[1][1]))
    elif len(e) >= 2 and len(o) == 1:
        print(N//2-e[1][1])
    elif len(e) == 1 and len(o) >= 2:
        print(N//2-o[1][1])
    else:
        print(N//2)

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

dl = {}
du = {}

for i in range(n):
  v = l[i]
  if i%2 == 0:
    if v in dl:
      dl[v] += 1
    else:
      dl[v] = 1
  else:
    if v in du:
      du[v] += 1
    else:
      du[v] = 1

if max(dl, key=dl.get) != max(du, key=du.get):
  ans = n - max(dl.values()) - max(du.values())
else:
  vsl = list(dl.values())
  vsl.sort(reverse=True)
  vsu = list(du.values())
  vsu.sort(reverse=True)
  if len(vsl) == 1 or len(vsu) == 1:
    ans = n//2
  else:
    ans = min(n-vsu[0]-vsl[1], n-vsl[0]-vsu[1])

print(ans)

Solution (Python):
n = int(input())
evens, odds = {}, {}
for i, v in enumerate(list(map(int, input().split()))):
    if i % 2 == 0:
        if v in evens:
            evens[v] += 1
        else:
            evens[v] = 1
    else:
        if v in odds:
            odds[v] += 1
        else:
            odds[v] = 1
evens = sorted(evens.items(), key=lambda x: x[1], reverse=True)
odds = sorted(odds.items(), key=lambda x: x[1], reverse=True)
if len(evens) == 1 and len(odds) == 1:
    if evens[0][0] == odds[0][0]:
        print(n // 2)
    else:
        print(0)
else:
    if evens[0][0] == odds[0][0]:
        if len(evens) == 1:
            print(n // 2 - odds[1][0])
        elif len(odds) == 1:
            print(n // 2 - evens[1][0])
        else:
            print(
                min(n // 2 - evens[0][1] + n // 2 - odds[1][1],
                    n // 2 - evens[1][1] + n // 2 - odds[0][1]))
    else:
        print(n // 2 - evens[0][1] + n // 2 - odds[0][1])

Solution (Python):


from collections import Counter


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


even_list = []
odd_list = []
for i in range(n):
    if (i+1)%2:
        even_list.append(v_list[i])
    else:
        odd_list.append(v_list[i])
e_len = len(even_list)
o_len = len(odd_list)

even_counter = Counter(even_list).most_common()
odd_counter = Counter(odd_list).most_common()

if len(even_counter)==1:
    even_counter.append((0, 0))
if len(odd_counter)==1:
    odd_counter.append((0, 0))

if not even_counter[0][0]==odd_counter[0][0]:
    even_count = e_len - even_counter[0][1] 
    odd_count = o_len - odd_counter[0][1] 
    print(even_count + odd_count)
else:
    even_count_1 = e_len - even_counter[0][1]
    odd_count_1 = o_len - odd_counter[1][1]
    cost_1 = even_count_1 + odd_count_1

    even_count_2 = e_len - even_counter[1][1]
    odd_count_2 = o_len - odd_counter[0][1]
    cost_2 = even_count_2 + odd_count_2

    ans = min(cost_1, cost_2)
    print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1:
    print(n//2)
    exit()

a1=a[::2]
a2=a[1::2]

import collections

c1=collections.Counter(a1)
c2=collections.Counter(a2)

cc1=c1.most_common(2)
cc2=c2.most_common(2)

if len(cc1)==1:
    print(n//2-cc2[0][1])
elif len(cc2)==1:
    print(n//2-cc1[0][1])
elif cc1[0][0]!=cc2[0][0]:
    print(n-cc1[0][1]-cc2[0][1])
elif cc1[0][0]==cc2[0][0]:
    if cc1[1][1]>=cc2[1][1]:
        print(n-cc1[1][1]-cc2[0][1])
    else:
        print(n-cc1[0][1]-cc2[1][1])

Solution (Python):

from collections import Counter
n = int(input())
v = [int(i) for i in input().split()] 

a1 = [0 for _ in range(n // 2)]
a2 = [0 for _ in range(n // 2)]
for i in range(n):
    if i % 2 == 0:
        a1[i // 2] = v[i]
    elif i % 2 == 1:
        a2[i // 2] = v[i]


tmp_a1 = Counter(a1)
tmp_a2 = Counter(a2)

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

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

Vodd = V[1::2]
Veven = V[::2]

from collections import Counter

Vodd = sorted(Counter(Vodd).items(), key=lambda x:x[1])
Veven = sorted(Counter(Veven).items(), key=lambda x:x[1])

if Vodd[-1][0] == Veven[-1][0]:
    if len(Vodd) == len(Veven) == 1:
        ans = N - Vodd[-1][1]
    elif len(Vodd) == 1:
        ans = N - Vodd[-1][1] - Veven[-2][1]
    elif len(Veven) == 1:
        ans = N - Vodd[-2][1] - Veven[-1][1]
    elif Vodd[-2][1] >= Veven[-2][1]:
        ans = N - Vodd[-2][1] - Veven[-1][1]
    else:
        ans = N - Vodd[-1][1] - Veven[-2][1]
else:
    ans = N - Vodd[-1][1] - Veven[-1][1]


print(ans)

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
v1 = v[0::2]
v2 = v[1::2]
v1.sort()
v2.sort()
v1_hind = dict()
v2_hind = dict()
v1_hind[v1[0]] = 1
v2_hind[v2[0]] = 1
for i in range(1, len(v1)):
    if v1[i] != v1[i-1]:
        v1_hind[v1[i]] = 0
    if v2[i] != v2[i-1]:
        v2_hind[v2[i]] = 0
    v1_hind[v1[i]] += 1
    v2_hind[v2[i]] += 1
v1_it = list(v1_hind.items())
v2_it = list(v2_hind.items())
v1_it.sort(key=lambda x: x[1], reverse=True)
v2_it.sort(key=lambda x: x[1], reverse=True)
if v1_it[0][0] != v2_it[0][0]:
    print(len(v1)-v1_it[0][1] + len(v2)-v2_it[0][1])
elif v1_it[0][0] == v2_it[0][0] and len(v2_it) == 1:
    print(len(v2))
else:
    print(min(len(v1) - v1_it[0][1] + len(v2) - v2_it[1][1],
          len(v1) - v1_it[1][1] + len(v2) - v2_it[0][1]))

Solution (Python):
N=int(input())
V=[int(i) for i in input().split()]
K=list(set(V))
if len(K)==1:
    print(N//2)
    exit()

cnt={}
cnt[-1]=0
for k in K:
    cnt[k]=0
for i in range(0,N,2):
    cnt[V[i]]+=1
ev_MAX=0
sec_ev_MAX=0
ev=-1
ev_cnt=[(cnt[k],k) for k in K]
ev_cnt.sort(key=lambda x: x[0],reverse=True)
ev=ev_cnt[0][1]
ev_MAX=ev_cnt[0][0]
sec_ev_MAX=0 if len(ev_cnt)<2 else ev_cnt[1][0]

cnt={}
cnt[-1]=0
for k in K:
    cnt[k]=0
for i in range(1,N,2):
    cnt[V[i]]+=1
od_MAX=0
sec_od_MAX=0
od=-1
od_cnt=[(cnt[k],k) for k in K]
od_cnt.sort(key=lambda x: x[0],reverse=True)
od=od_cnt[0][1]
od_MAX=od_cnt[0][0]
sec_od_MAX=0 if len(od_cnt)<2 else od_cnt[1][0]

ans=0
if od!=ev:
    
    ans+=N//2-ev_MAX
    ans+=N//2-od_MAX
else:
    
    ans+=min(N//2-sec_ev_MAX+N//2-od_MAX,N//2-sec_od_MAX+N//2-ev_MAX)
print(ans)

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

from collections import Counter
def solve():
    a1 = Counter(v[i] for i in range(0,n,2)).most_common(2)
    a2 = Counter(v[i] for i in range(1,n,2)).most_common(2)

    n1 = a1[0][1]
    n2 = a2[0][1]

    if a1[0][0] == a2[0][0]:
        if len(a1) <= 1:
            if len(a2) > 1: n2 = a2[1][1]
            else: n2 = 0
        elif len(a2) <= 1:
            if len(a1) > 1: n1 = a1[1][1]
            else: n1 = 0
        elif n1 - a1[1][1] < n2 - a2[1][1]:
            n1 = a1[1][1]
        else:
            n2 = a2[1][1]
    print(n-n1-n2)

solve()

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    odd = A[::2]
    even = A[1::2]
    from collections import Counter
    c_odd = Counter(odd)
    c_even = Counter(even)
    ans = 0
    odd_first = c_odd.most_common()[0][1]
    odd_second = c_odd.most_common()[1][1] if odd_first != N//2 else 0
    even_first = c_even.most_common()[0][1]
    even_second = c_even.most_common()[1][1] if even_first != N//2 else 0
    if c_odd.most_common()[0][0] != c_even.most_common()[0][0]:
        ans = N - odd_first - even_first
    else:
        if odd_first > even_first:
            ans = N - odd_first - even_second
        elif odd_first < even_first:
            ans = N - odd_second - even_first
        else:
            if even_second > odd_second:
                ans = N - even_second - odd_first
            else:
                ans = N - even_first - odd_second
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    H = N // 2
    V = [int(v) for v in input().split()]
    odd, even = dict(), dict()
    for i, v in enumerate(V):
        if i % 2 == 0:
            if v in even: even[v] += 1
            else: even[v] = 1
        else:
            if v in odd: odd[v] += 1
            else: odd[v] = 1

    evenL = [(0, 0), (0, 0)]
    evenMax = 0
    for key in even:
        if even[key] >= evenL[0][0]: evenL = [(even[key], key), evenL[0]]
        elif even[key] >= evenL[1][0]: evenL[1] = (even[key], key)
    oddL = [(0, 0), (0, 0)]
    for key in odd:
        if odd[key] >= oddL[0][0]: oddL = [(odd[key], key), oddL[0]]
        elif odd[key] >= oddL[1][0]: oddL[1] = (odd[key], key)


    if evenL[0][1] == oddL[0][1]: print(N - max(evenL[0][0] + oddL[1][0], evenL[1][0] + oddL[0][0]))
    else: print(N - evenL[0][0] - oddL[0][0])

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
v = LIST()
a = []
b = []
for i in range(0, n, 2):
    a.append(v[i])
for i in range(1, n, 2):
    b.append(v[i])
e = Counter(a).most_common()
f = Counter(b).most_common()
g = list(set(a) & set(b))
mns = e[0][1] + f[0][1]
for i in range(len(g)):
    if e[0][0] == g[i] and f[0][0] == g[i]:
        if len(e) > 1 and len(f) > 1:
            mns = max(e[1][1] + f[0][1], e[0][1] + f[1][1])
        elif len(e) > 1:
            mns = e[1][1] + f[0][1]
        elif len(f) > 1:
            mns = e[0][1] + f[1][1]
        else:
            mns = max(e[0][1], f[0][1])
print(n - mns)

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

Solution (Python):
from collections import Counter

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


even_num = items[::2]
odd_num = items[1::2]


dev = Counter(even_num).most_common(2)
dod = Counter(odd_num).most_common(2)

if dev[0][0] == dod[0][0] :
    if len(dev) == len(dod) == 1 :
        print(N//2)
    elif len(dev) < len(dod) :
        print(N//2 - dod[1][1])
    elif len(dev) > len(dod) :
        print(N//2 - dev[1][1])
    else :
        print(N - max(dod[1][1] + dev[0][1], dod[0][1] + dev[1][1]))
else :
    print(N - dod[0][1]- dev[0][1])

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

Vodd = V[1::2]
Veven = V[::2]

from collections import Counter

Vodd = sorted(Counter(Vodd).items(), key=lambda x:x[1])
Veven = sorted(Counter(Veven).items(), key=lambda x:x[1])

if Vodd[-1][0] == Veven[-1][0]:
    if len(Vodd) == len(Veven) == 1:
        ans = N - Vodd[-1][1]
    elif len(Vodd) == 1:
        ans = N - Vodd[-1][1] - Veven[-2][1]
    elif len(Veven) == 1:
        ans = N - Vodd[-2][1] - Veven[-1][1]
    elif Vodd[-2][1] >= Veven[-2][1]:
        ans = N - Vodd[-2][1] - Veven[-1][1]
    else:
        ans = N - Vodd[-1][1] - Veven[-2][1]
else:
    ans = N - Vodd[-1][1] - Veven[-1][1]


print(ans)

Solution (Python):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
even = Counter(v[::2])
odd = Counter(v[1::2])
em = even.most_common(1)[0]
om = odd.most_common(1)[0]
ans = 0
if em[0] != om[0]:
    ans = n - em[1] - om[1]
else:
    if len(even) == 1 and len(odd) == 1:
        ans = n // 2
    elif len(even) == 1:
        osm = odd.most_common(2)[1]
        ans = n - em[1] - osm[1]
    elif len(odd) == 1:
        esm = even.most_common(2)[1]
        ans = n - om[1] - esm[1]
    else:
        esm = even.most_common(2)[1]
        osm = odd.most_common(2)[1]
        ans = min(n - em[1] - osm[1], n - om[1] - esm[1])
print(ans)

Solution (Python):
from collections import Counter


n = int(input())
v = list(map(int, input().split()))
odd_cnt = Counter(v[0::2]).most_common() + ([(0, 0)])
even_cnt = Counter(v[1::2]).most_common() + ([(0, 0)])
if odd_cnt[0][0] != even_cnt[0][0]:
    ans = n - odd_cnt[0][1] - even_cnt[0][1]
else:
    ans = min(n - odd_cnt[1][1] - even_cnt[0][1], n - odd_cnt[0][1] - even_cnt[1][1])
print(ans)

Solution (Python):
from collections import Counter

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

if len(set(v)) == 1:
    print(n // 2)
else:
    v1 = [v[i] for i in range(0, n, 2)]
    v2 = [v[i + 1] for i in range(0, n, 2)]

    kw1 = Counter(v1)
    kw2 = Counter(v2)

    x1 = kw1.most_common()[0][0]
    x2 = kw2.most_common()[0][0]

    if x1 != x2:
        ans = 0
        for i in v1:
            if i != x1:
                ans += 1
        for i in v2:
            if i != x2:
                ans += 1
    else:
        y1 = kw1.most_common()[1][0]
        y2 = kw2.most_common()[1][0]

        ans1 = 0
        ans2 = 0

        for i in v1:
            if i != y1:
                ans1 += 1
        for i in v2:
            if i != x2:
                ans1 += 1

        for i in v1:
            if i != x1:
                ans2 += 1
        for i in v2:
            if i != y2:
                ans2 += 1

        ans = min(ans1, ans2)

    print(ans)

Solution (Python):
N = int(input())
v = [int(x) for x in input().split()]

even = v[::2]
odd = v[1::2]

from collections import Counter
dev = Counter(even).most_common(2)
dod = Counter(odd).most_common(2)

if dev[0][0] == dod[0][0] :
    if len(dev) == len(dod) == 1 :
        print(N//2)
    elif len(dev) < len(dod) :
        print(N//2 - dod[1][1])
    elif len(dev) > len(dod) :
        print(N//2 - dev[1][1])
    else :
        print(N - max(dod[1][1] + dev[0][1], dod[0][1] + dev[1][1]))
else :
    print(N - dod[0][1]- dev[0][1])

Solution (Python):

from collections import Counter

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

    odd_count = Counter(vlist[0::2]).most_common()
    even_count = Counter(vlist[1::2]).most_common()

    if odd_count[0][0] == even_count[0][0]:
        if len(odd_count) == len(even_count) == 1:
            print(n // 2)
        elif odd_count[0][1] > even_count[0][1]:
            print(n - odd_count[0][1] - even_count[1][1])
        elif odd_count[0][1] < even_count[0][1]:
            print(n - odd_count[1][1] - even_count[0][1])    
        else:
            if odd_count[1][1] > even_count[1][1]:
                print(n - even_count[0][1] - odd_count[1][1])
            else:
                print(n - odd_count[0][1] - even_count[1][1])
    else:
        print(n - odd_count[0][1] - even_count[0][1])


if __name__ == "__main__":
    submit()

Solution (Python):
import collections
N=int(input())
L=list(map(int,input().split()))
E=L[0::2]
O=L[1::2]
e = collections.Counter(E).most_common()
o = collections.Counter(O).most_common()
if e[0][0] != o[0][0]:
    print(N - e[0][1] - o[0][1])
else:
    if len(e) == 1 or len(o) == 1:
        print(N // 2)
    else:
        a = N - e[1][1] - o[0][1]
        b = N - e[0][1] - o[1][1]
        print(min(a, b))

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
a, b = [0] * 1000005, [0] * 1000005
for i in range(len(v)):
    if i % 2: a[v[i]] += 1
    else: b[v[i]] += 1
a2, b2 = [], []
for i in range(1000001):
    a2.append([a[i], i])
for i in range(1000001):
    b2.append([b[i], i])
a2.sort()
a2.reverse()
b2.sort()
b2.reverse()



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

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
a, b = [0] * 100005, [0] * 100005
for i in range(len(v)):
    if i % 2: a[v[i]] += 1
    else: b[v[i]] += 1
a2, b2 = [], []
for i in range(100001):
    a2.append([a[i], i])
for i in range(100001):
    b2.append([b[i], i])
a2.sort()
a2.reverse()
b2.sort()
b2.reverse()



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

Solution (Python):
from collections import defaultdict

def main():
    n = int(input())
    V = [int(e) for e in input().split()]

    De, Do = defaultdict(int), defaultdict(int)
    for i in range(0, n, 2):
        De[V[i]] += 1

    for i in range(1, n + 1, 2):
        Do[V[i]] += 1

    Des = sorted(De.items(), key=lambda x: -x[1])
    Dos = sorted(Do.items(), key=lambda x: -x[1])

    Des.append((-1, 0))
    Dos.append((-1, 0))

    ans = n - Des[0][1] - Dos[0][1]

    if Des[0][0] == Dos[0][0]:
        ans += min(Des[0][1] - Des[1][1], Dos[0][1] - Dos[1][1])

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
n, *A = map(int, open(0).read().split())

a0 = Counter(A[::2]).most_common(2)
a1 = Counter(A[1::2]).most_common(2)

if a0[0][0] == a1[0][0]:
    l0, l1 = len(a0), len(a1)
    if l0 == l1 == 1:
        print(n//2)
    elif l0 < l1:
        print(n//2 - a1[1][1])
    elif l0 > l1:
        print(n//2 - a0[1][1])
    else:
        print(n - max(a0[1][1] + a1[0][1], a0[0][1] + a1[1][1]))
else:
    print(n - a0[0][1] - a1[0][1])

Solution (Python):
from collections import Counter
n, *A = map(int, open(0).read().split())

a0 = Counter(A[::2]).most_common(2)
a1 = Counter(A[1::2]).most_common(2)

count = n
if a0[0][0] == a1[0][0]:
    if len(a0) == len(a1) == 1:
        count -= n//2
    elif len(a0) < len(a1):
        count -= n//2 - a1[1][1]
    elif len(a0) > len(a1):
        count -= n//2 - a0[1][1]
    else:
        count -= max(a0[1][1] + a1[0][1], a0[0][1] + a1[1][1])
else:
    count -= a0[0][1] + a1[0][1]
print(count)

Solution (Python):
def run_length_compress(string):
    """文字列をランレングス圧縮する
    例) string = "aabccaaabb" -> [(2, a), (1, b), (2, c), (3, a), (2, b)]
    """
    string.append(-1) 
    n = len(string)

    begin = 0
    end = 1
    cnt = 1
    ans = []
    while True:
        if end >= n:
            break
        if string[begin] == string[end]:
            end += 1
            cnt += 1
        else:
            ans.append((cnt, string[begin]))
            begin = end
            end = begin + 1
            cnt = 1

    return ans
  
n = int(input())
v = list(map(int, input().split()))
even = []
odd = []

for i in range(n):
    if i % 2 == 0:
        even.append(v[i])
    else:
        odd.append(v[i])
memo_o = {}
for num in odd:
    if num not in memo_o:
        memo_o[num] = 1
    else:
        memo_o[num] += 1

even = sorted(even)
even = run_length_compress(even)
even = sorted(even, reverse = True)
ans = 10 ** 9
for i in memo_o:
    tmp = n // 2 - memo_o[i]
    tmp2 = n // 2
    for cnt, num in even[:2]:
        if i != num:
            tmp2 = min(n // 2 - cnt, tmp2)
    ans = min(ans, tmp + tmp2)
print(ans)

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

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

a = Counter(v[0::2]).most_common()
b = Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
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):
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v1 = Counter(v[::2]).most_common()
v2 = Counter(v[1::2]).most_common()
v1.append((0,0))
v2.append((0,0))
ans = n
if v1[0][0]==v2[0][0]:
    ans -= max(v1[0][1]+v2[1][1],v1[1][1]+v2[0][1])
else:
    ans -= v1[0][1]+v2[0][1]
print(ans)

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
ans=0
x=dict()
y=dict()
z=dict()
for i in range(n):
    if v[i] in z:
        z[v[i]]+=1
    else:
        z[v[i]]=1
    if i%2==0:
        if v[i] in x:
            x[v[i]]+=1
        else:
            x[v[i]]=1
    else:
        if v[i] in y:
            y[v[i]]+=1
        else:
            y[v[i]]=1
c=len(z)
if c==1:
    ans=n//2
else:
    m1=0
    m2=0
    count=0
    flag=False
    for idx in y:
        if m1<y[idx]:
            tmp=idx
        m1=max(y[idx],m1)
    for idx in y:
        if m1==y[idx]:
            if tmp!=idx:
                flag=True
    for idx in x:
        if flag:
            m2=max(x[idx],m2)
        else:
            if idx!=tmp:
                m2=max(x[idx],m2)
    
    
    ans=(n//2-m1)+(n//2-m2)
    m1=0
    m2=0
    flag=False
    tmp=-1
    for idx in x:
        if m1<x[idx]:
            tmp=idx
        m1=max(x[idx],m1)
    for idx in x:
        if m1==x[idx]:
            if tmp!=idx:
                flag=True
    for idx in y:
        if flag:
            m2=max(y[idx],m2)
        else:
            if idx!=tmp:
                m2=max(y[idx],m2)
    ans=min(n-m1-m2,ans)
print(ans)

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

    even = v[::2]
    odd = v[1::2]
    count_e = collections.Counter(even)
    count_o = collections.Counter(odd)
    ce = count_e.most_common()
    co = count_o.most_common()
    if ce[0][0] != co[0][0]:
        print(n-ce[0][1] - co[0][1])
    else:
        if len(ce) == 1 and len(co) == 1:
            print(n//2)
        elif len(ce) == 1:
            print(n-co[1][1])
        elif len(co) == 1:
            print(n-ce[1][1])
        else:
            print(min(n-ce[0][1]-co[1][1], n-ce[1][1]-co[0][1]))




if __name__ == '__main__':
    main()

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

    if len(set(v)) == 1:
        print(n//2)
    elif len(set(v)) == 2:
        cnt1 = 0
        cnt2 = 0
        tmp1 = list(set(v))
        tmp2 = [tmp1[1], tmp1[0]]
        
        
        
        for i, a in enumerate(v):
            if i % 2 == 0:
                if a == tmp1[0]:
                    cnt1 += 1
                if a == tmp2[0]:
                    cnt2 += 1
            else :
                if a == tmp1[1]:
                    cnt1 += 1
                if a == tmp2[1]:
                    cnt2 += 1
        print(n-max(cnt1,cnt2))
    else:
        even = v[::2]
        odd = v[1::2]
        count_e = collections.Counter(even)
        count_o = collections.Counter(odd)
        ce = count_e.most_common()
        co = count_o.most_common()
        if ce[0][0] != co[0][0]:
            print(n-ce[0][1] - co[0][1])
        else:
            if len(ce) == 1:
                print(n-co[1][1])
            elif len(co) == 1:
                print(n-ce[1][1])
            else:
                print(min(n-ce[0][1]-co[1][1], n-ce[1][1]-co[0][1]))




if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
o = Counter(v[::2]).most_common()
o.append((0,0))
e = Counter(v[1::2]).most_common()
e.append((0,0))
if o[0][0] == e[0][0]:
    ans = min(n - o[0][1] - e[1][1], n - o[1][1] - e[0][1])
else:
    ans = n - o[0][1] - e[0][1]
print(ans)

Solution (Python):





import collections
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    v = list(map(int,ipti().split()))
    v1 = [0] * ((n+1) // 2)
    v2 = [0] * (n // 2)

    for i in range(n):
        if i % 2 == 0:
            v1[i//2] = v[i]
        else:
            v2[i//2] = v[i]

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

    v1n = (n+1) // 2
    v2n = n // 2

    ans = 0

    if c1[0][0] == c2[0][0]:
        if len(c1) > 1 and len(c2) > 1:
            temp1 = v1n + v2n -c1[0][1] -c2[1][1]
            temp2 = v1n + v2n -c1[1][1] - c2[0][1]
            ans = min(temp1, temp2)
        elif len(c1) == 1 and len(c2) > 1:
            temp1 = v1n
            temp2 = v1n + v2n - c1[0][1] - c2[1][1]
            ans = min(temp1, temp2)
        elif len(c1) > 1 and len(c2) == 1:
            temp1 = v1n + v2n - c1[1][1] - c2[0][1]
            temp2 = v2n
            ans = min(temp1, temp2)
        else:
            temp1 = v2n
            temp2 = v1n
            ans = min(temp1, temp2)
    else:
        if len(c1) > 1 and len(c2) > 1:
            ans = v1n + v2n - c1[0][1] -c2[0][1]
        elif len(c1) == 1 and len(c2) > 1:
            ans = v2n - c2[0][1]
        elif len(c1) > 1 and len(c2) == 1:
            ans = v1n - c1[0][1]
        else:
            ans = 0

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import Counter
def input(): return sys.stdin.readline().rstrip()

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

    c_odd_most =  Counter(v[1::2]).most_common(2)
    c_even_most =  Counter(v[::2]).most_common(2)

    c_odd = c_odd_most[0][1]
    c_odd2 = c_odd_most[1][1] if len(c_odd_most) > 1 else 0
    c_even = c_even_most[0][1]
    c_even2 = c_even_most[1][1] if len(c_even_most) > 1 else 0

    if c_odd_most[0][0] == c_even_most[0][0]:
        if c_odd + c_even2 > c_odd2 + c_even:
            c_even = c_even2
        else:
            c_odd = c_odd2
    
    print(n - c_odd - c_even)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

N = int(input())
V = list(map(int, input().split()))
V1 = Counter(V[::2]).most_common()
V2 = Counter(V[1::2]).most_common()
lengthV1 = (N+1)//2
lengthV2 = N//2

if V1[0][0] != V2[0][0]:
    print(N-V1[0][1] - V2[0][1])
else:
    if len(V2) > 1:
        ans1 = N - V1[0][1] - V2[1][1]
    else:
        ans1 = N - V1[0][1] - 0
    if len(V1) > 1:
        ans2 = N - V2[0][1] - V1[1][1]
    else:
        ans2 = N - V2[0][1] - 0
    print(min(ans1, ans2))

Solution (Python):
from collections import Counter

N = int(input())
V = list(map(int, input().split()))
V1 = Counter(V[::2]).most_common()
V2 = Counter(V[1::2]).most_common()
lengthV1 = (N+1)//2
lengthV2 = N//2

if V1[0][0] != V2[0][0]:
    print(N-V1[0][1] - V2[0][1])
else:
    if len(V2) > 1:
        ans1 = N - V1[0][1] - V2[1][1]
    else:
        ans1 = N - V1[0][1] - 0
    if len(V1) > 1:
        ans2 = N - V2[0][1] - V1[1][1]
    else:
        ans2 = N - V2[0][1] - 0
    print(min(ans1, ans2))

Solution (Python):
import collections
n=int(input())
t = list(map(int,input().split()))
fir = []
sec = []
for i in range(n): 
    if (i+1)%2==1:
        fir.append(t[i])
    else:
        sec.append(t[i])
f = collections.Counter(fir)
s = collections.Counter(sec)

if len(list(set(t))) == 1:
    print(n-len(sec))
elif f.most_common()[0][0] == s.most_common()[0][0]:
    print(min(n-f.most_common()[0][1]-s.most_common()[1][1], n-f.most_common()[1][1]-s.most_common()[0][1]))
else:
    print(n-f.most_common()[0][1]-s.most_common()[0][1])

Solution (Python):
import collections
n = int(input())
v_ = list(map(int,input().split()))
setv = set(v_)
if len(setv) == 1:
    print(n//2)
else: 
    v1 = v_[::2]
    v2 = v_[1::2]
    v1com = collections.Counter(v1)
    v2com = collections.Counter(v2)
    v1com = v1com.most_common()
    v2com = v2com.most_common()
    if v1com[0][0] != v2com[0][0]:
        print(n-v1com[0][1]-v2com[0][1])
    else:
        print(n-v1com[0][1]-max(v1com[1][1],v2com[1][1]))

Solution (Python):
from collections import Counter
n=int(input())
*v,=map(int,input().split())
odd=Counter(v[::2]).most_common()
odd.append((0,0))
even=Counter(v[1::2]).most_common()
even.append((0,0))
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)