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 /\/\/\/.



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


def main():
    N = I()
    v = LI()
    first_counter = {}
    second_counter = {}

    for i in range(N):
        if i % 2 == 0:
            if v[i] not in first_counter:
                first_counter[v[i]] = 0
            first_counter[v[i]] += 1
        else:
            if v[i] not in second_counter:
                second_counter[v[i]] = 0
            second_counter[v[i]] += 1

    first_items = sorted([(v, k) for k, v in first_counter.items()], reverse=True)
    second_items = sorted([(v, k)
                           for k, v in second_counter.items()], reverse=True)

    # print(first_items, second_items)
    first_counter, first_value = first_items.pop(0)
    second_counter, second_value = second_items.pop(0)

    first_total_count = (N + (2 - 1)) // 2
    second_total_count = N // 2

    if first_value != second_value:
        print(first_total_count - first_counter + second_total_count - second_counter)
    else:
        first_all_replace_count = first_total_count + second_total_count - second_counter
        second_all_replace_count = second_total_count + first_total_count - first_counter
        first_all_next_replace_count = 10 ** 9
        second_all_next_replace_count = 10 ** 9

        if len(first_items) > 0:
            next_first_counter, next_first_value = first_items.pop(0)
            first_all_next_replace_count = first_total_count - next_first_counter + \
                second_total_count - second_counter

        if len(second_items) > 0:
            next_second_counter, next_second_value = second_items.pop(0)
            second_all_next_replace_count = second_total_count - \
                next_second_counter + first_total_count - first_counter

        print(min(first_all_replace_count,
                  second_all_replace_count,
                  first_all_next_replace_count,
                  second_all_next_replace_count))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
from operator import itemgetter

n = int(input())
v = [int(i) for i in input().split()]
a = sorted(Counter(v[::2]).items(), key=itemgetter(1))
b = sorted(Counter(v[1::2]).items(), key=itemgetter(1))
ka, va = a[-1]
kb, vb = b[-1]
if ka != kb:
    print(n - va - vb)
else:
    sa = a[-2][1] if len(a) > 1 else va
    sb = b[-2][1] if len(b) > 1 else vb
    if len(a) == len(b) == 1:
        sa, sb = 0, 0
    print(n - max(sa + vb, va + sb))

Submission status: Accepted

Solution code:
N = int(input())
listv = list(map(int, input().split()))
even = [listv[x] for x in range(N) if x%2 == 0]
odd = [listv[x] for x in range(N) if x%2 == 1]
import collections
evenc = collections.Counter(even)
oddc = collections.Counter(odd)
listeven = evenc.most_common()
listodd = oddc.most_common()
ae, be = listeven[0]
ao, bo = listodd[0]
if ae != ao:
    ans = N-be-bo
elif len(listeven) ==1 and len(listodd) ==1:
    ans = N/2    
elif len(listeven) == 1:
    ao1, bo1 = listodd[1]
    ans = N/2-bo1
elif len(listodd) == 1:
    ae1, be1 = listeven[1]
    ans = N/2-bo1    
else:
    ao1, bo1 = listodd[1]
    ae1, be1 = listeven[1] 
    ans = N-bo-max(bo1,be1)
print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())

v = list(map(int, input().split( )))
##
v1 = v[0::2]
v2 = v[1::2]
##

##
from  collections import Counter

n1 = len(v1)
n2 = len(v2)
v11 = Counter(v1)
v21 = Counter(v2)

##
#c1 = Counter.most_common(v11)
#c2 = Counter.most_common(v21)
c1 = v11.most_common(2)
c2 = v21.most_common(2)

#print(c2)
#print(v21)
#print(v11[c1])　エラー

###
###
if c1[0][0]!=c2[0][0]:
    print(n1-c1[0][1]+n2-c2[0][1])
