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*
n,*v=map(int,open(0).read().split())
a=Counter(v[::2]).most_common()+[(0,0)]
b=Counter(v[1::2]).most_common()+[(0,0)]
if a[0][0]==b[0][0]:
    print(min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1]))
else:
    print(n-a[0][1]-b[0][1])

Solution (Python):
from collections import*
n,*v=map(int,open(0).read().split())
a=Counter(v[::2]).most_common()
b=Counter(v[1::2]).most_common()
if a[0][0]==b[0][0]:
    if len(a)>1and len(b)>1:
        print(min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1]))
    elif len(a)>1:
        print(n-a[1][1]-b[0][1])
    elif len(b)>1:
        print(n-a[0][1]-b[1][1])
    else:
        print(n//2)
else:
    print(n-a[0][1]-b[0][1])

Solution (Python):

import sys
from collections import *

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

if not n:
    print(0)
    sys.exit()

n1 = Counter(v[::2])
n2 = Counter(v[1::2])

max1 = 0

n1 = sorted([(count, k) for k, count in n1.items()], reverse=True)
n2 = sorted([(count, k) for k, count in n2.items()], reverse=True)

if n1[0][1] == n2[0][1]:
    if len(n1) == 1 and len(n2) == 1:
        print(n//2)
        sys.exit()
    if len(n1) == 1 or n1[0][0] > n2[0][0]:
        print(n - n1[0][0] - n2[1][0])
        sys.exit()
    if len(n2) == 1 or n1[0][0] < n2[0][0]:
        print(n - n1[1][0] - n2[0][0])
        sys.exit()
    if n1[0][0] == n2[0][0]:
        if n1[1][0] >= n2[1][0]:
            print(n - n1[1][0] - n2[0][0])
        elif n1[1][0] < n2[1][0]:
            print(n - n1[0][0] - n2[1][0])
        sys.exit()

count = n - n1[0][0] - n2[0][0]
print(count)

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
cnt = [[0 for j in range(10**5)] for i in range(2)]
for i in range(n):
  cnt[i%2][v[i]-1] += 1
maxce = max(cnt[0])
maxco = max(cnt[1])
maxve = -1
maxvo = -1
for i in range(len(cnt[0])):
  if(cnt[0][i] == maxce):
    maxve = i
    break
for i in range(len(cnt[1])):
  if(cnt[1][i] == maxco):
    maxvo = i
    break
if(maxvo != maxve):
  print((n//2 - maxco) + (n - n//2 - maxce))
else:
  cnt[0].pop(maxve)
  cnt[1].pop(maxvo)
  maxce2 = max(cnt[0])
  maxco2 = max(cnt[1])
  print(min((n//2 - maxco2) + (n - n//2 - maxce), (n//2 - maxco) + (n - n//2 - maxce2)))

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

nums1 = nums[0::2]
nums2 = nums[1::2]

bug1 = [0] * 100001
bug2 = [0] * 100001

for num in nums1:
    bug1[num] += 1

for num in nums2:
    bug2[num] += 1

max_v_1 = max(bug1)
max_i_1 = bug1.index(max_v_1)
max_v_2 = max(bug2)
max_i_2 = bug2.index(max_v_2)

if max_i_1 == max_i_2:
    bug1[max_i_1] = 0
    bug2[max_i_2] = 0
    sec_max_v_1 = max(bug1)
    sec_max_v_2 = max(bug2)
    print(n - min(max_v_1, max_v_2) - max(sec_max_v_1, sec_max_v_2))
else:
    print(n - max_v_1 - max_v_2)

Solution (Python):
import collections
N = int(input())
a = input().split( )

ret = [0]

odds = []
evens = []
for i in range(N):
    if i % 2 == 0:
        odds.append(int(a[i]))
    else:
        evens.append(int(a[i]))

codds = collections.Counter(odds)
cevens = collections.Counter(evens)

if codds.most_common()[0][0] ==cevens.most_common()[0][0]:
    if codds.most_common()[0][1] > cevens.most_common()[0][1]:
        codds = sorted(list(codds.values()))
        cevens = sorted(list(cevens.values()))
        if len(codds) > 1:
            codds.pop(-1)
        else:
            codds = [0]
        if len(cevens) > 1:
            cevens.pop(-2)
    elif codds.most_common()[0][1] < cevens.most_common()[0][1]:
        codds = sorted(list(codds.values()))
        cevens = sorted(list(cevens.values()))
        if len(codds) > 1:
            codds.pop(-2)
        if len(cevens) > 1:
            cevens.pop(-1)
        else:
            cevens = [0]
    else:
        if len(codds) == 1 and len(cevens) == 1:
            codds = [0]
            cevens = sorted(list(cevens.values()))
        elif codds.most_common()[1][1] > cevens.most_common()[1][1]:
            codds = sorted(list(codds.values()))
            cevens = sorted(list(cevens.values()))
            codds.pop(-2)
            cevens.pop(-1)
        else:
            codds = sorted(list(codds.values()))
            cevens = sorted(list(cevens.values()))
            codds.pop(-1)
            cevens.pop(-2)

else:
    codds = sorted(list(codds.values()))
    cevens = sorted(list(cevens.values()))
    if len(codds) > 1:
        codds.pop(-1)
    else:
        codds= [0]
    if len(cevens) > 1:
        cevens.pop(-1)
    else:
        cevens = [0]

print(sum(codds) + sum(cevens))

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

list_1=list[::2]
list_2=list[1::2]


a=collections.Counter(list_1)
b=collections.Counter(list_2)


if((a.most_common()[0]==b.most_common()[0]) & (a.most_common()[0][1]!=len(list_1))):
  
  if(n-a.most_common()[0][1]-b.most_common()[1][1]>n-a.most_common()[1][1]-b.most_common()[0][1]):
  	print(n-a.most_common()[1][1]-b.most_common()[0][1])
  else:
    print(n-a.most_common()[0][1]-b.most_common()[1][1])
elif ((a.most_common()==b.most_common()) & (a.most_common()[0][1]==len(list_1))):
  
  print(n//2)
else:
  
  
  
  
  
  

  print(n-a.most_common()[0][1]-b.most_common()[0][1])

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

os=dict()
es=dict()
for i in range(N//2):
    os[v[2*i]] = os.get(v[2*i], 0) + 1
    es[v[2*i+1]] = es.get(v[2*i+1], 0) + 1

osr=sorted(os.items(), key=lambda x: (x[1], x[0]))
esr=sorted(es.items(), key=lambda x: (x[1], x[0]))

osv = osr.pop()
esv = esr.pop()

o1n = N//2 - osv[1]
e1n = N//2 - esv[1]

count = o1n + e1n
if osv[0] == esv[0]:
    if len(osr) == 0:
        o2n = N//2
    else:
        o2n = N//2 - osr.pop()[1]
    if len(esr) == 0:
        e2n = N//2
    else:
        e2n = N//2 - esr.pop()[1]

    count = min(o1n + e2n, o2n + e1n)

print(count)

Solution (Python):
from collections import Counter
N=int(input())
NN=N//2
l=list(map(int,input().split()))
l1=[l[2*i] for i in range(NN)]
l2=[l[2*i+1] for i in range(NN)]
l1c=Counter(l1)
l2c=Counter(l2)
r1=l1c.most_common()
r2=l2c.most_common()
if r1[0][0]==r2[0][0]:
  if r1[0][1]==NN and r2[0][1]==NN:
    ans=NN
  elif r1[0][1]>r2[0][1]:
    ans=N-r1[0][1]-r2[1][1]
  elif r1[0][1]<r2[0][1]:
    ans=N-r1[1][1]-r2[0][1]
  else:
    if r1[1][1]>r2[1][1]:
      ans=N-r1[1][1]-r2[0][1]
    else:
      ans=N-r1[0][1]-r2[1][1]
else:
  ans=N-r1[0][1]-r2[0][1]
print(ans)

Solution (Python):
import collections
n = int(input())
all_list_str = input()










all_list = list(map(int, all_list_str.split()))

odd_list = [all_list[i] for i in range(1, n, 2)]
even_list = [all_list[i] for i in range(0, n - 1, 2)]

c = collections.Counter(odd_list)
c_odd_list = c.most_common()

c = collections.Counter(even_list)
c_even_list = c.most_common()

if (c_odd_list[0][0] != c_even_list[0][0]):
    odd_target = c_odd_list[0][0]
    even_target = c_even_list[0][0]
elif (c_odd_list[0][1] > c_even_list[0][1]):
    odd_target = c_odd_list[0][0]
    even_target = c_even_list[1][0]
elif (c_odd_list[0][1] < c_even_list[0][1]):
    odd_target = c_odd_list[1][0]
    even_target = c_even_list[0][0]
else:
    if (len(c_odd_list) == 1 and len(c_even_list) == 1):
        odd_target = c_odd_list[0][0]
        even_target = odd_target + 1    
    elif (len(c_odd_list) == 1):
        odd_target = c_odd_list[0][0]
        even_target = c_even_list[1][0]
    elif (len(c_even_list) == 1):
        odd_target = c_odd_list[1][0]
        even_target = c_even_list[0][0]
    elif (c_odd_list[1][1] > c_even_list[1][1]):
        odd_target = c_odd_list[1][0]
        even_target = c_even_list[0][0]
    else:
        odd_target = c_odd_list[0][0]
        even_target = c_even_list[1][0]

print(str(len(odd_list) - odd_list.count(odd_target) + len(even_list) - even_list.count(even_target)))

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

def solve(arr1, arr2):
    cnt1 = Counter(arr1)
    cnt2 = Counter(arr2)

    most1 = cnt1.most_common()
    most2 = cnt2.most_common()

    
    most1.append(('_', 0))
    most2.append(('_', 0))

    
    if most1[0][0] != most2[0][0]:
        return len(arr1) * 2 - most1[0][1] - most2[0][1]
    
    else:
        ans1 = len(arr1) * 2 - most1[0][1] - most2[1][1]
        ans2 = len(arr1) * 2 - most1[1][1] - most2[0][1]
        return min(ans1, ans2)

arr1 = As[0::2]
arr2 = As[1::2]
print(solve(arr1, arr2))

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

temp1 = [0] * (100000 + 1)

for i in range(N//2):
    a = V[2*i]
    temp1[a] += 1

te1 = []
for i in range(100001):
    te1.append((temp1[i], i))

temp2 = [0] * (100000 + 1)

for i in range(N//2):
    a = V[2*i+1]
    temp2[a] += 1

te2 = []
for i in range(100001):
    te2.append((temp2[i], i))

te1.sort()
te1.reverse()
te2.sort()
te2.reverse()

if te1[0][1] != te2[0][1]:
    res = N - te1[0][0] - te2[0][0]
else:
    res = N - max(te1[1][0] + te2[0][0], te1[0][0] + te2[1][0])

print(res)

Solution (Python):
from collections import Counter

N = int(input())
V = [int(x) for x in input().split()]
if all(v == V[0] for v in V):
    print(N // 2)
    quit()
even = Counter([v for i, v in enumerate(V) if i % 2 == 0])
odd = Counter([v for i, v in enumerate(V) if i % 2 != 0])
evens = even.most_common()
odds = odd.most_common()
if evens[0][0] != odds[0][0]:
    print(N - evens[0][1] - odds[0][1])
elif len(evens) == len(odds) == 1:
    print(N // 2)
elif len(evens) == 1:
    print(min(N - odds[0][1], N - len(evens) - odds[1][1]))
elif len(odds) == 1:
    print(min(N - evens[0][1], N - len(odds) - evens[1][1]))
else:
    print(min(N - evens[0][1] - odds[1][1], N - evens[1][1] - odds[0][1]))

Solution (Python):
n=int(input())
s=input().split()
s=[int(o) for o in s]
left=dict()
right=dict()
def count_nums(mydict,o):
  if o in mydict.keys():
    mydict[o]+=1
  else:
    mydict[o]=1
flag=True
for o in s:
  if flag:
    count_nums(left,o)
    flag=False
  else:
    count_nums(right,o)
    flag=True
myleft=sorted(left.keys(),key=lambda x: left[x])
myright=sorted(right.keys(),key=lambda x: right[x])
if myleft[-1]!=myright[-1]:
  print( len(s)-left[myleft[-1]]-right[myright[-1]])
else:
  a0,b0=left[myleft[-1]],right[myright[-1]]
  a1=0 if len(myleft)==1 else left[myleft[-2]]
  b1=0 if len(myright)==1 else right[myright[-2]]
  print( len(s)-max(a0+b1,a1+b0))

Solution (Python):



import sys
import collections

sys.setrecursionlimit(10 ** 6)

read_single_int = lambda: int(sys.stdin.readline().strip())
read_list_int = lambda: list(map(int, sys.stdin.readline().strip().split(' ')))


def solution(n: int, vs: list):
    map_a = collections.defaultdict(lambda: 0)
    map_b = collections.defaultdict(lambda: 0)

    for i in range(0, n, 2):
        map_a[vs[i]] += 1
        map_b[vs[i+1]] += 1

    pair_a = [(k, map_a[k]) for k in map_a.keys()]        
    pair_b = [(k, map_b[k]) for k in map_b.keys()]

    pair_a = sorted(pair_a, key=lambda x: x[1], reverse= True)
    pair_b = sorted(pair_b, key=lambda x: x[1], reverse= True)

    first_a, second_a = pair_a[0], (0, 0) if len(pair_a) == 1 else pair_a[1]
    first_b, second_b = pair_b[0], (0, 0) if len(pair_b) == 1 else pair_b[1]

    if first_a[0] != first_b[0]:
        return n//2-first_a[1] + n//2-first_b[1]
    else:
        if first_a[1] + second_b[1] < second_a[1] + first_b[1]:
            return n//2-second_a[1] + n//2-first_b[1]

    return n//2-first_a[1] + n//2-second_b[1]


def main():
    n = read_single_int()
    vs = read_list_int()
    print(solution(n, vs))


if __name__ == '__main__':
    main()

Solution (Python):



import sys
import collections

sys.setrecursionlimit(10 ** 6)

read_single_int = lambda: int(sys.stdin.readline().strip())
read_list_int = lambda: list(map(int, sys.stdin.readline().strip().split(' ')))


def solution(n: int, vs: list):
    map_a = collections.defaultdict(lambda: 0)
    map_b = collections.defaultdict(lambda: 0)

    for i in range(0, n, 2):
        map_a[vs[i]] += 1
        map_b[vs[i+1]] += 1


    pair_a = [(k, map_a[k]) for k in map_a.keys()]        
    pair_b = [(k, map_b[k]) for k in map_b.keys()]

    pair_a = sorted(pair_a, key=lambda x: x[1], reverse= True)
    pair_b = sorted(pair_b, key=lambda x: x[1], reverse= True)

    first_a, second_a = pair_a[0], (0, 0) if len(pair_a) == 1 else pair_a[1]
    first_b, second_b = pair_b[0], (0, 0) if len(pair_b) == 1 else pair_b[1]

    if first_a[0] != first_b[0]:
        return n//2-first_a[1] + n//2-first_b[1]
    else:
        if first_a[1] + second_b[1] < second_a[1] + first_b[1]:
            return n//2-second_a[1] + n//2-first_b[1]
        else:
            return n//2-first_a[1] + n//2-second_b[1]

    return 0


def main():
    n = read_single_int()
    vs = read_list_int()
    print(solution(n, vs))


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

n = int(input().strip())
vs = list(map(int, input().strip().split()))
oddv = [v for i, v in enumerate(vs) if i % 2 == 0]
evenv = [v for i, v in enumerate(vs) if i % 2 == 1]

oddc = Counter(oddv)
evenc = Counter(evenv)
if oddc.most_common(1)[0][0] != evenc.most_common(1)[0][0]:
  print(len(oddv) - oddc.most_common(1)[0][1] + len(evenv) - evenc.most_common(1)[0][1])
else:
  if len(oddc.most_common()) == 1 and len(evenc.most_common()) == 1:
    print(len(oddv))
  elif len(oddc.most_common()) == 1:
    print(len(evenv) - evenc.most_common(2)[1][1])
  elif len(evenc.most_common()) == 1:
    print(len(oddv) - oddc.most_common(2)[1][1])
  else:
    print(min(len(oddv) - oddc.most_common(2)[1][1] + len(evenv) - evenc.most_common(1)[0][1], len(oddv) - oddc.most_common(1)[0][1] + len(evenv) - evenc.most_common(2)[1][1]))

Solution (Python):
n = int(input())
v1 = [0 for i in range(n//2)]
v2 = [0 for i in range(n//2)] 

tmp = list(map(int, input().split()))
for i in range(n//2):
    v1[i], v2[i] = tmp[2 * i], tmp[2 * i + 1]

v1set = {n : 0}
v2set = {n+1 : 0}
for i in range(n//2):
    if v1[i] in v1set:
        v1set[v1[i]] += 1
    else:
        v1set[v1[i]] = 1
    if v2[i] in v2set:
        v2set[v2[i]] += 1
    else:
        v2set[v2[i]] = 1
lis1 = sorted(list(v1set.items()),reverse=True,key = lambda x: x[1])
lis2 = sorted(list(v2set.items()),reverse=True,key = lambda x: x[1])
i1 = 0
i2 = 0
tmp1 = lis1[0][0]
tmp2 = lis2[0][0]
if tmp1 == tmp2:
    print(min(n - lis1[0][1] - lis2[1][1],n - lis2[0][1] - lis1[1][1]))
else:
    print(n - lis1[0][1] - lis2[0][1])

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
odd=v[1::2]
even=v[0::2]
a=Counter(odd)
b=Counter(even)
if a.most_common()[0][0]!=b.most_common()[0][0]:
    print(n-a.most_common()[0][1]-b.most_common()[0][1])
else:
    if len(a)>1 and len(b)>1:
        print(min(n-a.most_common()[0][1]-b.most_common()[1][1],n-a.most_common()[1][1]-b.most_common()[0][1]))
    elif len(a)>1 and len(b)==1:
        print(n-a.most_common()[1][1]-b.most_common()[0][1])
    elif len(a)==1 and len(b)>1:
        print(n-a.most_common()[0][1]-b.most_common()[1][1])
    elif len(a)==1 and len(b)==1:
        print(n//2)

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

nums1 = nums[0::2]
nums2 = nums[1::2]

bug1 = [0] * 100001
bug2 = [0] * 100001

for num in nums1:
    bug1[num] += 1

for num in nums2:
    bug2[num] += 1

max_v_1 = max(bug1)
max_i_1 = bug1.index(max_v_1)
max_v_2 = max(bug2)
max_i_2 = bug2.index(max_v_2)

if max_i_1 == max_i_2:
    bug1[max_i_1] = 0
    bug2[max_i_2] = 0
    sec_max_v_1 = max(bug1)
    sec_max_v_2 = max(bug2)
    print(n - max(max_v_1, max_v_2) - max(sec_max_v_1, sec_max_v_2))
else:
    print(n - max_v_1 - max_v_2)

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

nums1 = nums[0::2]
nums2 = nums[1::2]

bug1 = [0] * 100001
bug2 = [0] * 100001

for num in nums1:
    bug1[num] += 1

for num in nums2:
    bug2[num] += 1

max_v_1 = max(bug1)
max_i_1 = bug1.index(max_v_1)
max_v_2 = max(bug2)
max_i_2 = bug2.index(max_v_2)

if max_i_1 == max_i_2:
    bug1[max_i_1] = 0
    bug2[max_i_2] = 0
    sec_max_v_1 = max(bug1)
    sec_max_v_2 = max(bug2)
    print(n - min(max_v_1, max_v_2) - max(sec_max_v_1, sec_max_v_2))
else:
    print(n - max_v_1 - max_v_2)

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

nums1 = nums[0::2]
nums2 = nums[1::2]

bug1 = [0] * 1000000
bug2 = [0] * 1000000

for num in nums1:
    bug1[num] += 1

for num in nums2:
    bug2[num] += 1

max_v_1 = max(bug1)
max_i_1 = bug1.index(max_v_1)
max_v_2 = max(bug2)
max_i_2 = bug2.index(max_v_2)

if max_i_1 == max_i_2:
    bug1[max_i_1] = 0
    bug2[max_i_2] = 0
    sec_max_v_1 = max(bug1)
    sec_max_v_2 = max(bug2)
    print(n - min(max_v_1, max_v_2) - max(sec_max_v_1, sec_max_v_2))
else:
    print(n - max_v_1 - max_v_2)

Solution (Python):
def I():return input()
def II():return int(input())
def LI():return list(map(int, input().split()))
def L():return input().split()

def count_num(lis):
    v = {}
    for i in lis:
        if i not in v.keys():
            v[i] = 1
        else:
            v[i] += 1
    return v
def dict_to_list(dic):
    ret = []
    for i in dic.keys():
        ret.append([i,dic[i]])
    return ret

def main():
    n = II()
    e = n//2
    o = e + n%2

    v = LI()
    v_o = count_num(v[::2])
    v_e = count_num(v[1::2])
    cnt_o = dict_to_list(v_o)
    cnt_e = dict_to_list(v_e)
    cnt_o.sort(key=lambda x: x[1], reverse=True)
    cnt_e.sort(key=lambda x: x[1], reverse=True)
    
    cnt_o.append([0,0])
    cnt_e.append([0,0])
    if cnt_e[0][0] != cnt_o[0][0]:
        ans = (e - cnt_e[0][1]) + (o - cnt_o[0][1])
    else:
        ans = min((e-cnt_e[0][1]) + (o-cnt_o[1][1]), (e-cnt_e[1][1]) + (o-cnt_o[0][1]))
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
v=list(input().split())
v0={}
v1={}
for i in range(0,n,2):
    if v[i] in v0:
        v0[v[i]]+=1
    else:
        v0[v[i]]=1
for i in range(1,n,2):
    if v[i] in v1:
        v1[v[i]]+=1
    else:
        v1[v[i]]=1
v0=sorted(v0.items(), key=lambda x:x[1], reverse=True)
v1=sorted(v1.items(), key=lambda x:x[1], reverse=True)
if v0[0][0]==v1[0][0]:
    if len(v0)==1:
        print(int(n/2))
    else:
        print(n-v0[0][1]-(v0[1][1] if v0[1][1]>v1[1][1] else v1[1][1] ))
else:
    print(n-v0[0][1]-v1[0][1])

Solution (Python):

n = int(input())
vv = list(map(int, input().split()))
d1 = {}
d2 = {}

for i in range(n):
    v = vv[i]
    if i%2==0:
        if v not in d2:
            d2[v] = 0
        d2[v] += 1
    else:
        if v not in d1:
            d1[v] = 0
        d1[v] += 1

dl1 = sorted(list(d1.keys()), reverse=True, key=lambda k:d1[k])
dl2 = sorted(list(d2.keys()), reverse=True, key=lambda k:d2[k])
i1 = 0
i2 = 0

if len(dl1)==1 and len(dl2)==1:
    if dl1[0]==dl2[0]:
        print(n//2)
    else:
        print(0)
    exit()
elif len(dl1)==1:
    print(sum(sorted(d2.values(), reverse=True)[1:]))
    exit()
elif len(dl2)==1:
    print(sum(sorted(d1.values(), reverse=True)[1:]))
    exit()


if dl1[0]!=dl2[0]:
    res = 0
    res += sum(sorted(d1.values(), reverse=True)[1:])
    res += sum(sorted(d2.values(), reverse=True)[1:])
    print(res)
else:
    res1 = 0
    l = sorted(d1.values(), reverse=True)
    res1 += l[0]
    if len(l)>2:
        res1 += sum(l[2:])
    res1 += sum(sorted(d2.values(), reverse=True)[1:])

    res2 = 0
    l = sorted(d2.values(), reverse=True)
    res2 += l[0]
    if len(l)>2:
        res2 += sum(l[2:])
    res2 += sum(sorted(d1.values(), reverse=True)[1:])
    print(min(res1,res2))

Solution (Python):
n = int(input())
lst = list(map(int, input().split()))
evens = [lst[i] for i in range(0, n, 2)]
odds = [lst[i] for i in range(1, n, 2)]

dic1 = {}
for i in evens:
  if i in dic1:
    dic1[i] += 1
  else:
    dic1[i] = 1

dic2 = {}
for i in odds:
  if i in dic2:
    dic2[i] += 1
  else:
    dic2[i] = 1

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

if lst1[0][0] == lst2[0][0]:
  if len(lst1) == 1 and len(lst2) == 1:
    ans = n // 2
  elif len(lst1) == 1:
    ans = n - (lst1[0][1] + lst2[1][1])
  elif len(lst2) == 1:
    ans = n - (lst1[1][1] + lst2[0][1])
  else:
    ans = n - max(lst1[0][1] + lst2[1][1], lst2[0][1] + lst1[1][1])
else:
  ans = n - (lst1[0][1] + lst2[0][1])

print(ans)

Solution (Python):
from collections import Counter

n = int(input())
lst = list(map(int, input().split()))
lst_odd = Counter(lst[::2])
lst_even = Counter(lst[1::2])
odd = sorted(lst_odd.items(), key=lambda x:x[1], reverse=True)
even = sorted(lst_even.items(), key=lambda x:x[1], reverse=True)

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

print(ans)

Solution (Python):
def solve(size=int(input()), ary=list(map(int, input().split())), max_range=100001):
    even = [0 for _ in range(max_range)]
    odd = [0 for _ in range(max_range)]

    (em, ei), (om, oi) = (0, 0), (0, 0)

    for i in range(size):
        if i % 2 == 0:
            even[ary[i]] += 1
            if even[ary[i]] > em:
                em, ei = even[ary[i]], ary[i]
        else:
            odd[ary[i]] += 1
            if odd[ary[i]] > om:
                om, oi = odd[ary[i]], ary[i]

    if ei == oi:
        even[ei], odd[oi] = 0, 0
        return size - max(max(even) + om, max(odd) + em)
    else:
        return size - (em + om)

print(solve())

Solution (Python):
from collections import Counter
size = int(input())
ary = list(map(int, input().split()))
even, odd = Counter(ary[::2]), Counter(ary[1::2])
even[0], odd[0] = 0, 0
(e, em), (_, es) = even.most_common(2)
(o, om), (_, os) = odd.most_common(2)
print(size - max(em + os, es + om)) if e == o else print(size - em - om)

Solution (Python):
from collections import Counter

def solve(size=int(input()), ary=list(map(int, input().split()))):
    even, odd = Counter(ary[::2]), Counter(ary[1::2])
    even[0], odd[0] = 0, 0
    (e, em), (_, es) = even.most_common(2)
    (o, om), (_, os) = odd.most_common(2)
    return size - max(em + os, es + om) if e == o else size - em - om

print(solve())

Solution (Python):
import collections as c
n = int(input())
P = list(map(int,input().split()))
ans = 0
x = []
y = []
for i in range(n):
    if i % 2 == 0:
        x.append(P[i])
    else:
        y.append(P[i])
p = c.Counter(x)
q = c.Counter(y)

values1, counts1 = zip(*p.most_common())
values2, counts2 = zip(*q.most_common())
if values1[0] == values2[0]:
    if len(values1) == 1 and len(values2) == 1:
        f = n // 2
        g = n // 2
    else:
        f = counts1[0] + counts2[1]
        g = counts1[1] + counts2[0]
    ans = n - max(f, g)
else:
    ans = n - (counts1[0] + counts2[0])

print(ans)

Solution (Python):
import collections


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

v1_1 = collections.Counter(v1).most_common()[0][1]
v2_1 = collections.Counter(v2).most_common()[0][1]

if collections.Counter(v1).most_common()[0][0]==collections.Counter(v2).most_common()[0][0]:
    if v1_1!=n//2 and v2_1!=n//2:
        v1_2 = collections.Counter(v1).most_common()[1][1]
        v2_2 = collections.Counter(v2).most_common()[1][1]
        print(min(n-v2_1-v1_2,n-v1_1-v2_2))
    elif v1_1==n//2 and v2_1==n//2:
        print(n//2)
    elif v1_1!=n//2 and v2_1==n//2:
        v1_2 = collections.Counter(v1).most_common()[1][1]
        print(n-v2_1-v1_2)
    elif v1_1==n//2 and v2_1!=n//2:
        v2_2 = collections.Counter(v2).most_common()[1][1]
        print(n-v2_2-v1_1)
else:
    print(n-v1_1-v2_1)

Solution (Python):
import collections
def inpl(): return [int(i) for i in input().split()]


n = int(input())
v = inpl()
ans = len(v)
v1 = [v[i] for i in range(ans) if i%2 == 0]
v2 = [v[i] for i in range(ans) if i%2 == 1]
cv1 = collections.Counter(v1)
cv2 = collections.Counter(v2)
c11 = cv1.most_common()[0]
if len(cv1) != 1:
    c12 = cv1.most_common()[1]
else: c12 = [0,0]
c21 = cv2.most_common()[0] 
if len(cv2) != 1:
    c22 = cv2.most_common()[1]
else: c22 = [0,0]

if c11[0] == c21[0]:
    ans -= max(c12[1]+c21[1],c11[1]+c22[1])
else:
    ans -= c11[1]+c21[1]
print(ans)

Solution (Python):
n = int(input())
v = list(map(int, input().split()))
v = [[i for e,i in enumerate(v) if e%2 == 0],[i for e,i in enumerate(v) if e%2 == 1]]
dic = [{},{}]
for i in range(2):
    for j in range(n//2):
        k = v[i][j]
        if k in dic[i].keys():
            dic[i][k] += 1
        else:
            dic[i][k] = 1
m1 = max(list(dic[0].values()))
m2 = max(list(dic[1].values()))
i1 = list(dic[0].keys())[list(dic[0].values()).index(m1)]
i2 = list(dic[1].keys())[list(dic[1].values()).index(m2)]
if i1 == i2:
    dic[0][i1] = 0
    dic[1][i2] = 0
    m3 = max(list(dic[0].values()))
    m4 = max(list(dic[1].values()))
    if m2+m3 >= m1+m4:
        print(n-m2-m3)
    elif m2+m3 < m1+m4:
        print(n-m1-m4)
else:
    print(n-m1-m2)

Solution (Python):
from collections import defaultdict

def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

n = getN()
nums = getlist()
lis1 = defaultdict(int)
lis2 = defaultdict(int)

for i,s in enumerate(nums):
    if i % 2 == 0:
        lis1[s] += 1
    else:
        lis2[s] += 1

maxk1 = []
maxv1 = 0
for k in lis1.keys():
    if lis1[k] == maxv1:
        maxk1.append(k)
    elif lis1[k] > maxv1:
        maxv1 = lis1[k]
        maxk1 = [k]

maxk2 = []
maxv2 = 0
for k in lis2.keys():
    if lis2[k] == maxv2:
        maxk2.append(k)
    elif lis2[k] > maxv2:
        maxv2 = lis2[k]
        maxk2 = [k]

v1 = list(lis1.values())
v1.sort(reverse=True)
v1 = v1 + [0]
v2 = list(lis2.values())
v2.sort(reverse=True)
v2 = v2 + [0]

if (len(maxk1) == 1) and (len(maxk2) == 1) and (maxk1[0] == maxk2[0]):
    rem = max(v1[0] + v2[1], v2[0] + v1[1])
    ans = n-rem

else:
    ans = n - maxv1 - maxv2
print(ans)

Solution (Python):
n = int(input())
numbers = [int(x) for x in input().rstrip("\n").split(" ")]

from collections import defaultdict
odd = defaultdict(int)
even = defaultdict(int)
for i in range(0,n,2):
  odd[numbers[i]] += 1
  even[numbers[i+1]] += 1

odd_items = list(reversed(sorted([(count, odd_number) for (odd_number, count) in odd.items()])))

even_items = list(reversed(sorted([(count, even_number) for (even_number, count) in even.items()])))

if odd_items[0][1] != even_items[0][1]:
  print(n - odd_items[0][0] - even_items[0][0])
else:
  if len(odd_items) == 1 and len(even_items) == 1:
    print(n // 2)
  else:
    if len(odd_items) == 1 and len(even_items) == 2:
      print(n - odd_items[0][0] - even_items[1][0])
    elif len(odd_items) == 2 and len(even_items) == 1:
      print(n - odd_items[1][0] - even_items[0][0])
    else:
      second_best1 = n - odd_items[0][0] - even_items[1][0]
      second_best2 = n - odd_items[1][0] - even_items[0][0]
      print(min(second_best1,second_best2))

Solution (Python):
n=int(input())
v=list(map(int,input().split()))
v0=[]
v1=[]
m=int(n/2)
for i in range(m):
    v0.append(v[i*2])
    v1.append(v[i*2+1])
v0.sort()
v1.sort()
mv0=[0,0]
mv1=[0,0]
jmv0=[0,0]
jmv1=[0,0]
c0=[0,0]
c1=[0,0]
for i in range(m):
    if c0[0]==v0[i]:
        c0[1]+=1
    else:
        if mv0[1]<=c0[1]:
            jmv0=mv0
            mv0=c0
        elif jmv0[1]<=c0[1]:
            jmv0=c0
        c0=[v0[i],1]

    if c1[0]==v1[i]:
        c1[1]+=1
    else:
        if mv1[1]<=c1[1]:
            jmv1=mv1
            mv1=c1
        elif jmv1[1]<=c1[1]:
            jmv1=c1
        c1=[v1[i],1]

if mv0[1]<=c0[1]:
            jmv0=mv0
            mv0=c0
elif jmv0[1]<=c0[1]:
            jmv0=c0

if mv1[1]<=c1[1]:
            jmv1=mv1
            mv1=c1
elif jmv1[1]<=c1[1]:
            jmv1=c1

if mv0[0]!=mv1[0]:
    print(n-mv0[1]-mv1[1])
else:
    print(min(n-mv0[1]-jmv1[1],n-jmv0[1]-mv1[1]))

Solution (Python):
from collections import defaultdict
N = int(input())
V = list(map(int, input().split()))
M = 10 ** 5 + 1
V0 = defaultdict(int)
V1 = defaultdict(int)
ma01, ma02 = 0, 0
ma11, ma12 = 0, 0
for i in range(N):
    if i % 2 == 0:
        V0[V[i]] += 1
    else:
        V1[V[i]] += 1

rec0 = []
rec1 = []
for i, k in V0.items():
    rec0.append((i, k))

for i, k in V1.items():
    rec1.append((i, k))

rec0 = sorted(rec0, key=lambda x: x[1], reverse=True)
rec1 = sorted(rec1, key=lambda x: x[1], reverse=True)

if rec0[0][0] != rec1[0][0]:
    print(N - rec0[0][1] - rec1[0][1])
else:
    if len(rec0) == 1 and len(rec1) == 1:
        print(N // 2)
    elif len(rec0) == 1:
        print(N // 2 - rec1[0][1])
    elif len(rec1) == 1:
        print(N // 2 - rec0[0][1])
    else:
        s = rec0[1][1]
        t = rec1[1][1]
        num = min(N - rec0[1][1] - rec1[0][1], N - rec0[0][1] - rec1[1][1])
        print(num)

Solution (Python):


from collections import Counter


def answer():
    n_2 = int(input())
    assert n_2 % 2 == 0
    n = n_2 // 2
    tmp = input()
    values = [int(w) for w in tmp.split()]

    GATE_KEEPER = -1

    values_odd = values[::2]
    values_even = values[1::2]

    counts = [Counter(values_partial).most_common(2) for values_partial in [values_odd, values_even]]
    if counts[0][0][0] != counts[1][0][0]:
        
        ans = sum([n - count[0][1] for count in counts])
    else:
        
        
        for i in range(2):
            counts[i].append((GATE_KEEPER, 0))
        ans = min([(n - counts[0][0][1]) + (n - counts[1][1][1]),
                   (n - counts[0][1][1]) + (n - counts[1][0][1])])
    print(ans)


if __name__ == '__main__':
    answer()

Solution (Python):
from collections import Counter


def check(A):
    N = len(A)
    even = Counter()
    odd = Counter()
    for i, a in enumerate(A):
        if i % 2 == 0:
            odd[a] += 1
        else:
            even[a] += 1
    
    even = even.most_common() + [(None, 0)]
    odd = odd.most_common() + [(None, 0)]
    
    if even[0][0] != odd[0][0]:
        return N - even[0][1] - odd[0][1]
    else:
        return min(N - even[0][1] - odd[1][1], N - odd[0][1] - even[1][1])

N = int(raw_input())
A = map(int, raw_input().split())

ans = check(A)
print ans