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):
n=int(input())
v=list(map(int,input().split()))
d1={}
d2={}
for i in range(n):
  if i%2==0:
    if v[i] not in d1:
      d1[v[i]]=1
    else:
      d1[v[i]]+=1
  else:
    if v[i] not in d2:
      d2[v[i]]=1
    else:
      d2[v[i]]+=1
nd1=sorted(d1.items(),key=lambda x:x[1],reverse=True)
nd2=sorted(d2.items(),key=lambda x:x[1],reverse=True)
nd1.append((0,0))
nd2.append((0,0))
if nd1[0][0]==nd2[0][0]:
  print(n-max(nd1[0][1]+nd2[1][1],nd1[1][1]+nd2[0][1]))
else:
  print(n-nd1[0][1]-nd2[0][1])

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
a = Counter(v[::2])
b = Counter(v[1::2])
if len(set(v)) == 1:
    print(n // 2)
elif a.most_common()[0][0] != b.most_common()[0][0]:
    print(n - a.most_common()[0][1] - b.most_common()[0][1])
elif len(a) < 2 and len(b) > 1:
    print(n // 2 - a.most_common()[1][1])
elif len(a) > 1 and len(b) < 2:
    print(n // 2 - b.most_common()[1][1])
else:
    print(
        min(n - a.most_common()[0][1] - b.most_common()[1][1],
            n - a.most_common()[1][1] - b.most_common()[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]
v1c = Counter(v1).most_common()
v2c = Counter(v2).most_common()
v1c.append((0,0))
v2c.append((0,0))
if v1c[0][0]==v2c[0][0]:
    print(min(N-v1c[0][1]-v2c[1][1],N-v1c[1][1]-v2c[0][1]))
else:
    print(N-v1c[0][1]-v2c[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]

v1c=Counter(v1).most_common()
v2c=Counter(v2).most_common()
v1c.append((0,0))
v2c.append((0,0))

if v1c[0][0]==v2c[0][0]:
    print(min(n-v1c[0][1]-v2c[1][1],n-v1c[1][1]-v2c[0][1]))
else:
    print(n-v1c[0][1]-v2c[0][1])

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=[]
v2=[]
for i in range(n):
    if i%2==0:
        v1.append(v[i])
    else:
        v2.append(v[i])

v1c=Counter(v1).most_common()
v2c=Counter(v2).most_common()
v1c.append((0,0))
v2c.append((0,0))

if v1c[0][0]==v2c[0][0]:
    print(min(n-v1c[0][1]-v2c[1][1],n-v1c[1][1]-v2c[0][1]))
else:
    print(n-v1c[0][1]-v2c[0][1])

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    n = I()
    v = LI()
    even_count = collections.defaultdict(int)
    odd_count = collections.defaultdict(int)
    for i in range(n):
        if i % 2 == 1:
            odd_count[v[i]] += 1
        else:
            even_count[v[i]] += 1
    odd_array = []
    even_array = []
    for k, v in odd_count.items():
        odd_array.append((k, v))
    for k, v in even_count.items():
        even_array.append((k, v))

    odd_array = sorted(odd_array, key=lambda x:x[1])[::-1]
    even_array = sorted(even_array, key=lambda x:x[1])[::-1]

    ans = inf
    arrLen = n // 2
    for ok, ov in odd_array[:2]:
        for ek, ev in even_array[:2]:
            if ok == ek:
                continue
            ans = min(ans, (arrLen - ov) + (arrLen - ev))
    if ans == inf:
        ans = arrLen
    print(ans)
main()

Solution (Python):
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]
v1.sort()
v2.sort()
num1 = 0
num2 = 0
num11 = 0
num22 = 0
check1 = 1
check2 = 1
p = 0
for i in range(len(v1)-1):
    if v1[i] != v1[i+1]:
        if check1 > num1:
            num1 = check1
            p = v1[i]
        check1 = 1
    else:
        check1 += 1
        if check1 > num1:
            num1 = check1
            p = v1[i]

for i in range(len(v2)-1):
    if v2[i] != v2[i+1]:
        if check2 > num2 and v2[i] != p:
            num2 = check2
        check2 = 1
    else:
        check2 += 1
    if check2 > num2 and v2[i] != p:
        num2 = check2

check1 = check2 = 1
for i in range(len(v2)-1):
    if v2[i] != v2[i+1]:
        if check2 > num22:
            num22 = check2
            p = v2[i]
        check2 = 1
    else:
        check2 += 1
    if check2 > num22:
        num22 = check2
        p = v2[i]
        
for i in range(len(v1)-1):
    if v1[i] != v1[i+1]:
        if check1 > num11 and v1[i] != p:
            num11 = check1
        check1 = 1
    else:
        check1 += 1
        if check1 > num11 and v1[i] != p:
            num11 = check1

print(min(n-num1-num2, n-num11-num22))

Solution (Python):
import collections

n = int(input())
V = list(map(int, input().split()))
kisuu = []
gusuu = []
for idx, v in enumerate(V):
    if idx % 2 == 0:
        gusuu.append(v)
    else:
        kisuu.append(v)
gusuu_c = collections.Counter(gusuu)
gusuu_c_sorted = sorted(gusuu_c.items(), key=lambda x: x[1], reverse=True)
kisuu_c = collections.Counter(kisuu)
kisuu_c_sorted = sorted(kisuu_c.items(), key=lambda x: x[1], reverse=True)

if gusuu_c_sorted[0][0] != kisuu_c_sorted[0][0]:
    print(
        len(kisuu) - kisuu_c_sorted[0][1] + len(gusuu) - gusuu_c_sorted[0][1])
else:
    if len(gusuu_c_sorted) == 1 and len(kisuu_c_sorted) == 1:
        print(min(len(gusuu), len(kisuu)))
    elif len(gusuu_c_sorted) == 1:
        print(len(kisuu) - kisuu_c_sorted[1][1])
    elif len(kisuu_c_sorted) == 1:
        print(len(gusuu) - gusuu_c_sorted[1][1])
    else:
        print(min(len(kisuu) - kisuu_c_sorted[1][1] + len(gusuu) - gusuu_c_sorted[0][1],
                  len(kisuu) - kisuu_c_sorted[0][1] + len(gusuu) - gusuu_c_sorted[1][1]))

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


even = [0] * (10 ** 5)
odd = [0] * (10 ** 5)

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

for i in range(1, n, 2):
    odd[v[i] - 1] += 1

even_max = max(even)
odd_max = max(odd)

even_max_i = even.index(even_max)
odd_max_i = odd.index(odd_max)

if even_max_i == odd_max_i:
    even[even_max_i] = 0
    odd[odd_max_i] = 0

    even_max_2 = max(even)
    odd_max_2 = max(odd)

    ans = n - max(even_max + odd_max_2, even_max_2 + odd_max)
else:
    ans = n - (even_max + odd_max)

print(ans)

Solution (Python):
import itertools
from collections import Counter
N = int(input())
V = list(map(int,input().split()))
even_counter = Counter(V[::2])
odd_counter = Counter(V[1::2])
even_counter[-1] = 0
odd_counter[-1] = 0
even = even_counter.most_common(2)
odd = odd_counter.most_common(2)
ans = N
for (k1,v1),(k2,v2) in itertools.product(even,odd):
  if k1 == k2:
    continue
  ans = min(ans,N - v1 - v2)
print(ans)

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
odd = [0] * (10 ** 5 + 1)
even = [0] * (10 ** 5 + 1)
odd_cnt = []
even_cnt = []
ans = 0
for i in range(n):
    if i % 2 == 0:
        even[v[i]] += 1
    else:
        odd[v[i]] += 1
for i in range(10 ** 5 + 1):
    odd_cnt.append((odd[i], i))
    even_cnt.append((even[i], i))
even_cnt.sort(reverse=True)
odd_cnt.sort(reverse=True)
if even_cnt[0][1] == odd_cnt[0][1]:
    ans = n - max(even_cnt[0][0] + odd_cnt[1][0],
                  even_cnt[1][0] + odd_cnt[0][0])
else:
    ans = n - (even_cnt[0][0] + odd_cnt[0][0])
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
L = list(map(int, input().split()))
odd = [v for i, v in enumerate(L) if i % 2 == 0]
even = [v for i, v in enumerate(L) if i % 2 == 1]

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


c_odd = sorted(dict(Counter(odd)).items(), key=lambda x: -x[1])
c_even = sorted(dict(Counter(even)).items(), key=lambda x: -x[1])

odd_1 = c_odd[0]
even_1 = c_even[0]

if odd_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

even_2 = c_even[1]
odd_2 = c_odd[1]

ans = N
ans = min(ans, N - odd_1[1] - even_2[1])
ans = min(ans, N - odd_2[1] - even_1[1])
print(ans)

Solution (Python):
from collections import defaultdict

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

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


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

for i in range(N):
    v = L[i]
    if i % 2 == 0:
        d_even[v] += 1
    else:
        d_odd[v] += 1

l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

if l_even[0][0] != l_odd[0][0]:
    print(N - l_odd[0][1] - l_even[0][1])
    exit()

ans = N
ans = min(ans, N - l_odd[0][1] - l_even[1][1])
ans = min(ans, N - l_odd[1][1] - l_even[0][1])
print(ans)

Solution (Python):
from collections import defaultdict

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

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


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

for i in range(N):
    v = L[i]
    if i % 2 == 0:
        d_even[v] += 1
    else:
        d_odd[v] += 1

l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

if l_even[0][0] != l_odd[0][0]:
    print(N - l_even[0][1] - l_odd[0][1])
else:
    
    ans1 = N - l_even[0][1] - l_odd[1][1]
    ans2 = N - l_even[1][1] - l_odd[0][1]
    print(min(ans1, ans2))

Solution (Python):
import itertools
from collections import Counter
N = int(input())
V = list(map(int,input().split()))
even_counter = Counter(V[::2])
odd_counter = Counter(V[1::2])
even_counter[-1] = 0
odd_counter[-1] = 0
even = even_counter.most_common(2)
odd = odd_counter.most_common(2)
ans = N
for (k1,v1),(k2,v2) in itertools.product(even,odd):
  if k1 == k2:
    continue
  ans = min(ans,N - v1 - v2)
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:
  odd = []
  even = []
  for i in range(len(V)):
    if i % 2 == 0:
      even.append(V[i])
    else:
      odd.append(V[i])
  max_even,max_e_count = Counter(even).most_common(1)[0]
  max_odd,max_o_count = Counter(odd).most_common(1)[0]
  if max_even == max_odd:
    sec_even,sec_e_count = Counter(even).most_common(2)[1]
    sec_odd,sec_o_count = Counter(odd).most_common(2)[1]
    even_rank2 = len(odd) - max_o_count + len(even) - sec_e_count
    odd_rank2 = len(odd) - sec_o_count + len(even) - max_e_count
    print(min(even_rank2,odd_rank2))
  else:
    print(len(odd) - max_o_count + len(even) - max_e_count)

Solution (Python):
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    v = list(map(int, readline().split()))
    ve = collections.Counter(v[0::2]).most_common()
    vo = collections.Counter(v[1::2]).most_common()
    if ve[0][0] != vo[0][0]:
        print((n // 2 - ve[0][1]) + (n // 2 - vo[0][1]))
    else:
        if len(ve) == len(vo) == 1:
            print(n // 2)
        elif len(ve) == 1:
            print((n // 2 - ve[0][1]) + (n // 2 - vo[1][1]))
        elif len(vo) == 1:
            print((n // 2 - ve[1][1]) + (n // 2 - vo[0][1]))
        else:
            print(min((n // 2 - ve[0][1]) + (n // 2 - vo[1][1]), (n // 2 - ve[1][1]) + (n // 2 - vo[0][1])))



if __name__ == '__main__':
    solve()

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
a = []
b = []
for i in range(0,n,2):
    a.append(v[i])
    b.append(v[i+1])
a = Counter(a)
b = Counter(b)
p = a.most_common()[0][1]
q = b.most_common()[0][1]

if a.most_common()[0][0] == b.most_common()[0][0]:
    if p == n//2:
        if q == n//2:
            print(n-p-q+n//2)
        else:
            print(n-q-b.most_common()[1][1])
    else:
        if q != n//2:
            
            print(min(n-p-b.most_common()[1][1],n-q-a.most_common()[1][1]))
        else:
            print(n-q-a.most_common()[1][1])
            
    
        
            
        

else:
    print(n-p-q)

Solution (Python):
from collections import Counter

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

even = Counter(lst[0::2]).most_common(2) + [(0, 0)]
odd = Counter(lst[1::2]).most_common(2) + [(0, 0)]

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

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

a=Counter(v[::2]).most_common(2)
b=Counter(v[1::2]).most_common(2)

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

import sys
input = sys.stdin.readline

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

if n==2:
    ret = 0
    if v[0]==v[1]:
        ret = 1
    print(ret)
    sys.exit()

max_v = max(v)+1
n_odd = v[0::2]
n_even = v[1::2]
n_half = n//2

odd_bucket = [0] * max_v
even_bucket = [0] * max_v

for i in n_odd:
    odd_bucket[i]+=1
for i in n_even:
    even_bucket[i]+=1


odd_max1 = [0,0]
odd_max2 = [0,0]
for i,v in enumerate(odd_bucket):
    if v >= odd_max1[1]:
        odd_max2[0],odd_max2[1] = odd_max1[0],odd_max1[1]
        odd_max1 = [i,v]
    elif v > odd_max2[1]:
        odd_max2 = [i,v]


even_max1 = [0,0]
even_max2 = [0,0]
odd_val = 0
even_val = 0

for i,v in enumerate(even_bucket):
    if v >= even_max1[1]:
        even_max2[0],even_max2[1] = even_max1[0],even_max1[1]
        even_max1 = [i,v]
    elif v > even_max2[1]:
        even_max2 = [i,v]
if odd_max1[0]==even_max1[0] and odd_max1[1]!=odd_max2[1] and even_max1[1]!=even_max2[1]:
    if odd_max1[1] - odd_max2[1] >= even_max1[1] - even_max2[1]:
        odd_val = odd_max1[1]
        even_val = even_max2[1]
    else:
        odd_val = odd_max2[1]
        even_val = even_max1[1]
elif odd_max1[0] != even_max1[0]:
    odd_val = odd_max1[1]
    even_val = even_max1[1]
else:
    if odd_max1[1]==odd_max2[1]:
        odd_val = odd_max2[1]
        even_val = even_max1[1]
    else:
        odd_val = odd_max1[1]
        even_val = even_max2[1]
print(n-odd_val-even_val)

Solution (Python):
import sys
from collections import Counter

sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

c = Counter(A)
v, c = zip(*c.most_common(2))
if max(c) == 1:
	print(N-2)
	sys.exit()
if len(v) < 2:
	print(N//2)
	sys.exit()
a = v[0]
b = v[1]

can_a = [a if i%2 else b for i in range(N)]
can_b = [b if i%2 else a for i in range(N)]


cand = [can_a, can_b]
ans = float('INF')
for c in cand:
	cnt = 0
	for i in range(N):
		if c[i] != A[i]: cnt+=1
	ans = min(ans, cnt)

print(ans)

Solution (Python):
n=int(input())
v=list(input().split())
v1=v[0:n:2]
v2=v[1:n:2]
import collections
c1=collections.Counter(v1)
a1=c1.most_common()[0][0]
a2=(c1.most_common()[1][0] if len(c1)>=2 else 0)
c2=collections.Counter(v2)
b1=c2.most_common()[0][0]
b2=(c2.most_common()[1][0] if len(c2)>=2 else 0)
if a1!=b1:
    cou=0
    for i in range(n//2):
        if v1[i]!=a1:
            cou+=1
    for i in range(n//2):
        if v2[i]!=b1:
            cou+=1
    print(cou)
else:
    cou1=0
    for i in range(n//2):
        if v1[i]!=a2:
            cou1+=1
    for i in range(n//2):
        if v2[i]!=b1:
            cou1+=1
    cou2=0
    for i in range(n//2):
        if v1[i]!=a1:
            cou2+=1
    for i in range(n//2):
        if v2[i]!=b2:
            cou2+=1
    print(min(cou1,cou2))

Solution (Python):
from collections import Counter

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

v_odd=v[::2]
v_even=v[1::2]
c_odd=Counter(v_odd)
cm_odd=c_odd.most_common()
c_even=Counter(v_even)
cm_even=c_even.most_common()

if cm_odd[0][0]!=cm_even[0][0]:
    ans=(len(v_odd)-cm_odd[0][1]+len(v_even)-cm_even[0][1])
elif len(cm_odd)==1 and len(cm_even)==1:
    ans=n//2
elif len(cm_odd)==1:
    ans=len(v_even)-cm_even[1][1]
elif len(cm_even)==1:
    ans=len(v_odd)-cm_odd[1][1]
else:
    ans=min((len(v_odd)-cm_odd[1][1])+(len(v_even)-cm_even[0][1]),(len(v_odd)-cm_odd[0][1])+(len(v_even)-cm_even[1][1]))
print(ans)

Solution (Python):
import collections
n=int(input())
v=list(map(int,input().split()))
v1=v[0::2]
v2=v[1::2]
c1=collections.Counter(v1)
c2=collections.Counter(v2)
arr1=c1.most_common()[1:]
arr2=c2.most_common()[1:]
arr21=c1.most_common()[:1]+c1.most_common()[2:]
arr22=c2.most_common()[:1]+c2.most_common()[2:]
arr1n=sum([a[1] for a in arr1])
arr2n=sum([a[1] for a in arr2])
arr21n=sum([a[1] for a in arr21])
arr22n=sum([a[1] for a in arr22])
if c1.most_common()[0][0]==c2.most_common()[0][0]:
  if arr21n<=arr22n:
    print(arr21n+arr2n)
  else:
    print(arr22n+arr1n)
else:
  print(arr1n+arr2n)

Solution (Python):
from collections import Counter

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

even = list(Counter(v[0::2]).items())
odd = list(Counter(v[1::2]).items())

even.append([0,0])
odd.append([0,0])
even.sort(key=lambda x: -x[1])
odd.sort(key=lambda x: -x[1])

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

Solution (Python):
n = int(input())
v = [int(i) for i in input().split()]
if [v[0]] * n == v:
    print(n // 2)
    exit()
even_n = {}
odd_n = {}
for i in range(0, n):
    if (i + 1) % 2 == 0:
        if str(v[i]) in even_n:
            even_n[str(v[i])] += 1
        else:
            even_n[str(v[i])] = 1
    if (i + 1) % 2 == 1:
        if str(v[i]) in odd_n:
            odd_n[str(v[i])] += 1
        else:
            odd_n[str(v[i])] = 1
even_n = sorted(even_n.items(), key=lambda x: x[1], reverse=True)
odd_n = sorted(odd_n.items(), key=lambda x: x[1], reverse=True)
unchanged = 0
if even_n[0][0] != odd_n[0][0]:
    unchanged = even_n[0][1] + odd_n[0][1]
else:
    unchanged = max(even_n[0][1] + odd_n[1][1], even_n[1][1] + odd_n[0][1])
print(n - unchanged)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a1=a[::2]
a2=a[1::2]
if a1==a2 and len(set(a1))==1:
    print(n//2)
    exit()
import collections as c
c1=c.Counter(a1)
c2=c.Counter(a2)
c1=c1.most_common()
c2=c2.most_common()
ans=0
if c1[0][0]==c2[0][0]:
    ans=min((n//2-c1[0][1])+(n//2-c2[1][1]),(n//2-c1[1][1])+(n//2-c2[0][1]))
else:
    ans=(n//2-c1[0][1])+(n//2-c2[0][1])
print(ans)

Solution (Python):

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

M = 10**5
C = [0 for i in range(M)]
D = [0 for i in range(M)]
for i in range(N):
    if i%2 == 0:
        C[V[i]-1]+=1
    else:
        D[V[i]-1]+=1
        
c,d = (N+1)//2,N//2

MC = max(C)
MD = max(D)

ans = 0
if C.index(MC) == D.index(MD):
    C[C.index(MC)]-=MC
    D[D.index(MD)]-=MC
    
    MC2 = max(C)
    MD2 = max(D)
    if c-MC + d-MD2 >= c-MC2 + d-MD:
        ans = c-MC2 + d-MD
    else:
        ans = c-MC + d-MD2
    
else:
    ans = c-MC + d-MD

print(ans)

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

from collections import Counter
l1 = Counter(l[0::2])
mostl1 = l1.most_common()[0]


l2 = Counter(l[1::2])
mostl2 = l2.most_common()[0]


if mostl1[0] != mostl2[0]:
    print(n-mostl1[1]-mostl2[1])
elif len(l1.keys()) == 1 and len(l2.keys()) == 1:
    print(int(n/2))

else:
    semimostl1 = l1.most_common()[1]
    semimostl2 = l2.most_common()[1]
    print(min(n - mostl1[1] - semimostl2[1], n - semimostl1[1] - mostl2[1]))

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
A=[]
B=[]
for i in range(n):
    if i%2==0:
        a.append(v[i])
        A.append([0,0])
    else:
        b.append(v[i])
        B.append([0,0])
a.sort()
b.sort()

A[0][1]=a[0]
B[0][1]=b[0]

x=a[0]
y=0
for j in range(len(a)):
  if a[j]==x:
    A[y][0]+=1
  else:
    x=a[j]
    y+=1
    A[y][1]=x
    A[y][0]+=1
    
w=b[0]  
z=0
for k in range(len(b)):
  if b[k]==w:
    B[z][0]+=1
   
  else:
    w=b[k]
    z+=1
    B[z][1]=w
    B[z][0]+=1 
    
A=sorted(A,key=lambda x:x[0],reverse=True) 
B=sorted(B,key=lambda x:x[0],reverse=True)  
if A[0][1]==B[0][1]:
    print(min(n-A[0][0]-B[1][0],n-A[1][0]-B[0][0]))
elif n-A[0][0]-B[0][0]==0 and A[0][1]==B[0][1]:
    print(int(n/2))
else:
    print(n-A[0][0]-B[0][0])

Solution (Python):
import collections

n=int(input())
a=list(map(int,input().split()))
a1=[a[2*i] for i in range(n-n//2)]
a2=[a[2*i+1] for i in range(n//2)]
c1=collections.Counter(a1)
c2=collections.Counter(a2)
e1=c1.most_common()
e2=c2.most_common()
d1=e1[0]
d2=e2[0]
if d1[0]!=d2[0]:
    print(n-d1[1]-d2[1])
elif len(e1)==1 and len(e2)==1:
    print(min(d1[1],d2[1]))
elif len(e1)==1:
    print(min((n//2-d2[1])+d1[1],n//2-e2[1][1]))
elif len(e2)==1:
    print(min((n-n//2-d1[1])+d2[1],n-n//2-e1[1][1]))
else:
    print(n-max(d1[1]+e2[1][1],d2[1]+e1[1][1]))

Solution (Python):

import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n=int(input())
v=list(map(int,input().split()))
v1=[]
v2=[]
for i in range(n):
    if i%2==1:
        v2.append(v[i])
    else:
        v1.append(v[i])
c1=collections.Counter(v1)
c2=collections.Counter(v2)
c1[0]=0;c2[0]=0
c1 = sorted(c1.items(), key=lambda tup: -tup[1])
c2 = sorted(c2.items(), key=lambda tup: -tup[1])

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

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
v.insert(0,0) 
check=0 
now=v[1]
for i in range(2,n):
    if now!=v[i]:
        check=1
        break
        
odd=[]
even=[]
for i in range(1,n+1):
    if i%2==1:
        odd.append(v[i])
    else:
        even.append(v[i])
        
odd2=sorted(odd)
even2=sorted(even)
now_odd,now_even=odd2[0],even2[0]
rensa_odd,rensa_even=1,1
half=n//2
count_odd=[]
count_even=[]

for i in range(1,half):
    if odd2[i]==now_odd:
        rensa_odd+=1
    else:
        count_odd.append([rensa_odd,now_odd])
        now_odd=odd2[i]
        rensa_odd=1
count_odd.append([rensa_odd,now_odd])

for i in range(1,half):
    if even2[i]==now_even:
        rensa_even+=1
    else:
        count_even.append([rensa_even,now_even])
        now_even=even2[i]
        rensa_even=1
count_even.append([rensa_even,now_even])
count_odd2=sorted(count_odd,reverse=True)
count_even2=sorted(count_even,reverse=True)


if check==0:
    print(half)
else:
    if count_odd2[0][1]!=count_even2[0][1]: 
        print((half-count_odd2[0][0])+(half-count_even2[0][0]))
    else:
        if len(count_odd2)==1:
            print((half-count_odd2[0][0])+(half-count_even2[1][0]))
        elif len(count_even2)==1:
            print((half-count_odd2[1][0])+(half-count_even2[0][0]))
        else:
            print(min((half-count_odd2[0][0])+(half-count_even2[1][0]),(half-count_odd2[1][0])+(half-count_even2[0][0])))

Solution (Python):
import collections

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

V_odd = [V[i] for i in range(0, n, 2)]
V_even = [V[i] for i in range(1, n, 2)]

c_odd = collections.Counter(V_odd)
c_even = collections.Counter(V_even)

list_odd = []
list_even = []

for k, v in c_odd.items():
    list_odd.append([v, k])
list_odd = sorted(list_odd, reverse=True)

for k, v in c_even.items():
    list_even.append([v, k])
list_even = sorted(list_even, reverse=True)

if list_odd[0][1] == list_even[0][1]:
    if len(list_odd) == 1:
        print(n - list_even[0][0])
    elif len(list_even) == 1:
        print(n - list_odd[0][0])
    else:
        print(min(n - list_odd[0][0] - list_even[1][0],
                  n - list_odd[1][0] - list_even[0][0]))
else:
    print(n - list_odd[0][0] - list_even[0][0])

Solution (Python):
n = int(input())
v = [int(i) for i in input().split()]
odd = [[0,i] for i in range(10**5+1)]
even = [[0,i] for i in range(10**5+1)]
for i in v[0:n-1:2]:
    odd[i][0] += 1
for i in v[1:n:2]:
    even[i][0] += 1
odd.sort(reverse=True)
even.sort(reverse=True)
if odd[0][1] != even[0][1]:
    ans = n//2 - odd[0][0] + n//2 - even[0][0]
else:
    ans=min(n//2-odd[0][0]+n//2-even[1][0],n//2-odd[1][0]+n//2-even[0][0])
print(ans)

Solution (Python):
import collections
n = int(input())
list1 = list(map(int,input().split()))
list2n = list1[::2]
list2n_1 = list1[1::2]
c2n = collections.Counter(list2n)
c2n_1 = collections.Counter(list2n_1)
c2n_mc = c2n.most_common(2)
c2n_1_mc = c2n_1.most_common(2)

if c2n_mc[0][0] == c2n_1_mc[0][0]:
    if len(c2n_mc) == 1 and len(c2n_1_mc)==1:
        if c2n_mc[0][0] == c2n_1_mc[0][0]:
            ans = n//2
        else:
            ans = 0
    elif len(c2n_mc)==1 or len(c2n_1_mc)==1:
        if len(c2n_mc)==1:
            ans = n - c2n_mc[0][1] - c2n_1_mc[1][1]
        else:
            ans = n - c2n_1_mc[0][1] - c2n_mc[1][1]
    elif c2n_mc[1][1] <= c2n_1_mc[1][1]:
        ans = n - c2n_mc[0][1] - c2n_1_mc[1][1]
    else:
        ans = n - c2n_1_mc[0][1] - c2n_mc[1][1]
else:
    ans = n - c2n_mc[0][1] - c2n_1_mc[0][1]
print(ans)

Solution (Python):
from collections import Counter
import sys
input = sys.stdin.readline
 
def solve(N,V):
    V_odd = Counter(V[::2]).most_common(2)
    V_even = Counter(V[1::2]).most_common(2)
 
    if V_odd[0][0] == V_even[0][0]:
        if len(V_odd) == 1 or len(V_even) == 1:
            print(n//2)
        else:
            print(N-max(V_odd[0][1]+V_even[1][1], V_odd[1][1]+V_even[0][1]))
    else:
        print(N-V_odd[0][1]-V_even[0][1])
 
if __name__ == "__main__":
    n = int(input())
    v = list(map(int,input().split()))
    solve(n,v)

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

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

v1 = [v for i, v in enumerate(vn) if i % 2 == 0]
v2 = [v for i, v in enumerate(vn) if i % 2 != 0]
v1cnt = Counter(v1)
v2cnt = Counter(v2)
maxv11 = 0
maxv12 = 0
maxv21 = 0
maxv22 = 0
c_ = 0
for v, c in v1cnt.items():
    if c > c_:
        maxv12 = c_
        c_ = c
        maxv1 = [v]
    elif c == c_:
        maxv1.append(v)
    else:
        maxv12 = max(maxv12, c)

c_ = 0
for v, c in v2cnt.items():
    if c > c_:
        maxv22 = c_
        c_ = c
        maxv2 = [v]
    elif c == c_:
        maxv2.append(v)
    else:
        maxv22 = max(maxv22, c)

if maxv1 != maxv2 or len(maxv1) > 1 or len(maxv2) > 1:
    print(len(v1) - max(v1cnt.values()) + len(v2) - max(v2cnt.values()))
else:
    print(min(len(v1) - max(v1cnt.values()) + len(v2) - maxv22, \
        len(v1) - maxv12 + len(v2) - max(v2cnt.values())))

Solution (Python):


n=int(input())
w=list(map(int,input().split()))
ans=0
if len(set(w))==1:
    print(len(w)//2)
else:
    a=[]
    a1=[]
    for i in range(n):
        if i%2==0:
            a.append(w[i])
        else:
            a1.append(w[i])
    a.sort()
    a1.sort()
    ans=0
    t=a[0]
    cnt1=[]
    cnt=[]
    b=[]
    b1=[]
    for j in range(len(a)):
        if a[j]==t:
            ans+=1
        else:
            cnt.append([ans,t])
            t=a[j]
            ans=1
        if j==len(a)-1:
            cnt.append([ans,t])
    s=a1[0]
    ans=0
    for j in range(len(a)):
        if a1[j]==s:
            ans+=1
        else:
            cnt1.append([ans,s])
            s=a1[j]
            ans=1
        if j==len(a1)-1:
            cnt1.append([ans,s])
    cnt.sort(reverse=True)
    cnt1.sort(reverse=True)
    """
    print(a)
    print(a1)
    print(cnt)
    print(cnt1)
    """
    if cnt[0][1]!=cnt1[0][1]:
        print(n-cnt[0][0]-cnt1[0][0])
    else:
        if cnt[0][0]>cnt1[0][0]:
            print(n-cnt[0][0]-cnt1[1][0])
        elif cnt[0][0]<cnt1[0][0]:
            print(n-cnt1[0][0]-cnt[1][0])
        else:
            t=0
            s=0
            for i in range(1,min(len(cnt),len(cnt1))):
                if cnt[i][0]!=cnt1[i][0]:
                    if cnt[i][0]==max(cnt[i][0],cnt1[i][0]):
                        t=cnt[i][0]
                        s=cnt1[0][0]
                        break
                if cnt[i][0]!=cnt1[i][0]:
                    if cnt1[i][0]==max(cnt[i][0],cnt1[i][0]):
                        t=cnt1[i][0]
                        s=cnt[0][0]
                        break
                if i==-1+min(len(cnt),len(cnt1)):
                    t=cnt[0][0]
                    s=cnt1[1][0]
            print(n-t-s)

Solution (Python):
n = int(input())
u = list(map(int, input().split()))
A = []
B = []
Af = [[i, -1] for i in range(100007)]
Bf = [[i, -1] for i in range(100007)]
for i in range(n):
    if i % 2 == 0:
        A.append(u[i])
        Af[u[i]][1] += 1
    else:
        B.append(u[i])
        Bf[u[i]][1] += 1

Af.sort(key=lambda x: -x[1])
Bf.sort(key=lambda x: -x[1])

Ae = 0
Be = 0
ans = 0
if Af[0][0] == Bf[0][0]:
    Ae = Af[0][0]
    Be = Bf[1][0]
    ans1 = 0
    for i in range(len(A)):
        if Ae != A[i]:
            ans1 += 1
    for i in range(len(B)):
        if Be != B[i]:
            ans1 += 1

    Ae = Af[1][0]
    Be = Bf[0][0]
    ans2 = 0
    for i in range(len(A)):
        if Ae != A[i]:
            ans2 += 1
    for i in range(len(B)):
        if Be != B[i]:
            ans2 += 1
    ans = min(ans1, ans2)
else:
    Ae = Af[0][0]
    Be = Bf[0][0]
    for i in range(len(A)):
        if Ae != A[i]:
            ans += 1
    for i in range(len(B)):
        if Be != B[i]:
            ans += 1

print(ans)

Solution (Python):
import collections

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

vs_odd=vs[::2]
c_odd=collections.Counter(vs_odd) 
C1=c_odd.most_common()
C1.append((0,0))
common1=C1[0][1] 
common1sec=C1[1][1] 

vs_even=vs[1::2]
c_even=collections.Counter(vs_even) 
C2=c_even.most_common()
C2.append((0,0))
common2=C2[0][1] 
common2sec=C2[1][1] 

Ans1=len(vs_odd)-common1
Ans2=len(vs_even)-common2
Ans3=len(vs_odd)-common1sec
Ans4=len(vs_even)-common2sec

if c_odd.most_common()[0][0] == c_even.most_common()[0][0]:
    
    print(min(Ans1+Ans4, Ans2+Ans3))
else:
    print(Ans1+Ans2)