else:
    try:
        ans1 = n1-c1[1][1]+n2-c2[0][1]
        ans2 = n1-c1[0][1]+n2-c2[1][1]
        print(min(ans1,ans2))
    except:
        try:
            ans1 = n1-c1[1][1]+n2-c2[0][1]
            #ans2 = n1-c1[0][1]+n2-c2[1][1]
            print(ans1)
        except:
            try:
                ans2 = n1-c1[0][1]+n2-c2[1][1]
                print(ans2)
            except:
                print(len(v2))

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	n = int(input())
	al = list(IN())
	odd_dd=defaultdict(lambda : 0)
	odd_dd[-1]=0
	even_dd=defaultdict(lambda :0)
	even_dd[-1]=0
	
	for i, v in enumerate(al):
		if i%2==0:
			odd_dd[v] += 1
		else:
			even_dd[v] += 1
	
	odd_ll=[(odd_dd[key], key) for key in odd_dd.keys()]
	even_ll=[(even_dd[key], key) for key in even_dd.keys()]
	
	odd_ll.sort(reverse=True)
	even_ll.sort(reverse=True)
	kk=n//2
	pa(odd_ll)
	pa(even_ll)
	
	#先頭が同じ
	if odd_ll[0][1] == even_ll[0][1]:
		ra=(kk-odd_ll[0][0])+(kk-even_ll[1][0])
		rb=(kk-odd_ll[1][0])+(kk-even_ll[0][0])
		return min(ra, rb)
	else:
		ret= (kk-odd_ll[0][0])+(kk-even_ll[0][0])
		return ret
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
u = [int(i) for i in input().split()]
e = Counter(u[0::2]).most_common() + [(0, 0)]
o = Counter(u[1::2]).most_common() + [(0, 0)]

if e[0][0] == o[0][0]:
    print(n - max(e[1][1] + o[0][1], e[0][1] + o[1][1]))
else:
    print(n - e[0][1] - o[0][1])

Submission status: Accepted

Solution code:
from collections import Counter
 
n = int(input())
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()

v_odd_common.append((0,0))
v_even_common.append((0,0))

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

dda= defaultdict(int)
ddb= defaultdict(int)


for i in range(N):
    if i%2==0:
        dda[v[i]]+=1
    else:
        ddb[v[i]]+=1

La=[]
Lb=[]

for k,v in dda.items():
    La.append((v,k))
    
for k,v in ddb.items():
    Lb.append((v,k))
        
La.sort()
Lb.sort()

ma=La[-1][0]
mb=Lb[-1][0]
ans=ma+mb

if La[-1][1]==Lb[-1][1]:
    if len(La)!=1:
        m2a=La[-2][0]
    else:
        m2a=0
    if len(Lb)!=1:
        m2b=Lb[-2][0]
    else:
        m2b=0
    ans=ma+max(m2a,m2b)
    
print(N-ans)

Submission status: Accepted

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

even_v=[]
odd_v=[]
for i in range(N):
    if i%2==0:
        even_v.append(v[i])
    else:
        odd_v.append(v[i])

import collections
even_c = collections.Counter(even_v)
odd_c = collections.Counter(odd_v)

even_num = even_c.most_common()[0][0]
odd_num = odd_c.most_common()[0][0]
even_cnt = even_c.most_common()[0][1]
odd_cnt = odd_c.most_common()[0][1]

if even_num == odd_num:
    if len(odd_c.most_common())==1 and len(even_c.most_common())==1: # only one num
        odd_num=even_num+1
    elif len(odd_c.most_common())!=1 and len(even_c.most_common())==1: # change odd
        odd_num = odd_c.most_common()[1][0]
    elif len(odd_c.most_common())==1 and len(even_c.most_common())!=1: # change even
        even_num = even_c.most_common()[1][0]
    else:
        if odd_cnt==even_cnt:
            even_cnt2= even_c.most_common()[1][1]
            odd_cnt2 = odd_c.most_common()[1][1]
            if even_cnt2>odd_cnt2:
                even_num = even_c.most_common()[1][0]
            else:
                odd_num = odd_c.most_common()[1][0]
        elif odd_cnt>even_cnt:
            even_num = even_c.most_common()[1][0]
        else:
            odd_num = odd_c.most_common()[1][0]
ans=0

for i in range(N):
    if i%2==0:
        num=even_num
    else:
        num=odd_num
    if num!=v[i]:
        ans+=1

print(ans)

Submission status: Accepted

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

even=[(0,0)]+sorted(Counter(V[::2]).items(), key=lambda x:x[1])
odd=[(0,0)]+sorted(Counter(V[1::2]).items(), key=lambda x:x[1])

