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


n = input()
s = input().split(' ')

even = collections.Counter(s[1::2])
odd = collections.Counter(s[0::2])
maxeven = even.most_common()[0]
maxodd = odd.most_common()[0]
ans = 0
if maxeven[0] != maxodd[0]:
    ans = len(s) - maxeven[1] - maxodd[1]
else:
    if len(s) == maxeven[1] + maxodd[1]:
        ans = len(s) - maxeven[1]
    else:
        if maxeven[1] == maxodd[1]:
            nextodd = odd.most_common()[1]
            nexteven = even.most_common()[1]
            ans = len(s) - maxeven[1] -max(nextodd[1], nexteven[1]) 

        elif maxeven[1] > maxodd[1]:
            nextodd = odd.most_common()[1]
            ans = len(s) - maxeven[1] - nextodd[1]
        else:
            nexteven = even.most_common()[1]
            ans = len(s) - maxodd[1] - nexteven[1]

print(ans)

Solution (Python):
import collections

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

odd = [v[2 * i] for i in range(N // 2)]
even = [v[2 * i + 1] for i in range(N // 2)]



odd_dict = sorted(collections.Counter(odd).items(), key=lambda x: x[1])[::-1]
even_dict = sorted(collections.Counter(even).items(), key=lambda x: x[1])[::-1]




if odd_dict[0][0] != even_dict[0][0]:
    odd_sum = N // 2 - odd_dict[0][1]
    even_sum = N//2 - even_dict[0][1]
    
    
    print(odd_sum + even_sum)

else:
    odd_len = len(odd_dict)
    even_len = len(even_dict)

    if (odd_len == 1) and (even_len == 1):
        print(N//2)
    elif (odd_len == 1) and (even_len != 1):
        even_val, even_sec_val = even_dict[0][1], even_dict[1][1]
        print(N//2 - even_sec_val)

    elif (odd_len != 1) and (even_len == 1):
        odd_val, odd_sec_val = odd_dict[0][1], odd_dict[1][1]
        print(N // 2 - odd_sec_val)

    else:
        odd_val, odd_sec_val = odd_dict[0][1], odd_dict[1][1]
        even_val, even_sec_val = even_dict[0][1], even_dict[1][1]
        print(min(N - odd_val - even_sec_val, N - odd_sec_val - even_val))

Solution (Python):

import numpy as np
n = int(input())
v = list(map(int, input().split()))
data1 = [0]*(10**5 + 1)
data2 = [0]*(10**5 + 1)
for i in range(len(v) // 2):
    data1[v[2 * i]] += 1
    data2[v[2 * i + 1]] += 1
result = None
if np.argmax(np.array(data1)) == np.argmax(np.array(data2)):
    data1.sort()
    data2.sort()
    data1.reverse()
    data2.reverse()
    result = min(len(v) - data1[0] - data2[1], len(v) - data1[1] - data2[0])
else:
    data1.sort()
    data2.sort()
    data1.reverse()
    data2.reverse()
    result = len(v) - data1[0] - data2[0]
print(result)

Solution (Python):
from collections import Counter

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





ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

ans = 0
if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n/2)

    elif len(ki) == 1:
        ans = n - ki[0][1] - gu[1][1]

    elif len(gu) == 1:
        ans = n - ki[1][1] - gu[0][1]

    else:
        if ki[1][1] > gu[1][1]:
            ans = n - ki[1][1] - gu[0][1]
        else:
            ans = n - ki[0][1] - gu[1][1]
else:
    ans = n - ki[0][1] - gu[0][1]
print(ans)

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))
d0 = {0:0}
d1 = {0:0}
for i,a in enumerate(arr):
  if i%2==0:
    if a not in d0:
      d0[a] = 1
    else:
      d0[a] += 1
  else:
    if a not in d1:
      d1[a] = 1
    else:
      d1[a] += 1
pairs0 = sorted(d0.items(), key=lambda x:x[1])[::-1]
pairs1 = sorted(d1.items(), key=lambda x:x[1])[::-1]
a0, maxlen0 = pairs0[0]
a1, maxlen1 = pairs1[0]

if a0!=a1:
  print(n - maxlen0 - maxlen1)
else:
  if maxlen0<maxlen1:
    print(n - maxlen1 - pairs0[1][1])
  elif maxlen0>maxlen0:
    print(n - maxlen0 - pairs1[1][1])
  else:
    if len(pairs0)>len(pairs1):
      pairs0, pairs1 = pairs1, pairs0
    flag = False
    for i,p in enumerate(pairs0):
      if i==0:
        continue
      x0, x1 = p[1], pairs1[i][1]
      if x0!=x1:
        flag = True
        break
    if flag:
      print(n - maxlen0 - max(x0, x1))
    else:
      print(n - maxlen0 - pairs1[1][1])

Solution (Python):
import collections
n=int(input())
v=list(map(int,input().split()))
v1=[]
v2=[]
c=0
for i in range(len(v)):
    if c==0:
        v1.append(v[i])
        c=1
    else:
        v2.append(v[i])
        c=0
m1=collections.Counter(v1)
w1=m1.most_common()
m2=collections.Counter(v2)
w2=m2.most_common()
if w1[0][0]==w2[0][0]:
    if w1[0][1]>w2[0][1]:
        print(n-w1[0][1]-w2[1][1])
    elif w1[0][1]<w2[0][1]:
        print(n-w1[1][1]-w2[0][1])
    elif len(w1)>1:
        if w1[1][1]>=w2[1][1]:
            print(n-w1[1][1]-w2[0][1])
        else:
            print(n-w1[0][1]-w2[1][1])
    else:
        print(n//2)
else:
    print(n-w1[0][1]-w2[0][1])

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

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

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

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

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


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

    from collections import Counter
    ve = Counter(v_idx_even)
    vo = Counter(v_idx_odd)

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

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

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

    return ans


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
a=[];b=[]
for i in range(len(v)):
  if i%2==0:a.append(v[i])
  else:b.append(v[i])
A=Counter(a);B=Counter(b)
c=A.most_common()[0][0];d=B.most_common()[0][0]
if len(set(a))!=1 and len(set(b))!=1:
  if c==d:
    e=A.most_common()[1][1];f=B.most_common()[1][1]
    if e<=f:
      d=B.most_common()[1][0]
    else:
      c=A.most_common()[1][0]
  x=len(a)-a.count(c)
  y=len(b)-b.count(d)
  print(x+y)
elif len(set(a))==1 and len(set(b))==1:
  if a[0]!=b[0]:print(0)
  else:print(len(a))
elif len(set(a))==1:
  if c==d:
    d=B.most_common()[1][0]
  x=len(a)-a.count(c)
  y=len(b)-b.count(d)
  print(x+y)
else:
  if c==d:
    c=A.most_common()[1][0]
  x=len(a)-a.count(c)
  y=len(b)-b.count(d)
  print(x+y)

Solution (Python):
from collections import Counter
n=input()
lists=input().split()
hi=[]
low=[]
c=True
for i in range(len(lists)):
    if(i==0):
        same_c=lists[i]
    if(same_c==lists[i] and c):
        pass
    else:
        c=False

    if(i%2==0):
        hi.append(lists[i])
    else:
        low.append(lists[i])
if(c):
    print(len(hi))
    exit(0)
hi_counter=Counter(hi)
low_counter=Counter(low)
while(True):
    if(hi_counter.most_common()[0][0]!=low_counter.most_common()[0][0]):
        print(len(hi)-hi_counter.most_common()[0][1]+len(low)-low_counter.most_common()[0][1])
        exit(0)
    else:
        if(hi_counter.most_common()[0][1]-hi_counter.most_common()[1][1]>low_counter.most_common()[0][1]-low_counter.most_common()[1][1]):
            print(len(hi)-hi_counter.most_common()[0][1]+len(low)-low_counter.most_common()[1][1])
            exit(0)
        else:
            print(len(hi)-hi_counter.most_common()[1][1]+len(low)-low_counter.most_common()[0][1])
            exit(0)

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



v = np.array(v)

if len(np.unique(v)) == 1:
    print(int(len(v)/2))
else:
    vodd = v[np.arange(0,len(v),2)]
    odd_count = Counter(vodd)

    veven = v[np.arange(1,len(v),2)]
    even_count = Counter(veven)
    

    d_odd = []
    odd_lis = list(odd_count.keys())
    for key in odd_count.keys():
        d_odd.append(odd_count[key])

    d_even = []
    even_lis = list(even_count.keys())
    for key in even_count.keys():
        d_even.append(even_count[key])

    
    if even_lis[np.argmax(d_even)] != odd_lis[np.argmax(d_odd)]:
        score = np.max(d_even) + np.max(d_odd)
    else:

        score1 = d_even[np.argsort(d_even)[-1]] + d_odd[np.argsort(d_odd)[-2]]
        score2 = d_even[np.argsort(d_even)[-2]] + d_odd[np.argsort(d_odd)[-1]]
        score = max(score1,score2)
    print(len(v) - score)

Solution (Python):
n = int(input())
lst = [int(x) for x in input().split()]
d1 = {None : -1}
d2 = {None : -1}
for i in range(n // 2):
    if lst[2 * i] in d1:
        d1[lst[2 * i]] += 1
    else:
        d1[lst[2 * i]] = 0 
        
    if lst[2 * i + 1] in d2:
        d2[lst[2 * i + 1]] += 1
    else:
        d2[lst[2 * i + 1]] = 0
        

u1 = sorted(d1.items(), key = lambda x : x[1], reverse = True)
u2 = sorted(d2.items(), key = lambda x : x[1], reverse = True)

MAKE = lambda x : x[1] + 1

if u1[0][0] != u2[0][0]:
    a = MAKE(u1[0]) + MAKE(u2[0])
    print(n - a)
else:
    a1 = MAKE(u1[0]) + MAKE(u2[1])
    a2 = MAKE(u1[1]) + MAKE(u2[0])
    a = max(a1, a2)
    print(n - a)

Solution (Python):
n = int(input())
v = [int(x) for x in input().split()]
odd = {}
even = {}
for i in range(n):
	x = v[i]
	if i&1==1:
		if x in odd:
			odd[x]+= 1
		else:
			odd[x] = 1
	else:
		if x in even:
			even[x]+= 1
		else:
			even[x] = 1
			
oddl = []
for p, q in odd.items():
	oddl.append((p, q))
evenl = []
for p, q in even.items():
	evenl.append((p, q))
	
oddl = sorted(oddl, key=lambda x: x[1], reverse=True)
evenl = sorted(evenl, key=lambda x: x[1], reverse=True)

oddn = (n+1)>>1
evenn = n-oddn
result = []
if oddl[0][0] == evenl[0][0]:
	if len(oddl) > 1:
		result.append((oddn-oddl[1][1])+(evenn-evenl[0][1]))
	if len(evenl) > 1:
		result.append((oddn-oddl[0][1])+(evenn-evenl[1][1]))
	if len(oddl) == len(evenl) == 1:
		result.append(evenn)
else:
	result.append((oddn-oddl[0][1])+(evenn-evenl[0][1]))
print(min(result))

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

v1 = {}; v2 = {}

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

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

max_v1 = max(v1.items(), key=lambda x: x[1])
max_v2 = max(v2.items(), key=lambda x: x[1])

ans = 0
if max_v1[0] != max_v2[0]:
    ans = n - max_v1[1] - max_v2[1]
elif len(v1) == len(v2) == 1:
    ans = int(n/2)
elif len(v1) == 1:
    max_v2_ = max(v2.items(), key=lambda x: x[1])
    ans = n - max_v1[1] - max_v2_[1]
elif len(v2) == 1:
    max_v1_ = max(v1.items(), key=lambda x: x[1])
    ans = n - max_v1_[1] - max_v2[1]
else:
    v1.pop(max_v1[0])
    v2.pop(max_v2[0])
    max_v1_ = max(v1.items(), key=lambda x: x[1])
    max_v2_ = max(v2.items(), key=lambda x: x[1])
    
    if max_v1_[1] >= max_v2_[1]:
        ans = n - max_v1_[1] - max_v2[1]
    else:
        ans = n - max_v1[1] - max_v2_[1]

print(ans)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
vv = inpl()

cnt1 = defaultdict(int)
cnt2 = defaultdict(int)
ed1 = []
ed2 = []

for i in range(N):
    v = vv[i]
    if i%2 == 0:
        if cnt1[v] == 0:
            ed1.append(v)
        cnt1[v] += 1
    else:
        if cnt2[v] == 0:
            ed2.append(v)
        cnt2[v] += 1

n1 = n2 = 0
cnts1 = []
cnts2 = []
for e in ed1:
    cnts1.append([cnt1[e],e])
for e in ed2:
    cnts2.append([cnt2[e],e])

cnts1.sort(reverse=True)
cnts2.sort(reverse=True)
cnts1.append([0,0])
cnts2.append([0,0])

if cnts1[0][1] != cnts2[0][1]:
    print(N-cnts1[0][0]-cnts2[0][0])
else:
    ans1 = cnts1[1][0] + cnts2[0][0]
    ans2 = cnts1[0][0] + cnts2[1][0]
    print(N-max(ans1,ans2))

Solution (Python):
a = input()
dict1 = dict()
dict2 = dict()
counter = 0
b = input().split()
for i in b:
	if counter % 2 == 0:
		if i not in dict1:
			dict1[i] = 1
		else:
			dict1[i] += 1
	elif counter % 2 == 1:
		if i not in dict2:
			dict2[i] = 1
		else:
			dict2[i] += 1
			
	counter += 1

dict1list = []
for i in dict1.keys():
	dict1list.append([i, dict1[i]])

dict2list = []
for i in dict2.keys():
	dict2list.append([i, dict2[i]])

dict1list.sort(key = lambda x: x[1])
dict2list.sort(key = lambda x: x[1])
if dict1list[-1][0] == dict2list[-1][0] and len(dict2list) > 1 and dict1list[-1][1]  > dict2list[-1][1]:
	print(len(b) - dict1list[-1][1] - dict2list[-2][1])
elif dict1list[-1][0] == dict2list[-1][0] and len(dict2list) == 1 and dict1list[-1][1]  > dict2list[-1][1]:
	print(len(b) - dict1list[-1][1])
elif dict1list[-1][0] == dict2list[-1][0] and len(dict1list) > 1 and dict1list[-1][1]  < dict2list[-1][1]:
	print(len(b) - dict1list[-2][1] - dict2list[-1][1])
elif dict1list[-1][0] == dict2list[-1][0] and len(dict1list) == 1 and dict1list[-1][1]  < dict2list[-1][1]:
	print(len(b) - dict2list[-1][1])
elif dict1list[-1][0] == dict2list[-1][0] and dict1list[-1][1]  == dict2list[-1][1]:
	if len(dict1list) == 1 and len(dict2list) == 1:
		print(len(b) - dict2list[-1][1])
	elif len(dict1list) == 1 and len(dict2list) > 1:
		print(len(b) - dict2list[-2][1] - dict1list[-1][1])
	elif len(dict1list) > 1 and len(dict2list) == 1:
		print(len(b) - dict2list[-1][1] - dict1list[-2][1])
	else:
		if (dict2list[-2][-1] >= dict1list[-2][-1]):
			print(len(b) - dict2list[-2][1] - dict1list[-1][1])
		elif (dict2list[-2][-1] < dict1list[-2][-1]):
			print(len(b) - dict2list[-1][1] - dict1list[-2][1])
else:
	print(len(b) - dict1list[-1][1] - dict2list[-1][1])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
a1 = A[::2]
a2 = A[1::2]

count1 = dict()
count2 = dict()

for a in a1:
    if a in count1.keys():
        count1[a] += 1
    else:
        count1[a] = 1

for a in a2:
    if a in count2.keys():
        count2[a] += 1
    else:
        count2[a] = 1

kf = lambda x: -x[1]

A1 = sorted(count1.items(), key=kf)
A2 = sorted(count2.items(), key=kf)

if A1[0][0] == A2[0][0]:
    if len(A1) == 1:
        if len(A2) == 1:
            keep = A1[0][1]
        else:
            keep = A1[0][1] + A2[1][1]
    else:
        keep = max([A1[1][1], A2[1][1]]) + A1[0][1]
else:
    keep = A1[0][1] + A2[0][1]

print(N - keep)

Solution (Python):
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])

sv1 = set(v1)
sv2 = set(v2)
if len(sv1) == 1 and len(sv2) == 1 :
    if sv1 != sv2:
        print(0)
    else:
        print(n//2)
else:
    dic1 = { i : 0 for i in sv1}
    dic2 = { i : 0 for i in sv2}
    for i in v1:
        dic1[i] = dic1[i] + 1
    for i in v2:
        dic2[i] = dic2[i] + 1
    
    dic1 = sorted(dic1.items(), key=lambda x: -x[1])
    dic2 = sorted(dic2.items(), key=lambda x: -x[1])
    if dic1[0][0] != dic2[0][0]:
        print(n-(dic1[0][1]+dic2[0][1]))
    else:
        if len(dic1)==1:
            print(n- (dic1[0][1]+dic2[1][1]))
        elif len(dic2)==1:
            print(n- (dic1[1][1]+dic2[0][1]))
        elif dic1[1][1]+dic2[0][1] >= dic1[0][1]+dic2[1][1] :
            print(n- (dic1[1][1]+dic2[0][1]))
        else :
            print(n- (dic1[0][1]+dic2[1][1]))

Solution (Python):
from collections import Counter
from operator import itemgetter

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

c0 = Counter(v)
if len(c0.values()) == 1:
    ans = n // 2
else:
    c1 = Counter(v[::2])
    c2 = Counter(v[1::2])

    x1 = sorted(c1.items(), reverse=True, key=itemgetter(1))
    x2 = sorted(c2.items(), reverse=True, key=itemgetter(1))

    ans = n
    if x1[0][0] == x2[0][0]:
        if len(x1) == 1:
            ans -= x2[0][1]
        elif len(x2) == 1:
            ans -= x1[0][1]
        else:
            if x1[0][1] + x2[1][1] < x2[0][1] + x1[1][1]:
                ans -= x2[0][1]
                ans -= x1[1][1]
            else:
                ans -= x1[0][1]
                ans -= x2[1][1]
    else:
        ans -= x1[0][1]
        ans -= x2[0][1]
print(ans)

Solution (Python):
from collections import defaultdict

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

def count(vs):
    d1 = defaultdict(int)
    d2 = defaultdict(int)
    for i, v in enumerate(vs):
        if i % 2 == 0:
            d1[v] += 1
        else:
            d2[v] += 1
    return d1, d2

d1, d2 = count(vs)
d1 = sorted([(v, k) for k, v in d1.items()], reverse=True)
d2 = sorted([(v, k) for k, v in d2.items()], reverse=True)
n1, v1 = d1[0]
n2, v2 = d2[0]
if v1 == v2:
    n1_2 = 0 if len(d1) == 1 else d1[1][0]
    n2_2 = 0 if len(d2) == 1 else d2[1][0]
    total = max(n1 + n2_2, n2 + n1_2)
else:
    total = n1 + n2

print(n - total)

Solution (Python):
from collections import defaultdict
import sys
n=int(input().strip())
v=list(map(int, input().strip().split()))
counterO=defaultdict(int)
counterE=defaultdict(int)
for i in v[::2]:
    counterO[i]+=1
for i in v[1::2]:
    counterE[i]+=1
cOO=sorted(counterO.items(),key=lambda x:x[1],reverse=True)
cEE=sorted(counterE.items(),key=lambda x:x[1],reverse=True)
iO,iE=0,0
if cOO[iO][0]!=cEE[iE][0]:
    ans=sum(x[1] for x in cOO[:iO]+cOO[iO+1:])+sum(x[1] for x in cEE[:iE]+cEE[iE+1:])
else:
    iO2=iO+1
    iE2=iE+1
    ans1=sum(x[1] for x in cOO[:iO2]+cOO[iO2+1:])+sum(x[1] for x in cEE[:iE]+cEE[iE+1:])
    ans2=sum(x[1] for x in cOO[:iO]+cOO[iO+1:])+sum(x[1] for x in cEE[:iE2]+cEE[iE2+1:])
    ans=min(ans1,ans2)
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
e = [0] * (n // 2)
o = [0] * (n // 2)
for i in range(n):
    if i % 2 == 0:
        e[i // 2] = v[i]
    else:
        o[(i-1) // 2] = v[i]
ce = Counter(e)
co = Counter(o)

if ce.most_common()[0][0] == co.most_common()[0][0]:
    if len(ce) == 1 and len(co) == 1:
        print(n // 2)
    else:
        print(n-max(ce.most_common()[0][1]+co.most_common()[1][1], ce.most_common()[1][1]+co.most_common()[0][1]))
else:
    print(n-ce.most_common()[0][1]-co.most_common()[0][1])

Solution (Python):
import collections

n = int(input())
array = list(map(int,input().split(" ")))

array1 = []
array2 = []

for i in range(int(n/2)):
    array1.append(array[i*2])
    array2.append(array[i*2+1])

a1 = collections.Counter(array1)
a2 = collections.Counter(array2)

a12 = sorted(a1.items(),key = lambda x: -x[1])
a22 = sorted(a2.items(),key = lambda x: -x[1])

if a12[0][0] != a22[0][0]:
    print(n- a12[0][1] - a22[0][1])
else:
    if len(a12) == 1:
        if len(a22) == 1:
            print(int(n/2))
        else:
            print(a22[0][1])
    elif len(a22) == 1:
        print(a12[0][1])
    else:
        print(n - max(a12[0][1] + a22[1][1],a12[1][1] + a22[0][1]))

Solution (Python):
n = int(input())
v = input().split()
for i in range(len(v)):
    v[i] = int(v[i])
nums = [[],[]]
fr = [[],[]]
for i in range(len(v)):
    idx = (i+1)%2
    if v[i] in nums[idx]:
        fr_idx = nums[idx].index(v[i])
        fr[idx][fr_idx] += 1
    else:
        nums[idx].append(v[i])
        fr[idx].append(1)
        


fr_sort = [[0,0,0,0]+sorted(fr[0]),[0,0,0,0]+sorted(fr[1])]
maxfr = [fr_sort[0][-1],fr_sort[1][-1],fr_sort[0][-2],fr_sort[1][-2]]
maxnum = [[],[],[],[]]

for i in [0,1,2,3]:
    for j in range(len(nums[i%2])):
        if fr[i%2][j] == maxfr[i]:
            maxnum[i].append(nums[i%2][j])
                   
if maxnum[0] == maxnum[1]:
    m = max([maxfr[0]+maxfr[3],maxfr[1]+maxfr[2]])
else:
    m = maxfr[0] + maxfr[1]
                   
print(n-m)

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int, input().split()))
b=[a[i] for i in range(n) if i%2==0]
c=[a[i] for i in range(n) if i%2==1]
b2=Counter(b)
c2=Counter(c)
b3=b2.most_common(3)
c3=c2.most_common(3)
ans=n
for i in b3:
    for j in c3:
        if i[0]!=j[0]:
            ans=min(ans,n-i[1]-j[1])
        else:
            ans=min(ans,n-max(i[1],j[1]))
print(ans)

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

d = [{}, {}]
for i in range(n):
    if vvv[i] not in d[i%2].keys():
        d[i%2][vvv[i]]=1
    else:
        d[i%2][vvv[i]]+=1

li1 = [(v,k) for (k,v) in d[0].items()]
li2 = [(v,k) for (k,v) in d[1].items()]

if max(li1)[1] != max(li2)[1]:
    print(n - (max(d[0].values()) + max(d[1].values())))
else:
    v0 = d[0].pop(max(li1)[1])
    v1 = d[1].pop(max(li2)[1])
    
    if len(d[0])==0:
        dtmp0 = 0
    else:
        dtmp0 = max(d[0].values())
        
    if len(d[1])==0:
        dtmp1 = 0
    else:
        dtmp1 = max(d[1].values())
    print(n - max(v0 +dtmp1, dtmp0+v1))

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])
    
c1 = collections.Counter(v1)
c2 = collections.Counter(v2)

a1 = c1.most_common()
a2 = c2.most_common()

if len(a1)==1:
  k1=0
else:
  k1=a1[1][1]
if len(a2)==1:
  k2=0
else:
  k2=a2[1][1]

if a1[0][0] != a2[0][0]:
  print(len(V)-a1[0][1]-a2[0][1])
elif a1[0][1]+k2 > k1+a2[0][1]:
  print(len(V)-a1[0][1]-k2) 
else:
  print(len(V)-k1-a2[0][1])

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

l=[int(i) for i in input().split()]
e,o={0:0},{0:0}
for a,i in enumerate(l):
    if a%2:
        if i in o: o[i]+=1
        else: o[i]=1
    else:
        if i in e: e[i]+=1
        else: e[i]=1
chko,chke=[0,0,0,0],[0,0,0,0]
for i in e:
    if e[i]>=chke[1]:
        chke[3]=chke[1]
        chke[2]=chke[0]
        chke[1]=e[i]
        chke[0]=i
    elif e[i]>=chke[3]:
        chke[3]=e[i]
        chke[2]=i
for i in o:
    if o[i]>=chko[1]:
        chko[3]=chko[1]
        chko[2]=chko[0]
        chko[1]=o[i]
        chko[0]=i
    elif o[i]>=chko[3]:
        chko[3]=o[i]
        chko[2]=i


if chko[0]!=chke[0]:
    print((n//2-chko[1])+(n//2-chke[1]))
else:
    ans=min((n//2-chko[1])+(n//2-chke[3]),(n//2-chko[3])+(n//2-chke[1]))
    print(ans)

Solution (Python):
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    N = int(input_raw[0])
    input_raw = read_func().strip().split()
    A_dic = {}
    B_dic = {}
    for i in range(0, N):
        if i % 2 == 0:
            if input_raw[i] in A_dic:
                A_dic[input_raw[i]] += 1
            else:
                A_dic[input_raw[i]] = 1
        else:
            if input_raw[i] in B_dic:
                B_dic[input_raw[i]] += 1
            else:
                B_dic[input_raw[i]] = 1

    max_A_num = 0
    max_B_num = 0
    max_A = 0
    max_B = 0
    for A in A_dic:
        if max_A_num < A_dic[A]:
            max_A_num = A_dic[A]
            max_A = A
    for B in B_dic:
        if max_B_num < B_dic[B]:
            max_B_num = B_dic[B]
            max_B = B

    max_A_num2 = 0
    max_B_num2 = 0
    if max_A == max_B:

            for A in A_dic:
                if A != max_A:
                    max_A_num2 = max(max_A_num2, A_dic[A])

            for B in B_dic:
                if B != max_B:
                    max_B_num2 = max(max_B_num2, B_dic[B])

            if max_A_num2 > max_B_num2:
                max_A_num = max_A_num2
            else:
                max_B_num = max_B_num2

    print N - max_A_num - max_B_num




if __name__ == '__main__':
    main()

Solution (Python):
import collections

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

vo=[]
ve=[]
i = 0
while i < n/2:
  ve.append(v[2*i])
  vo.append(v[2*i+1])
  i += 1
cve = collections.Counter(ve).most_common(2)
cvo = collections.Counter(vo).most_common(2)
ans = 0
if cve[0][0] == cvo[0][0]:
  if len(cve) == 1 and len(cvo) == 1:
    print(int(n/2))
  elif len(cve) == 1:
    print(int(n/2 - cvo[1][1]))
  elif len(cvo) == 1:
    print(int(n/2 - cve[1][1]))
  else:
    print(min(n-cvo[0][1]-cve[1][1], n-cvo[1][1]-cve[0][1]))
else:
  print(n - cve[0][1] - cvo[0][1])

Solution (Python):


import numpy as np


INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
V = inpl()

A = [0 for _ in range(10**5+1)]
for i in range(0, N, 2):
    A[V[i]] += 1

B = [0 for _ in range(10**5+1)]
for i in range(1, N, 2):
    B[V[i]] += 1

A = np.array(A)
B = np.array(B)

if A.argmax() == B.argmax():
    A.sort()
    B.sort()
    tmp = max(A[-1] + B[-2] , A[-2] + B[-1])
    ans = N - tmp
else:
    A.sort()
    B.sort()
    ans = N - A[-1] - B[-1]

print(ans)

Solution (Python):
from operator import itemgetter
N = int(input())
A = list(map(int, input().split()))

O = {}
E = {}

for i in range(N//2):
  if A[2*i] in O:
    O[A[2*i]] += 1
  else:
    O[A[2*i]] = 1
  if A[2*i+1] in E:
    E[A[2*i+1]] += 1
  else:
    E[A[2*i+1]] = 1

O = sorted(O.items(), key=itemgetter(1), reverse=True)      
E = sorted(E.items(), key=itemgetter(1), reverse=True)   

if O[0][0] != E[0][0]:
  print(N - O[0][1] - E[0][1])
else:
  print(min(N - O[0][1] - (E[1][1] if len(E) > 1 else 0), N - E[0][1] - (O[1][1] if len(O) > 1 else 0)))

Solution (Python):
n = int(input())
odd = [[i, 0] for i in range(100000)]
even = [[i, 0] for i in range(100000)]
arr = list(map(int, input().split()))
odd_e = True
even_e = True
for i, e in enumerate(arr):
    if i % 2 == 0:
        odd[e - 1][1] += 1
        if odd_e and arr[0] != e:
            odd_e = False
    else:
        even[e - 1][1] += 1
        if even_e and arr[1] != e:
            even_e = False
odd.sort(key=lambda z: z[1])
even.sort(key=lambda z: z[1])
if odd[-1][0] == even[-1][0]:
    if odd_e or even_e:
        ans = n - even[-1][1]
    elif odd[-2][1] > even[-2][1]:
        ans = n - even[-1][1] - odd[-2][1]
    else:
        ans = n - even[-2][1] - odd[-1][1]
else:
    ans = n - odd[-1][1] - even[-1][1]
print(ans)

Solution (Python):
n = int(input())
v = list(map(int,input().split()))
O = [0 for k in range(max(v)+1)]
E = [0 for k in range(max(v)+1)]

for k in range(n):
    if k%2 == 0:
        E[v[k]] += 1
    else:
        O[v[k]] += 1
if E.index(max(E)) != O.index(max(O)):
    print(n-max(E)-max(O))
else:
    E = sorted(E)
    O = sorted(O)
    print(min((n-max(E)-O[-2]),(n-max(O)-E[-2])))

Solution (Python):

from collections import defaultdict
from operator import itemgetter
def solve():
    n = int(input())
    V = list(map(int, input().split()))
    l = defaultdict(int)
    u = defaultdict(int)
    for i in range(0,n,2):
        l[V[i]] += 1
        u[V[i+1]] += 1

    l = sorted(list(l.items()),key=itemgetter(1))[::-1]
    u = sorted(list(u.items()),key=itemgetter(1))[::-1]
    if len(l) == len(u) == 1:
        if l[0][0] != u[0][0]:
            res = 0
        else:
            res = min(l[0][1], u[0][1])
    else:
        if l[0][0] != u[0][0]:
            res = sum(map(itemgetter(1), l[1:])) + sum(map(itemgetter(1), u[1:]))
        elif len(u) == 1 or (len(l) > 1 and l[1][1]+u[0][1] > l[0][1]+u[1][1]):
            res = l[0][1] + sum(map(itemgetter(1), l[2:])) + sum(map(itemgetter(1), u[1:]))
        else:
            res = u[0][1] + sum(map(itemgetter(1), l[1:])) + sum(map(itemgetter(1), u[2:]))

    return str(res)

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

Solution (Python):
import collections
n = int(input())
v = input().split(" ")
"""
n = 10000

v = [_i for _i in range(n)]
n = 10
v = [1, 1, 1, 1, 1, 1, 1, 1, 1, 2]
"""
if len(set(v)) == 1:
    print(n // 2)
else:
    odds = v[1::2]
    _o = collections.Counter(odds)
    r_o = {str(v): k for k, v in _o.items()}
    evens = v[::2]
    _e = collections.Counter(evens)
    r_e = {str(v): k for k, v in _e.items()}
    ans1 = 0
    tmp = max(_o.values())
    ans1 += len(odds) - tmp
    key = r_o[str(tmp)]
    if key in _e.keys():
        _e[key] = 0
    ans1 += len(evens) - max(_e.values())

    ans2 = 0
    _o = collections.Counter(odds)
    r_o = {str(v): k for k, v in _o.items()}
    _e = collections.Counter(evens)
    r_e = {str(v): k for k, v in _e.items()}
    tmp = max(_e.values())
    ans2 += len(evens) - tmp
    key = r_e[str(tmp)]
    if key in _o.keys():
        _o[key] = 0
    ans2 += len(evens) - max(_o.values())

    print(min(ans1, ans2))

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

import collections

v_odd = v_list[::2]
v_even = v_list[1::2]

count_odd = collections.Counter(v_odd).most_common(2)
count_even = collections.Counter(v_even).most_common(2)

if count_odd[0][0] != count_even[0][0]:
    ans = len(v_list) - (count_odd[0][1] + count_even[0][1])
elif len(count_odd) == 1 and len(count_even) == 1:
    ans = int(len(v_list) / 2)
elif len(count_odd) == 1 or count_odd[0][1] + count_even[1][1] > count_odd[1][1] + count_even[0][1]:
    ans = len(v_list) - (count_odd[0][1] + count_even[1][1])
else:
    ans = len(v_list) - (count_odd[1][1] + count_even[0][1])

print(ans)

Solution (Python):


n=int(input())
v=[int(x) for x in input().split()]
if len(set(v))==1:
    print(n//2)
    import sys
    sys.exit()
from collections import Counter
v1=[]
v2=[]
for i in range(n):
    if i%2==0:
        v1.append(v[i])
    else:
        v2.append(v[i])
v1=Counter(v1)
v2=Counter(v2)
ans=10**10

for i1 in v1.most_common(min(len(v1),10)):
    for i2 in v2.most_common(min(len(v1),10)):
        
        if i1==i2:
            continue
        ans=min(n-i1[1]-i2[1],ans)
print(ans)