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):
import collections,sys
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(0,n,2):
  a.append(v[i-1])
  b.append(v[i])
c=collections.Counter(a)
d=collections.Counter(b)
C=sorted(c.items(), key=lambda x:-x[1])
D=sorted(d.items(), key=lambda x:-x[1])
A=int(C[0][0])
B=int(D[0][0])
cnt=0
if len(set(v))==1:
  print(n//2)
  sys.exit()
if A!=B:
  for i in range(n//2):
    if a[i]!=A:
      cnt+=1
  for j in range(n//2):
    if b[j]!=B:
      cnt+=1
  print(cnt)
  sys.exit()
if A==B:
  totla=0
  A_=int(C[1][0]) if len(set(a))!=1 else A
  for i in range(n//2):
    if a[i]!=A_:
      totla+=1
  for j in range(n//2):
    if b[j]!=B:
      totla+=1
  totlb=0
  B_=int(D[1][0]) if len(set(b))!=1 else B
  for i in range(n//2):
    if a[i]!=A:
      totlb+=1
  for j in range(n//2):
    if b[j]!=B_:
      totlb+=1
  print(min(totla,totlb))
  sys.exit()

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

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

n3 = []
n4 = []
for i1 in range(n1):
    if i1 % 2 == 0:
        n3.append(n2[i1])
    else:
        n4.append(n2[i1])

n3.sort()
n4.sort()

t1 = 0
c1 = 0
n5 = []

for i2 in range(len(n3)):
    if n3[i2] == t1:
        c1 += 1
        if i2 == len(n3) - 1:
            n5.append([t1, c1])
    else:
        if i2 != 0:
            n5.append([t1, c1])
        t1 = n3[i2]
        c1 = 1
        if i2 == len(n3) - 1:
            n5.append([t1, c1])

t1 = 0
c1 = 0
n6 = []
for i3 in range(len(n4)):
    if n4[i3] == t1:
        c1 += 1
        if  i3 == len(n4) - 1:
            n6.append([t1, c1])
    else:
        if i3 != 0:
            n6.append([t1, c1])
        t1 = n4[i3]
        c1 = 1
        if  i3 == len(n4) - 1:
            n6.append([t1, c1])

n5.sort(key=lambda x:(x[1],x[0]), reverse=True)
n6.sort(key=lambda x:(x[1],x[0]), reverse=True)

r1 = 0

if len(n5) == 1 and len(n6) == 1 and n5[0][0] == n6[0][0]:
     r1 = n1 // 2
else:
    if n5[0][0] != n6[0][0]:
        r1 = n1 - n5[0][1] - n6[0][1]
    else:
        if len(n5) == 1:
            r1 = n1 - n5[0][1] - n6[1][1]
        elif len(n6) == 1:
            r1 = n1 - n5[1][1] - n6[0][1]
        else:
            if (n1 - n5[0][1] - n6[1][1]) >= (n1 - n5[1][1] - n6[0][1]):
                r1 = r1 = n1 - n5[1][1] - n6[0][1]
            else:
                r1 = n1 - n5[0][1] - n6[1][1]

print(r1)

Solution (Python):
from collections import defaultdict


def resolve():
    n = int(input())
    v = list(map(int, input().split()))
    d_o = defaultdict(int)
    d_e = defaultdict(int)
    for i in range(n):
        if i % 2:
            d_o[v[i]] += 1
        else:
            d_e[v[i]] += 1
    d_e[0] = 0
    d_o[0] = 0
    de = sorted(d_e.items(), key=lambda x: -x[1])
    do = sorted(d_o.items(), key=lambda x: -x[1])
    if de[0][0] != do[0][0]:
        print(n - de[0][1] - do[0][1])
    else:
        p01 = de[0][1] + do[1][1]
        p10 = de[1][1] + do[0][1]
        print(n - max(p01, p10))


if __name__ == "__main__":
    resolve()

Solution (Python):
n = int(input())
V = list(map(int, input().split()))
A = {}
B = {}
for i in range(n):
  if i % 2 == 0:
    A[V[i]] = A.get(V[i], 0) + 1
  else:
    B[V[i]] = B.get(V[i], 0) + 1

A = sorted(A.items(), key=lambda x:x[1], reverse=True)
B = sorted(B.items(), key=lambda x:x[1], reverse=True)
a1, b1 = A[0][1], B[0][1]
am, bm = A[0][0], B[0][0]
ans = n - a1 - b1
if ans == 0 and V[0]==V[1]:
  ans = n//2
elif am == bm and n > 4:
  a2,b2 = A[1][1], B[1][1]
  ans = min(n - a2 - b1, n - a1 - b2) 
print(ans)

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



from collections import Counter

n = I()
v = III()

if v==[v[0]]*len(v):
    print(len(v)//2)
    exit()

x = [v[i] for i in range(0,n,2)]
y = [v[i] for i in range(1,n,2)]

xc = Counter(x)
yc = Counter(y)
xval = xc.most_common(1)[0][0]
yval = yc.most_common(1)[0][0]
xnum = xc.most_common(1)[0][1]
ynum = yc.most_common(1)[0][1]

if xval!=yval:
    print(len(x)-xnum+len(y)-ynum)
else:
    if xnum==len(x):
        print(min(len(x)+len(y)-ynum, len(x)-xnum+len(y)-yc.most_common(2)[1][1]))
    elif ynum==len(y):
        print(min(len(x)-xnum+len(y), len(x)-xc.most_common(2)[1][1]+len(y)-ynum))
    else:
        print(min(len(x)-xc.most_common(2)[1][1]+len(y)-ynum, len(x)-xnum+len(y)-yc.most_common(2)[1][1]))

Solution (Python):
n=int(input())
v=[int(x) for x in input().split()]
v_e=v[::2]
v_o=v[1::2]
vote_e={}
vote_o={}
vote_e[-1]=0
vote_o[-1]=0

for i in range(n//2):
    vote_e[v_e[i]] = vote_e[v_e[i]] + 1 if v_e[i] in vote_e else 1
    vote_o[v_o[i]] = vote_o[v_o[i]] + 1 if v_o[i] in vote_o else 1

vote_e=sorted(vote_e.items(), reverse=True, key=lambda x:x[1])
vote_o=sorted(vote_o.items(), reverse=True, key=lambda x:x[1])
popular_e=vote_e[0][1]
popular_o=vote_o[0][1]
if vote_e[0][0]==vote_o[0][0]:
    if vote_e[0][1]+vote_o[1][1]>vote_o[0][1]+vote_e[1][1]:
        popular_o = vote_o[1][1]
    else:
        popular_e = vote_e[1][1]
print(n-popular_o-popular_e)

Solution (Python):
import collections

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

    even = [j for i, j in enumerate(v) if i % 2 == 0]
    odd = [j for i, j in enumerate(v) if i % 2 == 1]

    cnt_e = collections.Counter(even)
    cnt_o = collections.Counter(odd)

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

    if cnt_e.most_common()[0][0] == cnt_o.most_common()[0][0]:
        if cnt_e.most_common()[0][1] > cnt_o.most_common()[0][1]:
            print(n - cnt_e.most_common()[0][1] - cnt_o.most_common()[1][1])
        elif cnt_e.most_common()[0][1] < cnt_o.most_common()[0][1]:
            print(n - cnt_e.most_common()[1][1] - cnt_o.most_common()[0][1])
        else:
            if cnt_e.most_common()[1][1] > cnt_o.most_common()[1][1]:
                print(n - cnt_e.most_common()[1][1] - cnt_o.most_common()[0][1])
            else:
                print(n - cnt_e.most_common()[0][1] - cnt_o.most_common()[1][1])
    else:
        print(n - cnt_e.most_common()[0][1] - cnt_o.most_common()[0][1])


main()

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

odd = []
even = []

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

oddm = collections.Counter(odd)
evenm = collections.Counter(even)

odd1 = oddm.most_common()[0]
even1 = evenm.most_common()[0]

if (odd1 == even1) and (oddm.most_common()[0][1] + evenm.most_common()[0][1] == n):
  ans = n//2
else:
  if odd1 != even1:
    ans = n - oddm.most_common()[0][1] - evenm.most_common()[0][1] 
  else:
    p1 = ans = n - oddm.most_common()[1][1] - evenm.most_common()[0][1] 
    p2 = ans = n - oddm.most_common()[0][1] - evenm.most_common()[1][1] 
    ans = min(p1, p2)
    
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
V = [int(el) for el in input().split(' ')]

a = Counter(V[0::2]).most_common() + [(0,0)]
b = Counter(V[1::2]).most_common() + [(0,0)]

if a[0][0]!=b[0][0]:
    print(n-a[0][1]-b[0][1])
else:
    print(n-max(a[1][1]+b[0][1],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() + [(0,0)]
b = Counter(V[1::2]).most_common() + [(0,0)]
if a[0][0]!=b[0][0]:
    print(N-a[0][1]-b[0][1])
else:
    print(N-max(a[1][1]+b[0][1],a[0][1]+b[1][1]))

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

def main():
    N = int(input())
    V1 = {}
    V2 = {}
    V = list(map(int, input().split()))
    for i,v in enumerate(V):
        if i%2 == 0:
            V1[v] = V1[v] + 1 if v in V1 else 1
        else:
            V2[v] = V2[v] + 1 if v in V2 else 1

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

    if V1[0] != V2[0]:
        ans = 0
        for v in V1[1:]:
            ans += v[1]
        for v in V2[1:]:
            ans += v[1]
        print(ans)
    else:
        a1 = 0
        for v in V1[1:]:
            a1 += v[1]
        a1 += V2[0][1]
        for v in V2[2:]:
            a1 += v[1]
        a2 = 0
        a2 += V1[0][1]
        for v in V1[2:]:
            a2 += v[1]
        for v in V2[1:]:
            a2 += v[1]
        print(min(a1,a2))

if __name__ == '__main__':
    main()

Solution (Python):


import collections

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


odd_list = [str(v) for i, v in enumerate(v_list) if i % 2 == 1]

even_list = [str(v) for i, v in enumerate(v_list) if i % 2 == 0]


odd_counter = collections.Counter(odd_list)
odd_1 = odd_counter.most_common()[0][0]

if len(odd_counter) >= 2:
    odd_2 = odd_counter.most_common()[1][0]
else:
    odd_2 = '*' 


even_counter = collections.Counter(even_list)
even_1 = even_counter.most_common()[0][0]

if len(even_counter) >= 2:
    even_2 = even_counter.most_common()[1][0]
else:
    even_2 = '+' 




if even_1 == odd_1:
    
    even_op_count = len([v for v in even_list if v != even_1])
    
    odd_op_count = len([v for v in odd_list if v != odd_2])
    count_1 = even_op_count + odd_op_count

    
    even_op_count = len([v for v in even_list if v != even_2])
    
    odd_op_count = len([v for v in odd_list if v != odd_1])
    count_2 = even_op_count + odd_op_count

    count = min(count_1, count_2)
else:
    
    even_op_count = len([v for v in even_list if v != even_1])
    odd_op_count = len([v for v in odd_list if v != odd_1])
    count = even_op_count + odd_op_count

print(count)

Solution (Python):
from collections import defaultdict

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

odd = defaultdict(int)
even = defaultdict(int)
al = defaultdict(int)

for i in range(len(v)):
  al[v[i]] += 1
  if(i % 2 == 0): 
    even[v[i]] += 1
  else: 
    odd[v[i]] += 1

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

even_sorted = sorted(even.items(), key=lambda x: x[1], reverse=True)
odd_sorted = sorted(odd.items(), key=lambda x: x[1], reverse=True)





if(len(even_sorted) == 1): 
  if(odd_sorted[0][0] == even_sorted[0][0]):
    print(n - odd_sorted[1][1]  - even_sorted[0][1])
  else:
    print(n - odd_sorted[0][1] - even_sorted[0][1])
elif(len(odd_sorted) == 1):
  if(odd_sorted[0][0] == even_sorted[0][0]):
    print(n - even_sorted[1][1] - odd_sorted[0][1])
  else:
    print(n - odd_sorted[0][1] - even_sorted[0][1])


else: 
  if(odd_sorted[0][0] == even_sorted[0][0]):
    if(odd_sorted[0][1] == even_sorted[0][1]):
      if(odd_sorted[1][1] < even_sorted[1][1]):
        print(n - odd_sorted[0][1] - even_sorted[1][1])
      else:
        print(n - odd_sorted[1][1] - even_sorted[0][1])
    elif(odd_sorted[0][1] < even_sorted[0][1]): 
      print(n - odd_sorted[1][1] - even_sorted[0][1])
    else:
      print(n - odd_sorted[0][1] - even_sorted[1][1])
  else: 
    print(n - odd_sorted[0][1] - even_sorted[0][1])

Solution (Python):
def main():
    n = int(input())
    V = [int(v) for v in input().split()]
    even = dict()
    odd = dict()
    for i in range(n//2):
        even[V[2*i]] = even.get(V[2*i], 0) + 1
        odd[V[2*i+1]] = odd.get(V[2*i+1], 0) + 1
    max_count_even = max(even.values())
    max_count_odd = max(odd.values())
    max_v_even = [v for v in even if even[v] == max_count_even]
    max_v_odd = [v for v in odd if odd[v] == max_count_odd]

    if len(max_v_even) == len(max_v_odd) == 1 and max_v_even[0] == max_v_odd[0]:
        del even[max_v_even[0]]
        del odd[max_v_odd[0]]
        if even:
            max_count_even_nxt = max(even.values())
        else:
            max_count_even_nxt = 0
        if odd:
            max_count_odd_nxt = max(odd.values())
        else:
            max_count_odd_nxt = 0
        return min(n-max_count_even-max_count_odd_nxt, n-max_count_odd-max_count_even_nxt)
    else:
        return n - max_count_even - max_count_odd


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

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
a = Counter(v[::2])
b = Counter(v[1::2])
count = a.most_common()
count1 = b.most_common()
if len(set(v)) == 1:
    print(n//2)
    exit()
if count[0][0] == count1[0][0]:
    print(n- count[0][1] - (max(count[1][1], count1[1][1])))

else:
    print(n - count[0][1] - count1[0][1])

Solution (Python):
from collections import Counter

n,*l = map(int, open(0).read().split())

c0 = Counter(l[::2]).most_common() + [(0, 0)]
c1 = Counter(l[1::2]).most_common() + [(0, 0)]

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

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

Vodd = []
Veven = []
for i in range(n//2):
  Vodd.append(V[2*i])
  Veven.append(V[2*i+1])

import collections
Codd = collections.Counter(Vodd)
Ceven = collections.Counter(Veven)
cmlstodd = Codd.most_common()
cmlsteven = Ceven.most_common()


if len(cmlstodd)==1:
  if cmlstodd[0][0] == cmlsteven[0][0]:
    if len(cmlsteven)==1:
      print(n//2)
    else:
      print(n//2 - cmlsteven[1][1])
  else:
    print(n//2 - cmlsteven[0][1])
elif len(cmlsteven)==1:
  if cmlsteven[0][0] == cmlstodd[0][0]:
    print(n//2 - cmlstodd[1][1])
  else:
    print(n//2 - cmlstodd[0][1])
else:
  if cmlsteven[0][0] == cmlstodd[0][0]:
    print(n - max(cmlsteven[0][1] + cmlstodd[1][1], cmlsteven[1][1] + cmlstodd[0][1]))
  else:
    print(n - cmlstodd[0][1] - cmlsteven[0][1])

Solution (Python):
from collections import Counter

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

l0 = l[::2]
l1 = l[1::2]
c0 = Counter(l0)
c1 = Counter(l1)
ll0 = len(l0)
ll1 = len(l1)

c0m = c0.most_common()[:2] + [(0, 0)]
c1m = c1.most_common()[:2] + [(0, 0)]

if c0m[0][0] != c1m[0][0]:
  print(ll0 - c0m[0][1] + ll1 - c1m[0][1])
else:
  print(min(ll0 - c0m[1][1] + ll1 - c1m[0][1], ll0 - c0m[0][1] + ll1 - c1m[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(n-max(a[0][1]+b[1][1],a[1][1]+b[0][1]))

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

for i in range(0,n,2):
    if v[i] in dic_odd:
        dic_odd[v[i]] += 1
    else:
        dic_odd[v[i]] = 1

for i in range(1,n,2):
    if v[i] in dic_even:
        dic_even[v[i]] += 1
    else:
        dic_even[v[i]] = 1

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

if odd_sorted[len(odd_sorted)-1][0] == even_sorted[len(even_sorted)-1][0]:
    if len(odd_sorted) == 1 and len(even_sorted) == 1:
        print(n//2)
    elif len(odd_sorted) == 1:
        print(n//2-even_sorted[len(even_sorted)-2][1])
    elif len(even_sorted) == 1:
        print(n//2-odd_sorted[len(odd_sorted)-2][1])
    else:
        if odd_sorted[len(odd_sorted)-1][1] < even_sorted[len(even_sorted)-1][1]:
            print(n - (odd_sorted[len(odd_sorted)-2][1] + even_sorted[len(even_sorted)-1][1]))
        elif  odd_sorted[len(odd_sorted)-1][1] > even_sorted[len(even_sorted)-1][1]:
            print(n - (odd_sorted[len(odd_sorted)-1][1] + even_sorted[len(even_sorted)-2][1]))
        else:
            if odd_sorted[len(odd_sorted)-2][1] < even_sorted[len(even_sorted)-2][1]:
                print(n - (odd_sorted[len(odd_sorted)-1][1] + even_sorted[len(even_sorted)-2][1]))
            else:
                print(n - (odd_sorted[len(odd_sorted)-2][1] + even_sorted[len(even_sorted)-1][1]))
else:
    print(n-(odd_sorted[len(odd_sorted)-1][1]+even_sorted[len(even_sorted)-1][1]))

Solution (Python):
import math
import sys
from itertools import accumulate
from functools import reduce
from collections import Counter
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""

a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 



    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())


    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  
"""

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    L = list(map(int, sys.stdin.readline().split()))
    eL = Counter([L[i] for i in range(N) if i % 2 != 0])
    oL = Counter([L[i] for i in range(N) if i % 2 == 0])
    eLc = eL.most_common() 
    oLc = oL.most_common() 

    if eLc[0][0] != oLc[0][0]:
        print(N - (eLc[0][1] + oLc[0][1]))
    else:
        if len(eLc) == 1 or len(oLc) == 1:
            print(N // 2)
        else:
            print(min(N - (eLc[1][1] + oLc[0][1]), N - (eLc[0][1] + oLc[1][1])))

Solution (Python):
import math
import sys
from itertools import accumulate
from functools import reduce
from collections import Counter
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""

a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 



    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())


    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  
"""

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    L = list(map(int, sys.stdin.readline().split()))
    l = N // 2
    eL = Counter([L[i] for i in range(N) if i % 2 != 0])
    oL = Counter([L[i] for i in range(N) if i % 2 == 0])
    eLc = eL.most_common() 
    oLc = oL.most_common() 

    if len(eLc) == 1 or len(oLc) == 1:
        if len(eLc) == 1 and len(oLc) == 1:
            if eLc[0] != oLc[0]:
                print(0)
            else:
                print(l)
        elif len(eLc) == 1:
            print((l - oLc[0][1]))
        else:
            print((l - eLc[0][1]))
    else:
        if eLc[0][0] != oLc[0][0]:
            print((l - eLc[0][1]) + (l - oLc[0][1]))
        else:
            print(min((l - eLc[1][1]) + (l - oLc[0][1]), (l - eLc[0][1]) + (l - oLc[1][1])))

Solution (Python):
import collections

n = int(input())
v = list(map(int, input().split()))
v1 = []
v2 = []
ans = 0

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

c1 = collections.Counter(v1)
mostChar1, mostCount1 = c1.most_common()[0]


c2 = collections.Counter(v2)
mostChar2, mostCount2 = c2.most_common()[0]


if mostChar1 == mostChar2:
    if len(c1.most_common()) == 1 and len(c1.most_common()) == 1:
        ans = n // 2
    elif len(c1.most_common()) == 1:
        ndChar2, ndCount2 = c2.most_common()[1]
        ans = n - mostCount1 - ndCount2
    elif len(c2.most_common()) == 1:
        ndChar1, ndCount1 = c1.most_common()[1]
        ans = n - mostCount2 - ndCount1
    else:
        ndChar1, ndCount1 = c1.most_common()[1]
        ndChar2, ndCount2 = c2.most_common()[1]
        temp1 = n - mostCount1 - ndCount2
        temp2 = n - mostCount2 - ndCount1
        ans = min(temp1, temp2)
else:
    ans = n - mostCount1 - mostCount2

print(ans)

Solution (Python):
x=[]
y=[]
n=int(input())
a=list(map(int,input().split()))
for i in range(10**5+1):
	x.append([i,0])
	y.append([i,0])
for i in range(n//2):
	x[a[i*2]][1]+=1
	y[a[i*2+1]][1]+=1
x.sort(key=lambda x:-x[1])
y.sort(key=lambda x:-x[1])
if x[0][0]!=y[0][0]:
	print(n-x[0][1]-y[0][1])
else:
	print(n-max(x[0][1]+y[1][1],
		x[1][1]+y[0][1]))

Solution (Python):
import collections as c
import sys


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

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

length1 = len(v1)
length2 = len(v2)

v1 = c.Counter(v1)
v2 = c.Counter(v2)

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


if v1.most_common()[0][0] != v2.most_common()[0][0]:
    ans = (length1 - v1.most_common()[0][1]) + (length2 - v2.most_common()[0][1])
else:
    a1 = length1 - v1.most_common()[0][1]
    a2 = length1 - v1.most_common()[1][1]
    b1 = length2 - v2.most_common()[0][1]
    b2 = length2 - v2.most_common()[1][1]

    ans = min([a1+b2, a2+b1])

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v0 = v[0::2]
v1 = v[1::2]
c0 = Counter(v0).most_common()
c1 = Counter(v1).most_common()
if c0[0][0] == c1[0][0] :
    if len(c0)*len(c1) == 1 :
        print(n//2)
    elif len(c0) == 1 :
        print(n-c0[0][1]-c1[1][1])
    elif len(c1) == 1 :
        print(n-c1[0][1]-c0[1][1])
    else :
        if c0[0][1]+c1[1][1] > c1[0][1]+c0[1][1] :
            print(n-c0[0][1]-c1[1][1])
        else :
            print(n-c1[0][1]-c0[1][1])
else :
    print(n-c0[0][1]-c1[0][1])

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

if len(set(v))==1:
    print(n//2)
else:
    a=[]
    b=[]
    for i in range(n):
        if i%2==0:
            a.append(v[i])
        else:
            b.append(v[i])
    a=collections.Counter(a)
    a0=a.most_common()[0]
    b=collections.Counter(b)
    b0=b.most_common()[0]
    if a0[0]!=b0[0]:
        print(n-a0[1]-b0[1])
    elif a0[0]==b0[0]:
        if a0[1]>b0[1]:
            print(n-a0[1]-b.most_common()[1][1])
        elif a0[1]<b0[1]:
            print(n-b0[1]-a.most_common()[1][1])
        elif a0==b0:
            if b.most_common()[1][1]>=a.most_common()[1][1]:
                print(n-a0[1]-b.most_common()[1][1])
            elif b.most_common()[1][1]<=a.most_common()[1][1]:
                print(n-b0[1]-a.most_common()[1][1])

Solution (Python):
N=int(input())
lv=list(map(int,input().split()))
dev={}
dod={}


max1_ev=[0,0]
max2_ev=[0,0]
max1_od=[0,0]
max2_od=[0,0]

for i in range(N):
    if i%2==0:
        
        
        

        if lv[i] in dev:
            dev[lv[i]]+=1
        else:
            dev[lv[i]]=1
            
            
            
            
            
            
        
        
        if dev[lv[i]]>max1_ev[1]:
            a=max1_ev
            max1_ev=[lv[i],dev[lv[i]]]
            max2_ev=a
        
        elif dev[lv[i]]>=max2_ev[1]:
            max2_ev=[lv[i],dev[lv[i]]]
        
        
        
        
        
        
        
        
    else:
        
        
        if lv[i] in dod:
            dod[lv[i]]+=1
        else:
            dod[lv[i]]=1
        if dod[lv[i]]>max1_od[1]:
            a=max1_od
            max1_od=[lv[i],dod[lv[i]]]
            max2_od=a
        
        elif dod[lv[i]]>=max2_od[1]:
            max2_od=[lv[i],dod[lv[i]]]









    
    
    



if max1_ev[0]!=max1_od[0]:
    print(N-max1_ev[1]-max1_od[1])
elif len(dev)==1 and len(dod)==1:
    print(int(N/2))
elif len(dev)==1:
    print(int(N/2)-max2_od[1])
elif len(dod)==1:
    print(int(N/2)-max2_ev[1])
else:
    
    print(min(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1]))

Solution (Python):
N=int(input())
lv=list(map(int,input().split()))
dev={}
dod={}
for i in range(N):
    if i%2==0:
        if lv[i] in dev:
            dev[lv[i]]+=1
        else:
            dev[lv[i]]=1
    else:
        if lv[i] in dod:
            dod[lv[i]]+=1
        else:
            dod[lv[i]]=1

max1_ev=[0,0]
max2_ev=[0,0]
max1_od=[0,0]
max2_od=[0,0]

for v in dev:
    if dev[v]>max1_ev[1]:
        a=max1_ev
        max1_ev=[v,dev[v]]
        max2_ev=a
    elif dev[v]>max2_ev[1]:
        max2_ev=[v,dev[v]]
for v in dod:
    if dod[v]>max1_od[1]:
        a=max1_od
        max1_od=[v,dod[v]]
        max2_od=a
    elif dod[v]>max2_od[1]:
        max2_od=[v,dod[v]]
if max1_ev[0]!=max1_od[0]:
    print(N-max1_ev[1]-max1_od[1])
else:
    print(min(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1]))

Solution (Python):
import collections
n=int(input())
v=list(map(int,input().split()))
ans=0
e=v[::2]
o=v[1::2]
ec=collections.Counter(e)
oc=collections.Counter(o)
E=len(e)
O=len(o)

E1=ec.most_common()[0][0]
e1=ec.most_common()[0][1]
try:
  E2=ec.most_common()[1][0]
  e2=ec.most_common()[1][1]
except:
  e2=0
O1=oc.most_common()[0][0]
o1=oc.most_common()[0][1]
try:
  O2=oc.most_common()[1][0]
  o2=oc.most_common()[1][1]
except:
  o2=0

if E1!=O1:
  ans=(E-e1)+(O-o1)
else:
  ans=min((E-e1)+(O-o2),(E-e2)+(O-o1))
print(ans)

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

a = {}
for i in range(0, len(v), 2):
    a[v[i]] = a.get(v[i], 0) + 1

b = {}
for i in range(1, len(v), 2):
    b[v[i]] = b.get(v[i], 0) + 1

sorted_a = sorted(a.items(), reverse=True, key=lambda x: x[1])
sorted_b = sorted(b.items(), reverse=True, key=lambda x: x[1])

res = 0
if sorted_a[0][0] == sorted_b[0][0]:
    if sorted_a[0][1] > sorted_b[0][1]:
        sorted_b[0], sorted_b[1] = sorted_b[1], sorted_b[0]
    elif sorted_a[0][1] < sorted_b[0][1]:
        sorted_a[0], sorted_a[1] = sorted_a[1], sorted_a[0]
    else:
        if len(sorted_b) == 1:
            res += sorted_b[0][1]
        elif sorted_a[1][1] > sorted_b[1][1]:
            sorted_a[0], sorted_a[1] = sorted_a[1], sorted_a[0]
        else:
            sorted_b[0], sorted_b[1] = sorted_b[1], sorted_b[0]

res += len(v) - sorted_a[0][1] - sorted_b[0][1]

print(res)

Solution (Python):
n=int(input())
a,b=[None]*100000,[None]*100000
for i in range(100000):
    a[i]=[None]*2
    a[i][0]=0
    a[i][1]=i
    b[i]=[None]*2
    b[i][0]=0
    b[i][1]=i
l=list(map(int,input().split()))
for i in range(n//2):
    a[l[2*i]-1][0]+=1
    b[l[2*i+1]-1][0]+=1
a.sort(reverse=True)
b.sort(reverse=True)
if a[0][1]==b[0][1]:
    print(n-max(a[0][0]+b[1][0],a[1][0]+b[0][0]))
else:
    print(n-a[0][0]-b[0][0])

Solution (Python):
n=int(input())
a,b=[None]*100000,[None]*100000
for i in range(100000):
    a[i]=[None]*2
    a[i][0]=0
    a[i][1]=i
    b[i]=[None]*2
    b[i][0]=0
    b[i][1]=i
l=list(map(int,input().split()))
for i in range(n//2):
    a[l[2*i]-1][0]+=1
    b[l[2*i+1]-1][0]+=1
a.sort(reverse=True)
b.sort(reverse=True)
if a[0][1]==b[0][1]:
    print(n-max(a[0][0]+b[1][0],a[1][0]+b[0][0]))
else:
    print(n-a[0][0]-b[0][0])

Solution (Python):
N=int(input())
lv=list(map(int,input().split()))
dev={}
dod={}


max1_ev=[0,0]
max2_ev=[0,0]
max1_od=[0,0]
max2_od=[0,0]

for i in range(N):
    if i%2==0:
        
        
        

        if lv[i] in dev:
            dev[lv[i]]+=1
        else:
            dev[lv[i]]=1
            
            
            
            
            
            
        
        
        if dev[lv[i]]>max1_ev[1]:
            max1_ev=[lv[i],dev[lv[i]]]
        
        elif dev[lv[i]]>=max2_ev[1]:
            max2_ev=[lv[i],dev[lv[i]]]
        
        
        
        
        
        
        
        
    else:
        
        
        if lv[i] in dod:
            dod[lv[i]]+=1
        else:
            dod[lv[i]]=1
        if dod[lv[i]]>max1_od[1]:
            max1_od=[lv[i],dod[lv[i]]]
        
        elif dod[lv[i]]>=max2_od[1]:
            max2_od=[lv[i],dod[lv[i]]]









    
    
    



if max1_ev[0]!=max1_od[0]:
    print(N-max1_ev[1]-max1_od[1])
elif len(dev)==1 and len(dod)==1:
    print(int(N/2))
elif len(dev)==1:
    print(int(N/2)-max2_od[1])
elif len(dod)==1:
    print(int(N/2)-max2_ev[1])
else:
    
    print(min(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1]))

Solution (Python):
import math,fractions
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
a = Counter(v[1::2]).most_common()
b = Counter(v[0::2]).most_common()
a.append((0,0))
b.append((0,0))

if a[0][0] != b[0][0]:
    print(n//2 - a[0][1] + n//2 - b[0][1])
else:
    tmp_x = n//2 - a[1][1] + n//2 - b[0][1]
    tmp_y = n//2 - a[0][1] + n//2 - b[1][1]
    print(min(tmp_x, tmp_y))

Solution (Python):
import math,fractions
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
a = [v[i] for i in range(n) if i%2]
b = [v[i] for i in range(n) if i%2==0]
cnt_a = Counter(a)
cnt_b = Counter(b)
max_a = cnt_a.most_common()[0][1]
max_b = cnt_b.most_common()[0][1]

str_a = cnt_a.most_common()[0][0]
str_b = cnt_b.most_common()[0][0]

max_2a = 0
max_2b = 0

for i in cnt_a:
    if str_a != i  and cnt_a[i] > max_2a:
        max_2a = cnt_a[i]

for i in cnt_b:
    if str_b != i  and cnt_b[i] > max_2b:
        max_2b = cnt_b[i]

if str_a != str_b:
    print(n//2 - max_a + n//2 - max_b)
else:
    tmp_a = n//2 - max_2a + n//2 - max_b
    tmp_b = n//2 - max_a + n//2 - max_2b
    print(min(tmp_a,tmp_b))

Solution (Python):
import collections

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

hantei = 0

for i in range(0,n):
    if u[0] != u[i]:
        hantei = 1
        break

if hantei == 0:
    print(n // 2)
else:
   u1 = [] 
   u2 = [] 
   ans = 0
   for j in range(n):
       if j % 2 == 0:
           u2.append(u[j])
       else:
           u1.append(u[j])
   u1_list =collections.Counter(u1)
   u2_list =collections.Counter(u2)
   values1, counts1 = u1_list.most_common()[0]
   values2, counts2 = u2_list.most_common()[0]
   if values1 != values2:
       ans += n // 2 - counts1
       ans += n // 2 - counts2
   else:
       if len(u1_list) > 1 and len(u2_list) > 1:
           values3, counts3 = u1_list.most_common()[1]
           values4, counts4 = u2_list.most_common()[1]
           ans1 = n - counts1 - counts4
           ans2 = n - counts2 - counts3
           ans = max(ans1,ans2)
       elif len(u1_list) > 1 and len(u2_list) < 2:
           values3, counts3 = u1_list.most_common()[1]
           ans = n - counts2 - counts3
       elif len(u1_list) < 2 and len(u2_list) > 1:
           values3, counts3 = u2_list.most_common()[1]
           ans = n - counts1 - counts3

       ans = min(ans1,ans2)
   print(ans)