if even[-1][0]==odd[-1][0]:
    if even[-2][1]>odd[-2][1]:even=even[-2][0];odd=odd[-1][0]
    else:even=even[-1][0];odd=odd[-2][0]
else:even=even[-1][0];odd=odd[-1][0]

cnt=0
for i,j in enumerate(V):
    if i%2==0 and j!=even:cnt +=1
    elif i%2==1 and j!=odd:cnt +=1

print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
v = [int(e) for e in input().split(' ')]
a = Counter(v[0::2]).most_common()+[(0,0)]
b = Counter(v[1::2]).most_common()+[(0,0)]
if a[0][0] != b[0][0]:
    print(n-a[0][1]-b[0][1])
else:
    print(n-max(a[1][1]+b[0][1],a[0][1]+b[1][1]))

Submission status: Accepted

Solution code:
n=int(input())
v=list(map(int,input().split()))
from collections import defaultdict
dict_odd=defaultdict(lambda :0)
dict_even=defaultdict(lambda :0)
dict_even[0],dict_odd[0]=0,0
for i in range(0,n,2):
    dict_even[v[i]]+=1

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

even_val=list(dict_even.items())
odd_val=list(dict_odd.items())
even_val=sorted(even_val,reverse=True,key=lambda x: x[1])
odd_val=sorted(odd_val,reverse=True,key=lambda x: x[1])

if even_val[0][0]!=odd_val[0][0]:
    print(n-odd_val[0][1]-even_val[0][1])
else:
    ans1=n-odd_val[1][1]-even_val[0][1]
    ans2=n-odd_val[0][1]-even_val[1][1]
    print(min(ans1,ans2))

Submission status: Accepted

Solution code:
import itertools
from collections import Counter

N = int(input())
V = [int(x) for x in input().split()]
EV_cnt = Counter(V[::2])
OD_cnt = Counter(V[1::2])

EV_cnt[-1] = 0
OD_cnt[-2] = 0

EV = EV_cnt.most_common(2)
OD = OD_cnt.most_common(2)

ans = N
for (k1,v1), (k2,v2) in itertools.product(EV,OD):
    if k1 == k2:
        continue
    x = (N - v1 - v2)
    if ans > x:
        ans = x

print(ans)

Submission status: Accepted

Solution code:
import collections

N = int(input())
V = [int(x) for x in input().split()]

Va, Vb = [], []
for i in range(N):
    if i % 2 == 0:
        Va.append(V[i])
    else:
        Vb.append(V[i])

Va_most = collections.Counter(Va).most_common()
Vb_most = collections.Counter(Vb).most_common()

