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:

N = int(input())
seq = list(map(int, input().rstrip().split(' ')))

odd = [[0, i] for i in range(int(1e5 + 1))]
even = [[0, i] for i in range(int(1e5 + 1))]

for i in range(0, N, 2):
    even[seq[i]][0] += 1
    
for i in range(1, N, 2):
    odd[seq[i]][0] += 1

sorted_even = sorted(even, key=lambda x: x[0])[::-1]
sorted_odd = sorted(odd, key=lambda x: x[0])[::-1]

if sorted_even[0][1] == sorted_odd[0][1]:
    if sorted_even[0][0] + sorted_odd[1][0] > sorted_even[1][0] + sorted_odd[0][0]:
        max_even = sorted_even[0][0]
        max_odd = sorted_odd[1][0]
    else:
        max_even = sorted_even[1][0]
        max_odd = sorted_odd[0][0]
else:
    max_even = sorted_even[0][0]
    max_odd = sorted_odd[0][0]
 
count = 0
count += N // 2 - max_even
count += N // 2 - max_odd

print(count)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
e=[0]*(n//2)#偶数番号
o=[0]*(n//2)#奇数番号
ans=0
for i in range(n):
    if i%2==0:
        e[i//2]=v[i]
    else:
        o[(i-1)//2]=v[i]
a=Counter(e)
b=Counter(o)
c=a.most_common(2)
d=b.most_common(2)
if c[0][0]!=d[0][0]:#一番多い数が違う
    ans=n-c[0][1]-d[0][1]
else:#同じ→どちらかは2番目の方に揃える
    if len(c)==1:#偶数列が1種類の数から
        if len(d)==1:
            ans=n//2
        else:
            ans=len(d)-d[1][1]
    elif len(d)==1:#奇数列が1種類の数から
        if len(c)==1:
            ans=n//2
        else:
            ans=len(c)-c[1][1]
    else:
        if c[0][1]>d[0][1]:
            ans=n-c[0][1]-d[1][1]
        elif c[0][1]==d[0][1]:
            ans=min(n-c[0][1]-d[1][1],n-c[1][1]-d[0][1])
        else:
            ans=n-c[1][1]-d[0][1]
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
 
def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    #偶数列 奇数列
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    #頻値を取り出す
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    ans = -1
    
    #print(even_c)
    #print(odd_c)
    #print(len(even_c))
    
    #最頻値の比較
    if even_c[0][0] != odd_c[0][0]:
        ans = len(m) - (even_c[0][1] + odd_c[0][1])
    
    #偶数列と奇数列の最頻値の数字が同じかつ、全て同じ数字じゃない
    elif even_c[0][0] == odd_c[0][0] and len(even_c) > 1:
        ans1 = len(m) - (even_c[0][1] + odd_c[1][1])
        ans2 = len(m) - (even_c[1][1] + odd_c[0][1])
        ans = ans1 if ans1 <= ans2 else ans2
    
    #全て同じ
    else:
        ans = even_c[0][1]
        
    #出力
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import*;n,*v=map(int,open(0).read().split());a,b=[Counter(v[i::2]).most_common()+[(0,0)]for i in(0,1)];i,x=a[0];j,y=b[0];print(n-[x+y,max(x+b[1][1],y+a[1][1])][i==j])

Submission status: Accepted

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

a = []
b = []
for i in range(n//2):
    a.append(v[2*i])
    b.append(v[2*i+1])

def change(list):
    counter = Counter(list)
    m_ap1 = '0'
    m_ap2 = '0'
    if len(counter.most_common()) > 1:
        m_ap1, m_ap2 = counter.most_common()[0][0], counter.most_common()[1][0]
    else:
        m_ap1 = counter.most_common()[0][0]
    l = len(list)
    cnt1 = 0
    cnt2 = 0
    for i in range(l):
        if list[i] != m_ap1:
            cnt1 += 1
        if list[i] != m_ap2:
            cnt2 += 1
    return cnt1, cnt2, m_ap1, m_ap2
ca1, ca2, ma1, ma2 = change(a)
cb1, cb2, mb1, mb2 = change(b)
# print(change(a))
# print(change(b))
if ca1+cb1:
    if ma1 != mb1:
        print(ca1+cb1)
    else:
        print(min(ca1+cb2,cb1+ca2))
else:
    if ma1 != mb1:
        print(ca1+cb1)
    else:
        print(n//2)

Submission status: Accepted

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

from collections import Counter

v_0 = v[0::2]
v_1 = v[1::2]
v_0_ = Counter(v_0)
v_1_ = Counter(v_1)
v_0_[-1] = 0
v_1_[-1] = 0
v_0_ = v_0_.most_common()
v_1_ = v_1_.most_common()

if v_0_[0][0] != v_1_[0][0]:
    print(n-v_0_[0][1]-v_1_[0][1])
else:
    if v_0_[0][1] + v_1_[1][1] > v_0_[1][1] + v_1_[0][1]:
        print(n - v_0_[0][1] - v_1_[1][1])
    else:
        print(n - v_0_[1][1] - v_1_[0][1])

Submission status: Accepted

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

v = [v[::2], v[1::2]]

from collections import Counter
from operator import itemgetter
from itertools import product
c = list(map(Counter, v))
s = [sorted(d.items(), key=itemgetter(1), reverse=True) for d in c]
s = [(d + [(0, 0)])[:2] for d in s]
keep = 0
for e, o in product(*s):
    if e[0] == o[0]:
        continue
    tmp = e[1] + o[1]
    if tmp > keep:
        keep = tmp
ans = n - keep
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lst = str(input()).split(' ')
 
p1 = [0]*(max([int(i) for i in lst])+1)
p2 = [0]*(max([int(i) for i in lst])+1)
for idx in range(n):
	if idx%2 == 0:
		p1[int(lst[idx])] += 1
	else:
		p2[int(lst[idx])] += 1

if p1.index(max(p1)) == p2.index(max(p2)):
	print(min(n-max(p1)-sorted(p2)[-2], n-sorted(p1)[-2]-max(p2)))
else:
	print(n-max(p1)-max(p2))

'''
pp1 = p1.index(max(p1))
pp2 = p2.index(max(p2))
if pp1 == pp2:
	if max(p1)+sorted(p2)[-2] >= sorted(p1)[-2]+max(p2):
		pp2 = p2.index(sorted(p2)[-2])
		print(n-max(p1)-sorted(p2)[-2])
	else:
		pp1 = p1.index(sorted(p1)[-2])
		print(n-sorted(p1)[-2]-max(p2))
else:
	print(n-max(p1)-max(p2))

cnt1 = 0
cnt2 = 0
for idx in range(n):
	if idx%2 == 0:
		if not lst[idx] == str(pp1):
			cnt1 += 1
	else:
		if not lst[idx] == str(pp2):
			cnt2 += 1
'''

Submission status: Accepted

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

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

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

o.append((0,0))
e.append((0,0))

if o[0][0]==e[0][0]:
    ans=min(N-o[0][1]-e[1][1],N-e[0][1]-o[1][1])
else:
    ans=N-o[0][1]-e[0][1]
print(ans)



"""
ans=N
for o_l in o:
    for e_l in e:
        if o_l[0]!=e_l[0]:
            ans=min(ans,N-o_l[1]-e_l[1])
print(ans)
"""

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
V = list(map(int,input().split()))
even = Counter(V[1::2]).most_common()+([[0, 0]])
odd = Counter(V[::2]).most_common()+([[0, 0]])
if(even[0][0] != odd[0][0]):
  print(N-even[0][1]-odd[0][1])
else:
  print(min(N-even[1][1]-odd[0][1], N-even[0][1]-odd[1][1]))

Submission status: Accepted

Solution code:
n = int(input())
lst = str(input()).split(' ')

p1 = [0]*(max([int(i) for i in lst])+1)
p2 = [0]*(max([int(i) for i in lst])+1)
for idx in range(n):
	if idx%2 == 0:
		p1[int(lst[idx])] += 1
	else:
		p2[int(lst[idx])] += 1

pp1 = p1.index(max(p1))
pp2 = p2.index(max(p2))
if pp1 == pp2:
	if max(p1)+sorted(p2)[-2] >= sorted(p1)[-2]+max(p2):
		pp2 = p2.index(sorted(p2)[-2])
	else:
		pp1 = p1.index(sorted(p1)[-2])

cnt1 = 0
cnt2 = 0
for idx in range(n):
	if idx%2 == 0:
		if not lst[idx] == str(pp1):
			cnt1 += 1
	else:
		if not lst[idx] == str(pp2):
			cnt2 += 1

print(cnt1 + cnt2)

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    n = int(input())
    v_n = input().split(' ')
    
    gu = Counter(v_n[::2])
    ki = Counter(v_n[1::2])

    guusuu = gu.most_common()
    kisuu = ki.most_common()

    # print(guusuu, len(guusuu))
    # print(kisuu, len(kisuu))
    
    if guusuu[0][0]==kisuu[0][0]:
        if len(guusuu)==1 and len(kisuu)==1:
            # n=4, `4 4 4 4`
            # print('----------')
            print(guusuu[0][1])
        else:
            print(min(n - guusuu[0][1] - kisuu[1][1], n - guusuu[1][1] - kisuu[0][1]))
    else:
        print(n - guusuu[0][1] - kisuu[0][1])

main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(n: int, v: "List[int]"):
    a = {-1: 0}
    b = {-1: 0}
    for vv in v[::2]:
        if vv in a:
            a[vv] += 1
        else:
            a[vv] = 1
    for vv in v[1::2]:
        if vv in b:
            b[vv] += 1
        else:
            b[vv] = 1
    ai = sorted(list(a.keys()), key=lambda x: a[x], reverse=True)
    bi = sorted(list(b.keys()), key=lambda x: b[x], reverse=True)
    if ai[0] == bi[0]:
        ans1 = sum([a[x] for x in ai[1:]]) + sum([b[x] for x in bi])-b[bi[1]]
        ans2 = sum([a[x] for x in ai]) + sum([b[x] for x in bi[1:]])-a[ai[1]]
        print(min(ans1, ans2))

    else:
        ans = sum([a[x] for x in ai[1:]]) + sum([b[x] for x in bi[1:]])
        print(ans)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, v)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]

if len(set(a)) == 1:
    p = int(n/2)
else:
    b0 = set(a[::2])
    if len(b0)==1:
        q0 = 0
        mark00 = a[0]
        count00, count01 = int(n/2), 0
    else:
        c = Counter(a[::2])
        q0 =  int(n/2) - c.most_common(1)[0][1]
        mark00, mark01 = c.most_common(2)[0][0], c.most_common(2)[1][0]
        count00, count01 = c.most_common(2)[0][1], c.most_common(2)[1][1]

    b1 = set(a[1::2])
    if len(b1)==1:
        q1 = 0
        mark10 = a[1]
        count10, count11 = int(n/2), 0
    else:
        c = Counter(a[1::2])
        q1 =  int(n/2) - c.most_common(1)[0][1]
        mark10, mark11 = c.most_common(2)[0][0], c.most_common(2)[1][0]
        count10, count11 = c.most_common(2)[0][1], c.most_common(2)[1][1]
    if mark00==mark10:
        if count00+count01>count10+count11:
            p = n - (count00+count01)
        else:
            p = n - (count10+count11)
    else:
        p = n - (count00 + count10)

print(p)

Submission status: Accepted

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

def mkdc(l):
    di=dict()
    for i in range(len(l)):
        if l[i] in di:
            di[l[i]]+=1
        else:
            di[l[i]]=1
    return di

e,o=[],[]      
for i in range(int(n/2)):
    e.append(v[2*i])
    o.append(v[2*i+1])
#print(e)
de=mkdc(e)
do=mkdc(o)
#print(de)
de=sorted(de.items(),key=lambda d: d[1],reverse=True)
do=sorted(do.items(),key=lambda d: d[1],reverse=True)
de.append((0,0))
do.append((0,0))
#de=sorted(de)
#print(de)
if do[0][0]==de[0][0]:
    print(n- do[0][1]-max(de[1][1],do[1][1]))
else:
    print(n-de[0][1]-do[0][1])

Submission status: Accepted

Solution code:
import collections

N = int(input())
lst = input().split()
lst1 = []
lst2 = []
for i in range(N//2):
    lst1.append(lst[2 * i])
    lst2.append(lst[2 * i + 1])
dict1 = collections.Counter(lst1)
dict2 = collections.Counter(lst2)
#各リストで書き換える数
count1  = 0 
count2  = 0
# リスト１とリスト２の最頻語が同じであれば、
if (dict1.most_common()[0][0] == dict2.most_common()[0][0] ):
	# リスト１の方が多く出ている場合
	if dict1.most_common()[0][1] > dict2.most_common()[0][1]:
		count1 =  len(lst1) - dict1.most_common()[0][1]
		if len(lst2) == dict2.most_common()[0][1]:
			count2 = len(lst2)
		else:
		    count2 =  len(lst2) - dict2.most_common()[1][1]
	elif dict1.most_common()[0][1] < dict2.most_common()[0][1]:
		if len(lst1) == dict1.most_common()[0][1]:
			count1 = len(lst1)
		else:
		    count1 =  len(lst1) - dict1.most_common()[1][1]
		count2 =  len(lst2) - dict2.most_common()[0][1]
	# リスト１とリスト２の出現回数が同じであれば、２番目の数で決める
	else :
		if len(lst1) == dict1.most_common()[0][1]:
			count1 = len(lst1) 
		elif (dict1.most_common()[1][1] >= dict2.most_common()[1][1]):
			count1 =  len(lst1) - dict1.most_common()[1][1]
			count2 =  len(lst2) - dict2.most_common()[0][1]
		else:
			count1 =  len(lst1) - dict1.most_common()[0][1]
			count2 =  len(lst2) - dict2.most_common()[1][1]

else:
		count1 =  len(lst1) - dict1.most_common()[0][1]
		count2 =  len(lst2) - dict2.most_common()[0][1]

print(count1 + count2)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
even = Counter(v[1::2]).most_common(2)
odd = Counter(v[0::2]).most_common(2)
# print(even)
# print(odd)
if even[0][0] != odd[0][0]:
    print(n - even[0][1] - odd[0][1])
else:
    if len(even) == 1 or len(odd) == 1:
        print(n//2)
    else:
        print(n - max(even[0][1]+odd[1][1], even[1][1]+odd[0][1]))

Submission status: Accepted

Solution code:
from collections import Counter

input = open(0).read

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


def main():
    e = Counter(v[::2])
    o = Counter(v[1::2])

    em = e.most_common(2)
    om = o.most_common(2)

    # 要素は最低でも 2 つ
    em.append((0, 0))
    om.append((0, 0))

    if em[0][0] == om[0][0]:
        print(min(n - em[0][1] - om[1][1], n - em[1][1] - om[0][1]))
    else:
        print(n - em[0][1] - om[0][1])

    return


main()

Submission status: Accepted

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

def calc(start): 
    di = dict()
    for i in range(start, N, 2):
        if Ai[i] in di:
            n = di[Ai[i]]
            di[Ai[i]] = n + 1
        else:
            di[Ai[i]] = 1
    l = []
    for k in di.keys():
        l.append([k, di[k]])
    l.sort(key=lambda x: x[1], reverse=True)
    return l

l1 = calc(0)
l2 = calc(1)

if l1[0][0] != l2[0][0]:
    print(N - l1[0][1] - l2[0][1])
elif len(l1) == 1 and len(l2) == 1:
    print(N // 2)
else:
    v1 = 100000000000000
    v2 = 100000000000000

    if len(l1) > 1:
        v1 = N - l1[1][1] - l2[0][1]
    if len(l2) > 1:
        v2 = N - l1[0][1] - l2[1][1]
    print(min(v1, v2))

Submission status: Accepted

Solution code:
import numpy as np
from collections import Counter
n = int(input())
As = input().split()
As = [int(A) for A in As]

A_odd = As[::2]         #奇数列
A_even = As[1:][::2]    #偶数列

# 最頻の要素を並べる
odd_pair = Counter(A_odd).most_common(2)
even_pair = Counter(A_even).most_common(2)

if odd_pair[0][0] != even_pair[0][0]:               # TOPの数字が違う
    N = n-odd_pair[0][1]-even_pair[0][1]
else:                                               # TOPの数字が一緒
    if len(odd_pair) == 1 and len(even_pair) == 1:  # 文字列がそもそも1種類
        N = n/2
    elif len(odd_pair) == 1:                        # oddが1種類
        N = n-even_pair[1][1]
    elif len(even_pair) == 1:                       # evenが1種類
        N = n-odd_pair[1][1] 
    elif odd_pair[1][1] > even_pair[1][1]:          # oddの2番目のが多い
        N = n-even_pair[0][1]-odd_pair[1][1]
    else:
        N = n-odd_pair[0][1]-even_pair[1][1]        # oddの1番目のが多い
print(int(N))

Submission status: Accepted

Solution code:
import collections as c
N = int(input())
a = list(map(int,input().split()))
ue = a[0::2]
sita = a[1::2]
dictue = c.defaultdict(int)
dictsita = c.defaultdict(int)
for i in ue:
    dictue[i] += 1
for i in sita:
    dictsita[i] += 1
ue = list(dictue.items())
ue.sort(key=lambda x:x[1])
sita = list(dictsita.items())
sita.sort(key=lambda x:x[1])
m = ue[len(ue)-1]
n = sita[len(sita)-1]
if m[0] == n[0]:
    if len(ue) == 1:
        if len(sita) == 1:
            print(N//2)
        else:
            print(N-m[1]-sita[len(sita)-2][1])
    else:
        if len(sita) == 1:
            print(N-n[1]-ue[len(ue)-2][1])
        else:
            print(min(N-n[1]-ue[len(ue)-2][1],N-m[1]-sita[len(sita)-2][1]))
else:
    print(N-m[1]-n[1])

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    v = LI()

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

    #  n = 10**5
    #  #  v = [10**5 - i%18 for i in range(n)]
    #  v = [random.randint(0, 100) for i in range(n)]
    #  print(v[:10])

    odd = []
    even = []
    for idx, i in enumerate(v):
        if idx % 2 == 0:
            even.append(i)
        else:
            odd.append(i)

    # Counterが速い
    odd_count = collections.Counter(odd)
    even_count = collections.Counter(even)

    #  print(odd_count, even_count)
    if len(odd_count) == len(even_count) == 1:
        # 変更の必要なし
        print(0)
        exit()

    if odd_count.most_common(1)[0][0] != even_count.most_common(1)[0][0]:
        # 楽なほう
        if len(odd_count) == 1:
            even_result = sum([i[1] for i in even_count.most_common()[1:]])
            print(even_result)
        elif len(even_count) == 1:
            odd_result = sum([i[1] for i in odd_count.most_common()[1:]])
            print(odd_result)
        else:
            odd_result = sum([i[1] for i in odd_count.most_common()[1:]])
            even_result = sum([i[1] for i in even_count.most_common()[1:]])
            print(odd_result + even_result)
    else:
        # 全部同じ数字にならないようにしたい
        # ２個め同士で比べて、２個めをより多く含んでる方はそっちにしちゃう
        if len(odd_count) == 1:
            even_result = even_count.most_common(1)[0][1]
            even_result += sum([i[1] for i in even_count.most_common()[2:]])
            print(even_result)
        elif len(even_count) == 1:
            odd_result = odd_count.most_common(1)[0][1]
            odd_result += sum([i[1] for i in odd_count.most_common()[2:]])
            print(odd_result)
        elif odd_count.most_common(2)[1][1] > even_count.most_common(2)[1][1]:
            # oddは２つめに多いものを不変にする
            # evenは１つめを不変に
            odd_result = odd_count.most_common(1)[0][1]
            odd_result += sum([i[1] for i in odd_count.most_common()[2:]])
            even_result = sum([i[1] for i in even_count.most_common()[1:]])
            print(odd_result + even_result)
        else:
            odd_result = sum([i[1] for i in odd_count.most_common(len(odd_count))[1:]])
            even_result = even_count.most_common(1)[0][1]
            even_result += sum([i[1] for i in even_count.most_common()[2:]])
            print(odd_result + even_result)

main()

Submission status: Accepted

Solution code:
def ans():
  N = int(input())
  V = list(map(int,input().split()))
  even = [0]*100001
  odd = [0]*100001
  for v in V[1::2]:
    even[v] += 1
  for v in V[::2]:
    odd[v] += 1
  me = max(even)
  mo = max(odd)
  if(even.index(me) != odd.index(mo)):
    print(N - me - mo)
  else:
    even.sort()
    odd.sort()
    print(min(N-even[-1]-odd[-2], N-even[-2]-odd[-1]))
ans()

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

n = ri()
v=rl()
a = []
b = []
for i in range(0,n,2):
    a.append(v[i])
for i in range(1,n,2):
    b.append(v[i])

import collections
ca = collections.Counter(a)
ca = ca.most_common()
cb = collections.Counter(b)
cb = cb.most_common()
la = len(a)
lb = len(b)

if ca[0][0] != cb[0][0]:
    ans = (la - ca[0][1]) + (lb - cb[0][1])
else:
    ans = []
    if len(ca) >= 2:
        ans.append(la-ca[1][1] + lb-cb[0][1])
    if len(cb) >= 2:
        ans.append(la-ca[0][1] + lb-cb[1][1])
    if len(ca)==1 and len(cb)==1:
        ans.append(ca[0][1])
        ans.append(cb[0][1])
    ans = min(ans)

print(ans)

Submission status: Accepted

Solution code:
def dekoboko(n: int, v: list) -> int:
    o, e = {}, {}
    for i, vv in enumerate(v):
        if i % 2 == 0:
            if vv not in e:
                e[vv] = 1
            else:
                e[vv] += 1
        else:
            if vv not in o:
                o[vv] = 1
            else:
                o[vv] += 1

    ol = sorted(o.items(), key=lambda x: -x[1])
    el = sorted(e.items(), key=lambda x: -x[1])

    # pivot 選択
    # 頻度が最大のものを固定してそれに合わす様にしたいが、
    # 偶数番号列と奇数番号列とで同じあたいの pivot を使う
    # ことはできない。なので、頻度が最大のものがかぶる様な
    # ら、2番目に頻度が多いものを比較して、頻度の多い方は
    # 2番目のものを使う様にする。
    if ol[0][0] == el[0][0]:
        if len(ol) > 1:
            # 長さが 1 でない時は 2 番目に頻度が高いものの頻度を比べる。
            if ol[1][1] > el[1][1]:
                ol[0], ol[1] = ol[1], ol[0]
            else:
                el[0], el[1] = el[1], el[0]
        else:  # len(ol) == 1
            # 長さが 1 の時はダミーを挿入する
            el.append((0, 0))
            el[0], el[1] = el[1], el[0]

    return sum(v for _, v in ol[1:]) + sum(v for _, v in el[1:])


if __name__ == "__main__":
    n = int(input())
    v = map(int, input().split())
    ans = dekoboko(n, v)
    print(ans)

Submission status: Accepted

Solution code:
import collections
 
n=int(input())
v=list(map(int,input().split()))
 
even=v[0::2]
odd=v[1::2]
 
even_count=collections.Counter(even).most_common()
odd_count=collections.Counter(odd).most_common()
 
#最多出現のものが重複していない
if even_count[0][0]!=odd_count[0][0]:
    print(n-even_count[0][1]-odd_count[0][1])
    
#最多出現のものが重複
else:
    if len(even_count)==1:
        a=0
    else:
        a=even_count[1][1]
 
    if len(odd_count)==1:
        b=0
    else:
        b=odd_count[1][1]    
    
    ans1=n-a-odd_count[0][1]
    ans2=n-even_count[0][1]-b
    print(min(ans1,ans2))

Submission status: Accepted

Solution code:
from collections import Counter

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

even = v[0::2]
odd = v[1::2]
count_even = Counter(even).most_common()
count_odd = Counter(odd).most_common()

if count_even[0][0] == count_odd[0][0]:
    a = 0 if len(count_odd) == 1 else count_odd[1][1]
    b = 0 if len(count_even) == 1 else count_even[1][1]
    print(n - max(count_even[0][1] + a, count_odd[0][1] + b))
else:
    print(n - count_even[0][1] - count_odd[0][1])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
a = []
b = []
for i in range(n):
    if i % 2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])

a = Counter(a)
amc = a.most_common()
b = Counter(b)
bmc = b.most_common()
amc.append((0,0))
bmc.append((0,0))
rewrite = 0

if amc[0][0] == bmc[0][0]:
    rewrite = max(amc[0][1]+bmc[1][1],amc[1][1]+bmc[0][1])
else:
    rewrite = amc[0][1]+bmc[0][1]
print(n-rewrite)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
even=Counter(v[0::2]).most_common()
odd=Counter(v[1::2]).most_common()
even.append((0,0))
odd.append((0,0))
if even[0][0]!=odd[0][0]:print(n-(even[0][1]+odd[0][1]))
else:print(min(n-(even[0][1]+odd[1][1]),n-(even[1][1]+odd[0][1])))

Submission status: Accepted

Solution code:
import collections
n=int(input())
arr=input().split(" ")
arr_s=set(arr)
a=0
arr_e=[0 for i in range(int(n/2))]
arr_o=[0 for i in range(int(n/2))]
for i in range(int(n/2)):
    arr_e[i]=arr[a]
    arr_o[i]=arr[a+1]
    a+=2
ce=collections.Counter(arr_e).most_common()
co=collections.Counter(arr_o).most_common()
if len(arr_s)==1:
    print(int(n/2))
else:
    if ce[0][0]!=co[0][0]:
        print(n-ce[0][1]-co[0][1])
    else:
        print(n-max(ce[0][1]+co[1][1],ce[1][1]+co[0][1]))

Submission status: Accepted

Solution code:
from collections import Counter

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

ve = Counter(V[0::2]).most_common(2)
vo = Counter(V[1::2]).most_common(2)

# 最頻出が偶奇のリストでそれぞれ異なるときは、それぞれを最頻出で置き換える
if ve[0][0] != vo[0][0]:
    print(n - ve[0][1] - vo[0][1])
else:
    # 最頻出の数が1種類のみのとき
    if len(ve) == 1 or len(vo) == 1:
        print(n // 2)
    else:
        # 偶奇の最頻出が同じ時、偶奇の最頻出ともう片方の二番目の最頻出の合計が大きい方を
        # 書き換え回数として使用する
        print(n - max(ve[0][1] + vo[1][1], ve[1][1] + vo[0][1]))

Submission status: Accepted

Solution code:
from sys import stdin
import collections
N=int(stdin.readline().rstrip())
data=[(x) for x in stdin.readline().rstrip().split()]
ans=0
if len(set(data)) == 1:
    ans=len((data[1::2]))
else:
    evenc = collections.Counter(data[0::2])
    even_num = evenc.most_common()[0][1]
    alle_num=len(data[0::2])
    
    oddc = collections.Counter(data[1::2])
    odd_num = oddc.most_common()[0][1]
    allo_num=len(data[1::2])
    
    if evenc.most_common()[0][0] == oddc.most_common()[0][0]:
        ans=min((N-(evenc.most_common()[1][1]+odd_num)),(N-(oddc.most_common()[1][1]+even_num)))
    
    else:
        ans=N-(even_num+odd_num)
            
    
print(ans)

Submission status: Accepted

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
odd = []
even = []
for i in range(0, n - 1, 2):
	odd.append(v[i])
	even.append(v[i + 1])
N = n // 2
co = collections.Counter(odd)
ce = collections.Counter(even)
omost = co.most_common(2)
emost = ce.most_common(2)
if len(omost) == 1 and len(emost) == 1:
	if omost[0][0] != emost[0][0]:
		print(0)
	else:
		print(N)
elif len(omost) == 1:
	print(N - emost[0][1])
elif len(emost) == 1:
	print(N - omost[0][1])
else:
	if omost[0][0] != emost[0][0]:
		print(n - omost[0][1] - emost[0][1])
	else:
		print(min(n - omost[0][1] - emost[1][1], n - omost[1][1] - emost[0][1]))

Submission status: Accepted

Solution code:
import collections
v_odd,v_even=[],[]
ans=0
n=int(input())
all_v=input().split()
for i in range(1,n+1):
    if i % 2 == 0:
        v_even.append(all_v[i-1])
    else:
        v_odd.append(all_v[i-1])

v_odd_count = collections.Counter(v_odd)
v_even_count = collections.Counter(v_even)
v1=v_odd_count.most_common(2)
v11=v_even_count.most_common(2)
if v1[0][0] != v11[0][0]:
    ans = n-v1[0][1]-v11[0][1]
else:
    if len(v1)==len(v11)==1:
        ans = n//2
    elif len(v1)==1:
        ans = n//2 - v11[1][1]
    elif len(v11)==1:
        ans = n//2 - v1[1][1]
    else:
        ans = min((n - v1[0][1] - v11[1][1]),(n - v1[1][1] - v11[0][1]))
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

V1, V2 = {}, {}
for i in range(N // 2):
    v1, v2 = V[i * 2], V[i * 2 + 1]
    if v1 in V1:
        V1[v1] += 1
    else:
        V1[v1] = 1
    if v2 in V2:
        V2[v2] += 1
    else:
        V2[v2] = 1

VS1, VS2 = sorted(V1.values()), sorted(V2.values())

if max(V1, key=V1.get) == max(V2, key=V2.get):
    if len(V1) == 1:
        if len(V2) == 1:
            print(N // 2)
        else:
            print(N - VS1[-1] - VS2[-2])
    else:
        if len(V2) == 1:
            print(N - VS1[-2] - VS2[-1])
        else:
            if VS1[-2] < VS2[-2]:
                print(N - VS1[-1] - VS2[-2])
            else:
                print(N - VS1[-2] - VS2[-1])
else:
    print(N - VS1[-1] - VS2[-1])

Submission status: Accepted

Solution code:
import collections


def solve(string):
    n, *v = map(int, string.split())
    if len(set(v)) == 1:
        return str(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())

        return str(min(ans1, ans2))


if __name__ == '__main__':
    print(solve("\n".join([input(), input()])))

Submission status: Accepted

Solution code:
# /user/bin/python
# -*- coding: utf-8 -*-
from collections import Counter
import sys

n = int(sys.stdin.readline().rstrip())
v_s = list(map(int, sys.stdin.readline().rstrip().split()))

v_even = Counter(v_s[0::2]).most_common()
v_even.append((0,0))
v_odd = Counter(v_s[1::2]).most_common()
v_odd.append((0,0))

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

Submission status: Accepted

Solution code:

# coding: utf-8

# In[129]:


from collections import Counter


# In[141]:


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


# In[142]:


v_even = Counter(v[::2]).most_common()
v_odd = Counter(v[1::2]).most_common()


# In[146]:


if len(v_even) == 1:
    v_even.append([0,0])
if len(v_odd) == 1:
    v_odd.append([0,0])
if v_even[0][0] == v_odd[0][0]:
    if v_even[1][1] > v_odd[1][1]:
        ret = n - v_even[1][1] - v_odd[0][1]
    else:
        ret = n - v_even[0][1] - v_odd[1][1]
else:
    ret = n - v_even[0][1] - v_odd[0][1]


# In[147]:


print(ret)

Submission status: Accepted

Solution code:
from collections import*
n,*v=map(int,open(0).read().split())
a,b=[Counter(i).most_common()+[(0,0)]for i in(v[::2],v[1::2])]
i,j=a[0][1],b[0][1]
print(min(n-i-b[1][1],n-a[1][1]-j)*(a[0][0]==b[0][0])or n-i-j)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
vn = list(map(int,input().split()))
vo={}
ve={}
for i in range(n//2):
  if vn[2*i] not in vo:
    vo[vn[2*i]]=0
  vo[vn[2*i]]+=1
  if vn[2*i+1] not in ve:
    ve[vn[2*i+1]]=0
  ve[vn[2*i+1]]+=1
volist = sorted(vo.items(), key=lambda x:x[1], reverse=True)
velist = sorted(ve.items(), key=lambda x:x[1], reverse=True)

if volist[0][0] != velist[0][0]:
  print(n-volist[0][1]-velist[0][1])
elif len(volist) > 1 and len(velist) > 1:
  if volist[1][1] > velist[1][1]:
    print(n-volist[1][1]-velist[0][1])
  else:
    print(n-volist[0][1]-velist[1][1])
else:
  if len(volist) == 1 and len(velist) == 1:
    print(n//2)
  elif len(volist) == 1:
    print(n-volist[0][1]-velist[1][1])
  else:
    print(n-volist[1][1]-velist[0][1])