if N == collections.Counter(V).most_common()[0][1]:
    print(N//2)
    exit()

if Va_most[0][0] == Vb_most[0][0]:
    typea = 10 ** 10
    if len(Vb_most) >= 2:
        typea = (len(Va) - Va_most[0][1]) + (len(Vb) - Vb_most[1][1])
    typeb = 10 ** 10
    if len(Va_most) >= 2:
        typeb = (len(Va) - Va_most[1][1]) + (len(Vb) - Vb_most[0][1])
    print(min(typea, typeb))
    exit()

print((len(Va) - Va_most[0][1]) + (len(Vb) - Vb_most[0][1]))

Submission status: Accepted

Solution code:
import collections
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_count=collections.Counter(a)
b_count=collections.Counter(b)

if a_count.most_common()[0][0]==b_count.most_common()[0][0]:
    if a_count.most_common()[0][1]==n//2 :
        print(a_count.most_common()[0][1])
    else:
        print(min(n-a_count.most_common()[0][1]-a_count.most_common()[1][1],n-b_count.most_common()[0][1]-b_count.most_common()[1][1]))
else:
    ans=n-a_count.most_common()[0][1]-b_count.most_common()[0][1]
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
V = map(int, input().split())

import collections

E = []
O = []
for i, v in enumerate(V):
  if i % 2 == 0:
    E.append(v)
  else:
    O.append(v)

ec = collections.Counter(E)
oc = collections.Counter(O)
e_common = ec.most_common()
o_common = oc.most_common()

E1 = e_common[0][1]
E2 = 0
if len(e_common) > 1:
  E2 = e_common[1][1]

O1 = o_common[0][1]
O2 = 0
if len(o_common) > 1:
  O2 = o_common[1][1]

if e_common[0][0] == o_common[0][0]:
  A1 = N - E1 - O2
  A2 = N - O1 - E2
  print(min(A1, A2))
else:
  ans = N - E1 - O1
  print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
V = list(map(int,input().split(" ")))

V1 = V[::2]
V2 = V[1::2]
ans = 0
d1 = Counter(V1)
d2 = Counter(V2)
if len(d1) == 1 and V1 == V2:
    print(N//2)
    exit()
m1 = max(d1.items(), key = lambda x:x[1])
m2 = max(d2.items(), key = lambda x:x[1])
d1.pop(m1[0])
d2.pop(m2[0])
a = m1[1]
b = m2[1]
if m1[0] != m2[0]:
    if d1:
      ans += sum(d1.values())
    if d2:
      ans += sum(d2.values())
else:
    c = 0
    d = 0
    if d1:
	    c = max(d1.values())
    if d2:
	    d = max(d2.values())
    if c != 0:
        tmp = N-b-c
    if c == 0:
        tmp = N-b-a
    if d != 0:
        ttmp = N-a-d
    if d == 0:
        ttmp = N-a-b
    
    ans = min(tmp,ttmp)
print(ans)

Submission status: Accepted

Solution code:
x=int(input())
a=list(map(int,input().split()))
d=[0]*100001
d0=[0]*100001
p=0
q=0
m0=0
n0=0
m=n=0
for i in range(x):
    if i%2==0:
        d[a[i]]+=1
        if d[a[i]]>=p:
            p=max(p,d[a[i]])
            if a[i]!=m:
                m0=m
                m=a[i]
    else:
        d0[a[i]]+=1
        if d0[a[i]]>=q:
            q=max(q,d0[a[i]])
            if a[i]!=n:
                n0=n
                n=a[i]
if m==n:
    if d[m0]>d0[n0]:
        p=d[m0]
    else:
        q=d0[n0]
print(x-p-q)        

#print(m0,n0,d[m0],d0[n0])

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    v = input().split(" ")
    even = {}
    odd = {}
    for i in range(n):
        if i % 2 == 0:
            even.setdefault(v[i], 0)
            even[v[i]] += 1
        else:
            odd.setdefault(v[i], 0)
            odd[v[i]] += 1
    even = sorted(even.items(), key=lambda x: x[1], reverse=True)
    odd = sorted(odd.items(), key=lambda x: x[1], reverse=True)
    # print(even,odd)
    if even[0][0] == odd[0][0]:
        if len(even) > 1 and len(odd) > 1:
            print(n - int(even[0][1]) - max(even[1][1], odd[1][1]))
        elif len(even) > 1:
            print(n - odd[0][1] - even[1][1])
        elif len(odd) > 1:
            print(n - even[0][1] - odd[1][1])
        else:
            print(n // 2)
    else:
        print(n - int(even[0][1]) - int(odd[0][1]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

odd = [[0, i] for i in range(10**5 + 1)]
even = [[0, i] for i in range(10**5 + 1)]

for i, vi in enumerate(v, 1):
  if i % 2 == 0:
    even[vi][0] += 1
  
  else:
    odd[vi][0] += 1

odd.sort(reverse=True)
even.sort(reverse=True)

no1, o1 = odd[0]
no2, o2 = odd[1]
ne1, e1 = even[0]
ne2, e2 = even[1]


if e1 == o1:
  ans = min((n//2-ne1)+(n//2-no2), (n//2-ne2)+(n//2-no1))
else:
  ans = (n//2-ne1) + (n//2-no1)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

odClass = Counter(odd)
evClass = Counter(even)
mostOd = odClass.most_common()
mostEv = evClass.most_common()

numOd = mostOd[0]
numEv = mostEv[0]

if len(mostOd) == 1 and len(mostEv) == 1:
    if mostOd[0][0] == mostEv[0][0]:
        print(len(odd))
    else:
        print(0)
    exit()
elif len(mostOd) == 1 and len(mostEv) != 1:
    if mostOd[0][0] == mostEv[0][0]:
        numEv = mostEv[1]
elif len(mostOd) != 1 and len(mostEv) == 1:
    if mostOd[0][0] == mostEv[0][0]:
        numOd = mostOd[1]
elif len(mostOd) != 1 and len(mostEv) != 1:
    if mostOd[0][0] == mostEv[0][0]:
        if mostOd[0][1] == mostEv[0][1]:
            if mostOd[1][1] <= mostEv[1][1]:
                numEv = mostEv[1]
            else:
                numOd = mostOd[1]
        elif mostOd[0][1] < mostEv[0][1]:
            numOd = mostOd[1]
        else:
            numEv = mostEv[1]

print(len(odd) + len(even) - numOd[1] - numEv[1])
#print(len(odd) , len(even) , numOd[1] , numEv[1])

Submission status: Accepted

Solution code:
n = int(input())
v = input().split()

even_dict = {'dummy':0}
odd_dict = {'dummy':0}

for x in list(set(v)):
	even_dict[x] = 0
	odd_dict[x] = 0

for i in range(n):
	x = v[i]
	if(i % 2 == 0):
		odd_dict[x] += 1
	else:
		even_dict[x] += 1

even_sort = sorted(even_dict.items(), key=lambda x:x[1], reverse=True)
odd_sort = sorted(odd_dict.items(), key=lambda x:x[1], reverse=True)

if( even_sort[0][0] != odd_sort[0][0] ):
	ans =  n - even_sort[0][1] - odd_sort[0][1]
else:
	ans = min(n - even_sort[1][1] - odd_sort[0][1],
			 n - even_sort[0][1] - odd_sort[1][1])

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
data_list = input().split()
odd_list = [data_list[i] for i in range(0, n, 2)]
even_list = [data_list[i] for i in range(1, n, 2)]

def make_dict(list):
  appeared = dict()
  for i in list:
    if not i in appeared:
      appeared[i] = 1
    else:
      appeared[i] += 1
  return appeared

odd_dict = make_dict(odd_list)
even_dict = make_dict(even_list)
odd_max = max(odd_dict.items(), key=lambda x: x[1])
even_max = max(even_dict.items(), key=lambda x: x[1])

if odd_max[0] != even_max[0]:
  print(n - (odd_max[1] + even_max[1]))
else:
  del odd_dict[odd_max[0]]
  del even_dict[even_max[0]]
  if len(odd_dict) == 0 and len(even_dict) == 0:
    print(n//2)
  elif len(odd_dict) == 0:
    even_second_max = max(even_dict.items(), key=lambda x: x[1])
    print(n//2 - even_second_max[1])
  elif len(even_dict) == 0:
    odd_second_max = max(odd_dict.items(), key=lambda x: x[1])
    print(n//2 - odd_second_max[1])
  else:
    odd_second_max = max(odd_dict.items(), key=lambda x: x[1])
    even_second_max = max(even_dict.items(), key=lambda x: x[1])
    print(n - max((odd_max[1] + even_second_max[1]), (odd_second_max[1] + even_max[1])))

Submission status: Accepted

Solution code:
from collections import Counter

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

odd = Counter()
even = Counter()

for i, v in enumerate(V):
    cnt = even if i % 2 else odd
    cnt[v] += 1

oddCmn = odd.most_common(2)
evenCmn = even.most_common(2)

oddCmn.append((0, 0))
evenCmn.append((0, 0))

od = 0
ev = 0
if oddCmn[od][0] == evenCmn[ev][0]:
    if oddCmn[od][1] + evenCmn[ev + 1][1] < evenCmn[ev][1] + oddCmn[od + 1][1]:
        od += 1
    else:
        ev += 1


print(N - oddCmn[od][1] - evenCmn[ev][1])

Submission status: Accepted

Solution code:
from collections import Counter

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

odd = Counter()
even = Counter()

for i, v in enumerate(V):
    cnt = even if i % 2 else odd
    cnt[v] += 1

oddCmn = odd.most_common(2)
evenCmn = even.most_common(2)

oddCmn.append((0, 0))
evenCmn.append((0, 0))

od = 0
ev = 0
if oddCmn[od][0] == evenCmn[ev][0]:
    if oddCmn[od][1] + oddCmn[od + 1][1] < evenCmn[ev][1] + evenCmn[ev + 1][1]:
        ev += 1
    else:
        od += 1


print(N - oddCmn[od][1] - evenCmn[ev][1])

Submission status: Accepted

Solution code:
#111
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
L=Counter(v[0::2]).most_common()
R=Counter(v[1::2]).most_common()


if L[0][0]!=R[0][0]:#再頻出の数がRとLで同一ではない場合
    ans=n-L[0][1]-R[0][1]
elif len(R)!=1 and len(L)!=1:
    ans=n-max(L[0][1]+R[1][1],L[1][1]+R[0][1])
elif len(R)!=1 and len(L)==1:
    ans=n-R[1][1]-L[0][1]
elif len(R)==1 and len(L)!=1:
    ans=n-R[0][1]-L[1][1]
elif len(R)==1 and len(L)==1:
    ans=n//2
print(ans)

Submission status: Accepted

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

c0=Counter(v[0::2]).most_common()
c1=Counter(v[1::2]).most_common()

if c0[0][0]!=c1[0][0]:#再頻出の数がRとLで同一ではない場合
    ans=n-c0[0][1]-c1[0][1]
elif len(c0)!=1 and len(c1)!=1:
    ans=n-max(c0[0][1]+c1[1][1],c0[1][1]+c1[0][1])
elif len(c0)!=1 and len(c1)==1:
    ans=n-c0[1][1]-c1[0][1]
elif len(c0)==1 and len(c1)!=1:
    ans=n-c0[0][1]-c1[1][1]
elif len(c0)==1 and len(c1)==1:
    ans=n//2
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import product

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

# 出現回数
O_cnt,E_cnt=Counter(V[::2]),Counter(V[1::2])
O_cnt[-1]=0
E_cnt[-2]=0

# 出現回数順
O_key,E_key=O_cnt.most_common(2),E_cnt.most_common(2)

ans=float('inf')

for O_k,E_k in product(O_key,E_key):
    if O_k[0]!=E_k[0]:
	    ans=min(ans,N-O_k[1]-E_k[1])
print(ans)

Submission status: Accepted

Solution code:
from collections  import Counter
n = int(input())
l = [int(i) for i in input().split()]
 
l1 = [l[i] for i in range(n) if i%2 ==0]
l2 = [l[i] for i in range(n) if i%2 ==1]
 
c1 = Counter(l1)
c2 = Counter(l2)
 
even1 = c1.most_common()[0][1]
even2 = c1.most_common()[1][1] if len(c1) > 1 else 0
odd1 = c2.most_common()[0][1]
odd2 = c2.most_common()[1][1] if len(c2) > 1 else 0

if c1.most_common()[0][0] == c2.most_common()[0][0]:
    ans = min((n - even1 - odd2),(n - odd1 - even2))
else:
    ans = (n//2 - even1) + (n//2 - odd1)
    
print(ans)

Submission status: Accepted

Solution code:
import itertools
"""
n = int(input())
m, a, r, c, h = [0] * 5
for i in range(n):
    s = input()
    if s[0] == "M": m += 1
    if s[0] == "A": a += 1
    if s[0] == "R": r += 1
    if s[0] == "C": c += 1
    if s[0] == "H": h += 1
x = [m, a, r, c, h]
y = ["M", "A", "R", "C", "H"]
ans = 0
for i in itertools.combinations(x, 3):
    ans += i[0] * i[1] * i[2]
print(ans)
"""

# n <= 10**5
n = int(input())
# vi <= 10**5
v = list(map(int, input().split()))
a = [[0] * 100010 for _ in range(2)]
for i in range(n):
    a[i % 2][v[i]] += 1

od, ev = [], []
for i in range(100010):
    od.append([a[1][i], i])
    ev.append([a[0][i], i])
od.sort()
od.reverse()
ev.sort()
ev.reverse()
if od[0][1] != ev[0][1]: print(n - od[0][0] - ev[0][0])
else: print(n - max(od[0][0] + ev[1][0], od[1][0] + ev[0][0]))

Submission status: Accepted

Solution code:
from collections import Counter

def solve(n, V):
    if V.count(V[0]) == n:
        return n // 2
    return min(
        n - oc - ec
        for o, oc in Counter(V[0::2]).most_common(2)
        for e, ec in Counter(V[1::2]).most_common(2)
        if o != e
    )

_n = int(input())
_V = list(map(int, input().split()))
print(solve(_n, _V))

Submission status: Accepted

Solution code:
from collections import Counter

def solve(n, V):
    if len(set(V)) == 1:
        return n // 2
    return min(
        n - oc - ec
        for o, oc in Counter(V[0::2]).most_common(2)
        for e, ec in Counter(V[1::2]).most_common(2)
        if o != e
    )

_n = int(input())
_V = list(map(int, input().split()))
print(solve(_n, _V))

Submission status: Accepted

Solution code:
from collections import Counter

def solve(n, V):
    if len(set(V)) == 1:
        return n // 2
    odds = V[0::2]
    evens = V[1::2]
    return min(
        len(odds) - oc + len(evens) - ec
        for o, oc in Counter(odds).most_common(2)
        for e, ec in Counter(evens).most_common(2)
        if o != e
    )

_n = int(input())
_V = list(map(int, input().split()))
print(solve(_n, _V))

Submission status: Accepted

Solution code:
from collections import Counter

def solve(n, V):
    odds = V[0::2]
    evens = V[1::2]
    o2 = [k for k, c in Counter(odds).most_common(2)]
    e2 = [k for k, c in Counter(evens).most_common(2)]
    if len(o2) == 1 and o2 == e2:
        return n // 2
    return min(
        len(odds) - odds.count(o) + len(evens) - evens.count(e)
        for o in o2
        for e in e2
        if o != e
    )

_n = int(input())
_V = list(map(int, input().split()))
print(solve(_n, _V))

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

odd = v[::-2]
even = v[::2]
#一個飛ばしもこうすれば簡単に書ける

o_elm = Counter(odd).most_common(2)+[(0,0)]
e_elm = Counter(even).most_common(2)+[(0,0)]
if o_elm[0][0]==e_elm[0][0]:
  print(N -max(o_elm[0][1]+e_elm[1][1], o_elm[1][1]+e_elm[0][1]))
else:
  print(N -o_elm[0][1] -e_elm[0][1])

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

mod = 1000000007
inf = 1 << 60

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

from collections import Counter
from itertools import product

n = ni()
a = na()

even = Counter(a[::2])
odd = Counter(a[1::2])

even[-1] = 0
odd[-2] = 0

e = even.most_common(2)
o = odd.most_common(2)

ans = n
for (k1, v1), (k2, v2) in product(e, o):
    if k1 == k2:
        continue
    x = (n - v1 - v2)
    if ans > x:
        ans = x

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
# Counterについては↓
# https://qiita.com/JunJun0706/items/9d1befb90a823c466c32#%E6%9C%80%E9%A0%BB%E5%80%A4
n = int(input())
v = list(map(int, input().split()))

o = []
e = []

for i in range(n):
    # 奇遇が逆なの注意
    if i%2 == 1:
        e.append(v[i])
    else:
        o.append(v[i])

o = Counter(o)
e = Counter(e)
#  print(o)
#  print(e)
#  print(len(e))
#  print(o.most_common(1))
#  print(o.most_common(2))
#  print(e.most_common(1))
#  print(e.most_common(2))

if o.most_common(1)[0][0] != e.most_common(1)[0][0]:
    #  ans += (n/2 - o.most_common(1)[0][1]) + (n/2 - e.most_common(1)[0][1])
    ans = n - o.most_common(1)[0][1] - e.most_common(1)[0][1]
elif len(o) == 1 and len(e) == 1:
    # 例3のパターン
    ans = n/2
else:
    # 1 1 1 2 パターン
    # 1 1 2 1 パターン
    #  temp1 = (n/2 - o.most_common(2)[0][1]) + (n/2 - e.most_common(1)[0][1])
    try:
        temp1 = n - o.most_common(2)[1][1] - e.most_common(1)[0][1]
    except:
        temp1 = 10**6
    try:
        temp2 = n - o.most_common(1)[0][1] - e.most_common(2)[1][1]
    except:
        temp2 = 10**6
    ans = min(temp1, temp2)

print(int(ans))

Submission status: Accepted

Solution code:
N=int(input())
A = list( map(int,input().split()))
C0 = [ [0,i] for i in range(100005) ]
C1 = [ [0,i] for i in range(100005) ]
for i in range(0,N,2):
    C0[A[i]][0] += 1
    C1[A[i+1]][0] += 1
C0.sort(reverse=True)
C1.sort(reverse=True)
if C0[0][1] == C1[0][1]:
    ans = N - max(C0[0][0]+C1[1][0], C0[1][0]+C1[0][0])
else:
    ans = N - C0[0][0] - C1[0][0]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
dic1={}
dic2={}
for i in range(n):
  if i%2==0:
    if l[i] in dic1:
      dic1[l[i]] += 1
    else:
      dic1[l[i]]=1
  else:
    if l[i] in dic2:
      dic2[l[i]] += 1
    else:
      dic2[l[i]]=1
dic1a = sorted(dic1.items(),key = lambda x:x[1])
dic2a = sorted(dic2.items(),key = lambda x:x[1]) 
 
if dic1a[-1][0] == dic2a[-1][0]:
    if len(dic1a) == len(dic2a) == 1:
        print(n//2)
    else:
        if dic1a[-2][1] >= dic2a[-2][1]:
            print(sum(dic2.values())-dic2a[-1][1]+sum(dic1.values())-dic1a[-2][1])
        else:
            print(sum(dic1.values())-dic1a[-1][1]+sum(dic2.values())-dic2a[-2][1])
else:
    print(sum(dic1.values())-dic1a[-1][1]+sum(dic2.values())-dic2a[-1][1])

Submission status: Accepted

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

m = max(v)+1
o = [0]*m
e = [0]*m

for i in range(n):
    if i%2 == 0:
        o[v[i]] += 1
    else:
        e[v[i]] += 1

a = sorted(o)[-2:]
b = sorted(e)[-2:]


if o.index(a[1]) == e.index(b[1]):
    if a[0] >= b[0]:
        ans = n - o[o.index(a[0])] - e[e.index(b[1])]
    else:
        ans = n - o[o.index(a[1])] - e[e.index(b[0])]
else:
    ans = n - a[1] - b[1]
    
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict as DD
import numpy as np
N = int(input())
v = list(map(int, input().split()))

E = DD(int)
O = DD(int)
E[-1] = 0
O[-1] = 0
for i in range(N):
  if i % 2 == 1:
    E[v[i]] += 1
  else:
    O[v[i]] += 1

NE = np.array(sorted(E.items(), key=lambda x: x[1], reverse = True))
NO = np.array(sorted(O.items(), key=lambda x: x[1], reverse = True))

#print (NE)
#print (NO)
ans = 0
if NE[0][0] == NO[0][0]:
  if len(NE) == 2 and  len(NO) == 2:
    ans = NE[0][1]
  else:
      ans = min(sum(NO[:,1]) - NO[1][1] + sum(NE[1:,1]), sum(NE[:,1]) - NE[1][1] + sum(NO[1:,1]))
else:
  ans = sum(NE[1:,1]) + sum(NO[1:,1])
print (ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v_1 = v[0:n:2]
v_2 = v[1:n:2]
count_1 = dict(Counter(v_1))
count_2 = dict(Counter(v_2))

# 同じ値かチェック
v1 = sorted(count_1.items(), key=lambda x:x[1], reverse=True)
v2 = sorted(count_2.items(), key=lambda x:x[1], reverse=True)


def calc(l):
    if len(l) == 1:
        return l[0][1]
    else:
        return l[0][1] - l[1][1]
    
    
if v1[0][0] == v2[0][0]:
    
    if calc(v1) > calc(v2):
        s1 = v1[0][0]
        if len(v2) == 1:
            s2 = s1 + 1
        else:
            s2 = v2[1][0]
    else:
        s2 = v2[0][0]
        if len(v1) == 1:
            s1 = s2 + 1
        else:
            s1 = v1[1][0]
else:
    s1 = v1[0][0]
    s2 = v2[0][0]

ans = n - v_1.count(s1) - v_2.count(s2)
print(ans)