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: Wrong Answer

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

import collections


'''
奇数番目の数列
'''
v_odd = []
for i in range(0,n,2):
  v_odd.append(v[i])

c_odd = collections.Counter(v_odd)
c_common_odd = c_odd.most_common()


'''
偶数番目の数列
'''
v_even = []
for i in range(1,n,2):
  v_even.append(v[i])

c_even = collections.Counter(v_even)
c_common_even = c_even.most_common()


'''
後処理

1.一番多くカウントした数字が同じ数字
2番目に多くカウントした数字について比較し、数字が小さい方を採用する

2.一番多くカウントした数字が異なる数字
単純に計算

ただし、奇数・偶数の数列に出てくる数字の種類が2種類以上か否か、を考慮する必要がある
'''
# 

if len(c_common_odd) >= 2 and len(c_common_even) >= 2:
  if c_common_odd[0][0] != c_common_even[0][0]:
    ans = n - c_common_odd[0][1] - c_common_even[0][1]
  else:
    if c_common_odd[0][1] >= c_common_even[0][1]:
      ans = n - c_common_odd[0][1] - c_common_even[1][1]
    else:
      ans = n - c_common_odd[1][1] - c_common_even[0][1]
elif len(c_common_odd) < 2 and len(c_common_even) >= 2:
  ans = int(n / 2) - c_common_even[0][1]
elif len(c_common_odd) >= 2 and len(c_common_even) < 2:
  ans = int(n / 2) - c_common_odd[0][1]
# 両方の数字がそれぞれ一種類
else:
  ans = 0

print(ans)

Submission status: Wrong Answer

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

import collections


'''
奇数番目の数列
'''
v_odd = []
for i in range(0,n,2):
  v_odd.append(v[i])

c_odd = collections.Counter(v_odd)
c_common_odd = c_odd.most_common()


'''
偶数番目の数列
'''
v_even = []
for i in range(1,n,2):
  v_even.append(v[i])

c_even = collections.Counter(v_even)
c_common_even = c_even.most_common()


'''
後処理

1.一番多くカウントした数字が同じ数字
2番目に多くカウントした数字について比較し、数字が小さい方を採用する

2.一番多くカウントした数字が異なる数字
単純に計算

ただし、奇数・偶数の数列に出てくる数字の種類が2種類以上か否か、を考慮する必要がある
'''
# 

if len(c_common_odd) >= 2 and len(c_common_even) >= 2:
  if c_common_odd[0][0] != c_common_even[0][0]:
    ans = n - c_common_odd[0][1] - c_common_even[0][1]
  else:
    if c_common_odd[1][1] >= c_common_even[1][1]:
      ans = n - c_common_odd[0][1] - c_common_even[1][1]
    else:
      ans = n - c_common_odd[1][1] - c_common_even[0][1]
elif len(c_common_odd) < 2 and len(c_common_even) >= 2:
  ans = int(n / 2) - c_common_even[0][1]
elif len(c_common_odd) >= 2 and len(c_common_even) < 2:
  ans = int(n / 2) - c_common_odd[0][1]
# 両方の数字がそれぞれ一種類
else:
  ans = 0

print(ans)

Submission status: Wrong Answer

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

import collections


'''
奇数番目の数列
'''
v_odd = []
for i in range(0,n,2):
  v_odd.append(v[i])

c_odd = collections.Counter(v_odd)
c_common_odd = c_odd.most_common()
chane_cnt_odd = int(n / 2) - c_common_odd[0][1]

'''
偶数番目の数列
'''
v_even = []
for i in range(1,n,2):
  v_even.append(v[i])

c_even = collections.Counter(v_even)
c_common_even = c_even.most_common()
chane_cnt_even = int(n / 2) - c_common_even[0][1]

print(chane_cnt_odd + chane_cnt_even)

Submission status: Wrong Answer

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

import collections

c = collections.Counter(v)

# 2種類の要素
if len(c) >= 2:
  cnt = c.most_common()[0][1] + c.most_common()[1][1]
  print(len(v) - cnt)
# 1種類の要素
else:
  print(int(len(v) / 2))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
count=0
A=[[0,i] for i in range(10**5+1)]
Z=[[0,i] for i in range(10**5+1)]
for i in range(n):
  if i%2==0:
    A[v[i]][0]+=1
  else:
    Z[v[i]][0]+=1
A.sort()
Z.sort()
def wfs(x,y):
  if A[x][1]!=Z[y][1]:
    return n-A[x][0]-Z[x][0]
  else:
    return min(wfs(x,y-1),wfs(x-1,y))
print(wfs(-1,-1))

Submission status: Wrong Answer

Solution code:
from itertools import *
from collections import Counter

N = int(input())
v = list(map(int,input().split()))
d = Counter(v).most_common()
most_common = d[0][0]
try:
    second_common = d[1][0]
except:
    print(N//2)
    exit()
try:
    third_common = d[2][0]
except:
    third_common = float('Inf')

def f(v,m,s):
    cnt = 0
    for j in range(N):
        if j % 2 != 0:
            if v[j] != m:
                cnt += 1
        else:
            if v[j] != s:
                cnt += 1
    return cnt

p = [most_common,second_common,third_common]
p = list(product(p,p))
p = [i for i in p if i[0] != i[1]]
ans = float('inf')
for i in p:
    tmp = f(v,i[0],i[1])
    ans = min(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from collections import Counter

N = int(input())
v = list(map(int,input().split()))
d = Counter(v).most_common()
most_common = d[0][0]
try:
    second_common = d[1][0]
except:
    print(N//2)
    exit()

def f(v,m,s):
    cnt = 0
    for j in range(N):
        if j % 2 != 0:
            if v[j] != m:
                cnt += 1
        else:
            if v[j] != s:
                cnt += 1
    return cnt
    
cnt = f(v,most_common,second_common)
ccnt = f(v,second_common,most_common)

print(min(cnt,ccnt))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int, input().split()))
vad = {}
vbd = {}
for i in range(n):
	if i%2 == 0:
		if v[i] in vad:
			vad[v[i]] = vad[v[i]]+1
		else:
			vad[v[i]] = 0
	else:
		if v[i] in vbd:
			vbd[v[i]] = vbd[v[i]]+1
		else:
			vbd[v[i]] = 0

vadl = sorted(vad.items(), key=lambda x: -x[1])[0:1] # value 降順
vbdl = sorted(vbd.items(), key=lambda x: -x[1])[0:1] # value 降順

va_k, va_v = vadl[0]
vb_k, vb_v = vbdl[0]

if va_k == vb_k:
	if va_v==vb_v:
		if len(vadl)==1:
			print(va_v+1)
		else:
			_, va2_v=vadl[1]
			_, vb2_v=vbdl[1]
			print(n//2-va_v+n//2-max(va2_v,vb2_v)-2)
	elif va_v>vb_v:
		vb_k, vb_v=vbdl[1]
		print(n//2-va_v+n//2-vb_v-2)
	else:
		va_k, va_v=vadl[1]
		print(n//2-va_v+n//2-vb_v-2)
else:
	print(n//2-va_v+n//2-vb_v-2)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int, input().split()))
vad = {}
vbd = {}
for i in range(n):
	if i%2 == 0:
		if v[i] in vad:
			vad[v[i]] = vad[v[i]]+1
		else:
			vad[v[i]] = 0
	else:
		if v[i] in vbd:
			vbd[v[i]] = vbd[v[i]]+1
		else:
			vbd[v[i]] = 0

vadl = sorted(vad.items(), key=lambda x: -x[1])[0:1] # value 降順
vbdl = sorted(vbd.items(), key=lambda x: -x[1])[0:1] # value 降順

va_k, va_v = vadl[0]
vb_k, vb_v = vbdl[0]

if va_k == vb_k:
	if va_v==vb_v:
		if len(vadl)==1:
			print(va_v+1)
		else:
			_, va2_v=vadl[1]
			_, vb2_v=vbdl[1]
			print(n//2-va_v+n//2-min(va2_v,vb2_v)-2)
	elif va_v>vb_v:
		vb_k, vb_v=vbdl[1]
		print(n//2-va_v+n//2-vb_v-2)
	else:
		va_k, va_v=vadl[1]
		print(n//2-va_v+n//2-vb_v-2)
else:
	print(n//2-va_v+n//2-vb_v-2)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int, input().split()))
vad = {}
vbd = {}
for i in range(n):
	if i%2 == 0:
		if v[i] in vad:
			vad[v[i]] = vad[v[i]]+1
		else:
			vad[v[i]] = 0
	else:
		if v[i] in vbd:
			vbd[v[i]] = vbd[v[i]]+1
		else:
			vbd[v[i]] = 0

vadl = sorted(vad.items(), key=lambda x: -x[1])[0:1] # value 降順
vbdl = sorted(vbd.items(), key=lambda x: -x[1])[0:1] # value 降順

va_k, va_v = vadl[0]
vb_k, vb_v = vbdl[0]

if va_k == vb_k:
	if va_v==vb_v:
		if len(vadl)==1:
			print(va_v+1)
		else:
			vb_k, vb_v=vbdl[1]
			print(n//2-va_v+n//2-vb_v-2)
	elif va_v>vb_v:
		vb_k, vb_v=vbdl[1]
		print(n//2-va_v+n//2-vb_v-2)
	else:
		va_k, va_v=vadl[1]
		print(n//2-va_v+n//2-vb_v-2)
else:
	print(n//2-va_v+n//2-vb_v-2)

Submission status: Wrong Answer

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 != odd:
  print(N-even[0][1]-odd[0][1])
else:
  print(min(N-even[-1][1]-odd[-2][1], N-even[-2][1]-odd[-1][1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int, input().split()))
even = lst[0::2]
odd = lst[1::2]
del(lst)

even_hash = dict()
odd_hash = dict()

for i in even:
  even_hash[i] = even_hash.get(i, 0) + 1
    
for i in odd:
  odd_hash[i] = odd_hash.get(i, 0) + 1

reven = dict([(v,k) for (k,v) in even_hash.items()])
rodd = dict([(v,k) for (k,v) in odd_hash.items()])

me_list = sorted(list(reven.keys()), reverse=True)
mo_list = sorted(list(rodd.keys()), reverse=True)

me = me_list[0]
mo = mo_list[0]


if me == mo:
  me2 = me_list[1] if len(me_list) >= 2 else 0
  mo2 = mo_list[1] if len(mo_list) >= 2 else 0
  if me + mo2 > me2 + mo:
    print(len(even)-me+len(odd)-mo2)
  else:
    print(len(even)-me2+len(odd)-mo)
else:
  print((len(even)-me)+(len(odd)-mo))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from collections import Counter
import copy
N = int(input())
v = list(map(int,input().split()))
d = Counter(v).most_common()
most_common = d[0][0]
try:
    second_common = d[1][0]
except:
    print(N//2)
    exit()

vv = copy.deepcopy(v)
cnt = 0
for j in range(N):
    if j % 2 != 0:
        if v[j] != most_common:
            #v[j] = most_common
            cnt += 1
    else:
        if v[j] != second_common:
            #v[j] = second_common
            cnt += 1
ccnt = 0
for j in range(N):
    if j % 2 != 0:
        if vv[j] != second_common:
            #vv[j] = second_common
            ccnt += 1
    else:
        if vv[j] != most_common:
            #vv[j] = most_common
            ccnt += 1
#print(v,cnt)
#print(vv,ccnt)
print(min(cnt,ccnt))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from collections import Counter
import copy
N = int(input())
v = list(map(int,input().split()))
d = Counter(v).most_common()
most_common = d[0][0]
try:
    second_common = d[1][0]
except:
    second_common = most_common + 1

vv = copy.deepcopy(v)
cnt = 0
for j in range(N):
    if j % 2 != 0:
        if v[j] != most_common:
            #v[j] = most_common
            cnt += 1
    else:
        if v[j] != second_common:
            #v[j] = second_common
            cnt += 1
ccnt = 0
for j in range(N):
    if j % 2 != 0:
        if vv[j] != second_common:
            #vv[j] = second_common
            ccnt += 1
    else:
        if vv[j] != most_common:
            #vv[j] = most_common
            ccnt += 1
#print(v,cnt)
#print(vv,ccnt)
print(min(cnt,ccnt))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int, input().split()))
import collections
v1=v[0::2]
v11=collections.Counter(v1)
v2=v[1::2]
v22=collections.Counter(v2)
o=v11.most_common()
e=v22.most_common()
if o[0][0]!=e[0][0]:
    print(n-o[0][1]-e[0][1])
elif e[0][1]==o[0][1]:
    print(e[0][1])
else:
    print(min(n-o[0][1]-e[1][1],n-o[1][1]-e[0][1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int, input().split()))
import collections
v1=v[0::2]
v11=collections.Counter(v1)
v2=v[1::2]
v22=collections.Counter(v2)
o=v11.most_common()
e=v22.most_common()
if o[0][0]!=e[0][0] or e==o:
    print(n-o[0][1]-e[0][1])
else:
    print(min(n-o[0][1]-e[1][1],n-o[1][1]-e[0][1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int, input().split()))
import collections
v1=v[0::2]
v11=collections.Counter(v1)
v2=v[1::2]
v22=collections.Counter(v2)
ans=0
o=v11.most_common()[0][0]
e=v22.most_common()[0][0]
for x in v1:
    if x!=o:
        ans+=1
for y in v2:
    if y!=e:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n = int(input())
v = [int(x) for x in input().split()]
li = [[[0 for _ in range(2)] for _ in range(10**5)] for _ in range(2)]
for index,i in enumerate(v):
    li[index%2][i-1][0]+=1
    li[index%2][i-1][1]=i

li[0].sort(key=itemgetter(0),reverse=True)
li[1].sort(key=itemgetter(0),reverse=True)

if(li[0][0][1]!=li[1][0][1]):
    print(n-li[0][0][0]-li[1][0][0])
elif(li[0][0][0]>li[1][0][0]):
    print(n-li[0][0][0]-li[1][1][0])
else:
    print(n-li[0][1][0]-li[1][0][0])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(x) for x in input().split()]
li1 = [0]*10**5
li2 = [0]*10**5
max1 = [0]*2
sec1 = [0]*2
max2 = [0]*2
sec2 = [0]*2
for index,i in enumerate(v):
    if(index%2==0):
        li1[i-1]+=1
        if(li1[i-1]>max1[0]):
            if(sec1[1]!=i-1):
                sec1[0]=max1[0]
                sec1[1]=max1[1]
            max1[0] = li1[i-1]
            max1[1] = i-1
        elif(li1[i-1]>sec1[0] and i-1!=sec1[1]):
            sec1[0] = li1[i-1]
            sec1[1] = i-1
    else:
        li2[i-1]+=1
        if(li2[i-1]>max2[0]):
            if(sec2[1]!=i-1):
                sec2[0]=max2[0]
                sec2[1]=max2[1]
            max2[0] = li2[i-1]
            max2[1] = i-1
        elif(li2[i-1]>sec2[0] and i-1!=sec2[1]):
            sec2[0] = li2[i-1]
            sec2[1] = i-1

if(max1[1]!=max2[1]):
    print(n-max1[0]-max2[0])
else:
    if(sec1>sec2):
        print(n-sec1[0]-max2[0])
    else:
        print(n-max1[0]-sec2[0])

Submission status: Wrong Answer

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

a = [0 for i in range(max(v)+1)]
b = [0 for i in range(max(v)+1)]

for i in range(n):
    if i%2==0:
        a[v[i]]+=1
    else:
        b[v[i]]+=1
maxa = a.index(max(a))
maxb = b.index(max(b))
if maxa != maxb:
    count = n - max(a) - max(b)
    print(count)
else:
    maxa_num = max(a)
    maxb_num = max(b)
    a[maxa] = 0
    b[maxb] = 0
    count1 = n - maxa_num - max(b)
    count2 = n - maxb_num - max(a)
    print(count1 if count1>=count2 else count2)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
even = v[0::2]
odd = v[1::2]
ce = collections.Counter(even)
oe = collections.Counter(odd)
if len(set(odd)) ==1 and len(set(even)) == 1:
    if ce.most_common()[0][0] != oe.most_common()[0][0]:
        print("0")
    else:
        print(int(n/2))
elif len(set(odd)) ==1 and len(set(even)) != 1:
#    ce = collections.Counter(even)
    print(int(n/2-ce.most_common()[0][1]))
elif len(set(odd)) !=1 and len(set(even)) == 1:
#    oe = collections.Counter(odd)
    print(int(n/2-oe.most_common()[0][1]))
else:
#    ce = collections.Counter(even)
#    oe = collections.Counter(odd)
    #print(ce.most_common()[0][1])
    #print(oe.most_common()[0][1])
    if ce.most_common()[0][0] != oe.most_common()[0][0]:
        print(int(n/2-ce.most_common()[0][1]-oe.most_common()[0][1]))
    else:
        print(n - max(ce.most_common()[1][1]+oe.most_common()[0][1], oe.most_common()[1][1]+ce.most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import collections 
n = int(input())
vls = [int(x) for x in input().split()]
number = set(vls)
countls = []
for i in number:
    ls1 = vls[::2]
    ls2 = vls[1::2]
    a = sum(1 for x in ls1 if x != i)
    u=collections.Counter(ls2)
    mostcommon = u.most_common()[0][1]
    b = n/2-mostcommon
    c = sum(1 for x in ls2 if x != i)
    v = collections.Counter(ls1)
    mostcommon = v.most_common()[0][1]
    d = n/2-mostcommon
    countls.append(a+b)
    countls.append(c+d)

print(int(min(countls)))

Submission status: Wrong Answer

Solution code:
import numpy as np
import collections
n = int(input())
a_n = np.array(input().split(),dtype='int')
diff = a_n[1:] - a_n[:-1]
if len(set(diff))==2:
    print(0)
elif len(set(diff))==1:
    print(int(n/2))
else:
    odd_th = collections.Counter(a_n[1::2]).most_common()
    eve_th = collections.Counter(a_n[0::2]).most_common()
    if odd_th[0][0]==eve_th[0][0]:
        if odd_th[0][1]>=eve_th[0][1]:
            odd_ = odd_th[0][1]
            eve_ = eve_th[1][1]
        else:
            odd_ = odd_th[1][1]
            eve_ = eve_th[0][1]
    else:
            odd_ = odd_th[0][1]
            eve_ = eve_th[0][1]
    print(n-odd_-eve_)

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
odd = {}
even = {}
for i, v in enumerate(V):
    if i % 2 == 0:
        odd.setdefault(v, 0)
        odd[v] += 1
    else:
        even.setdefault(v, 0)
        even[v] += 1
oddMaxK, oddMaxV, oddSmaxK, oddSmaxV, oddRes = 0, 0, 0, 0, 0
for k, v in sorted(odd.items(), key = lambda x:x[1], reverse=True):
    if oddMaxK == 0:
        oddMaxK, oddMaxV = k, v
    elif oddMaxK != 0 and oddSmaxK == 0:
        oddSmaxK, oddSmaxV = k, v
    else:
        oddRes += 1
evenMaxK, evenMaxV, evenSmaxK, evenSmaxV, evenRes = 0, 0, 0, 0, 0
for k, v in sorted(even.items(), key = lambda x:x[1], reverse=True):
    if evenMaxK == 0:
        evenMaxK, evenMaxV = k, v
    elif evenMaxK != 0 and evenSmaxK == 0:
        evenSmaxK, evenSmaxV = k, v
    else:
        evenRes += 1
if oddMaxK != evenMaxK:
    print(oddRes + oddSmaxV + evenRes + evenSmaxV)
else:
    if oddMaxV > evenMaxV:
        print(oddRes + oddSmaxV + evenRes + evenMaxV)
    else:
        print(oddRes + oddMaxV + evenRes + evenSmaxV)

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
odd = {}
even = {}
for i, v in enumerate(V):
    if i % 2 == 0:
        odd.setdefault(v, 0)
        odd[v] += 1
    else:
        even.setdefault(v, 0)
        even[v] += 1
oddMaxK, oddMaxV, oddSmaxK, oddSmaxV, oddRes = 0, 0, 0, 0, 0
for k, v in sorted(odd.items(), key = lambda x:x[1], reverse=True):
    if oddMaxK == 0:
        oddMaxK, oddMaxV = k, v
    elif oddMaxK != 0 and oddSmaxK == 0:
        oddSmaxK, oddSmaxV = k, v
    else:
        oddRes += 1

evenMaxK, evenMaxV, evenSmaxK, evenSmaxV, evenRes = 0, 0, 0, 0, 0
for k, v in sorted(even.items(), key = lambda x:x[1], reverse=True):
    if evenMaxK == 0:
        evenMaxK, evenMaxV = k, v
    elif evenMaxK != 0 and evenSmaxK == 0:
        oddSmaxK, oddSmaxV = k, v
    else:
        evenRes += 1
if oddMaxK != evenMaxK:
    print(oddRes + oddSmaxV + evenRes + evenSmaxV)
else:
    if oddMaxV > evenMaxV:
        print(oddRes + oddSmaxV + evenRes + evenMaxV)
    else:
        print(oddRes + oddMaxV + evenRes + evenSmaxV)

Submission status: Wrong Answer

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


def get_word_num(Ss):
    hists = {}
    for v in Ss:
        if v in hists.keys():
            hists[v] += 1
        else:
            hists[v] = 1

    return sorted(hists.items(),reverse = True)


even_ar = Vs[0::2]
odd_ar = Vs[1::2]

even_hist = get_word_num(even_ar)
odd_hist = get_word_num(odd_ar)

if even_hist[0][0] != odd_hist[0][0]:
    print(N - even_hist[0][1] - odd_hist[0][1])
else:
    if len(even_hist) == 1 and len(odd_hist) == 1:
        print(len(even_ar))
    else:
        print(N - max(even_hist[0][1] + odd_hist[1][1], even_hist[1][1] + odd_hist[0][1]))

Submission status: Wrong Answer

Solution code:
N = int(input().strip())

Vs = list(map(int,input().strip().split()))


def get_word_num(Ss):
    hists = {}
    for v in Ss:
        if v in hists.keys():
            hists[v] += 1
        else:
            hists[v] = 1

    return sorted(hists.items(),reverse = True)


even_ar = Vs[0::2]
odd_ar = Vs[1::2]

even_hist = get_word_num(even_ar)
odd_hist = get_word_num(odd_ar)

if even_hist[0][0] != odd_hist[0][0]:
    print(len(even_ar) - even_hist[0][1] + len(odd_ar) - odd_hist[0][1])
else:
    if len(even_hist) == 1 and len(odd_hist) == 1:
        print(len(even_ar))
    else:
        print(min(len(even_ar) - even_hist[0][1] + len(odd_ar) - odd_hist[1][1], len(even_ar) - even_hist[1][1] + len(odd_ar) - odd_hist[0][1]))

Submission status: Wrong Answer

Solution code:
import math

N = int(input().strip())

Vs = list(map(int,input().strip().split()))


def get_word_num(Ss):
    hists = {}
    for v in Ss:
        if v in hists.keys():
            hists[v] += 1
        else:
            hists[v] = 1

    return sorted(hists.items(),reverse = True)

even_ar = Vs[0::2]
odd_ar = Vs[1::2]

even_hist = get_word_num(even_ar)
odd_hist = get_word_num(odd_ar)

if even_hist[0][0] == odd_hist[0][0] and len(even_hist) == 1 and len(odd_hist) == 1:
    print(len(even_ar))
    exit()

if even_hist[0][0] == odd_hist[0][0]:
    print(min(len(even_ar) - even_hist[0][1] + len(odd_ar) - odd_hist[1][1], len(even_ar) - even_hist[1][1] + len(odd_ar) - odd_hist[0][1]))
    exit()

print(len(even_ar) - even_hist[0][1] + len(odd_ar) - odd_hist[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

O = Counter(S[::2])
E = Counter(S[1::2])

of = []
ef = []
for i in O.items():
	of.append([i[1],i[0]])
for i in E.items():
	ef.append([i[1],i[0]])

of.sort()
ef.sort()

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

Submission status: Wrong Answer

Solution code:
import math

N = int(input().strip())

Vs = list(map(int,input().strip().split()))

hists = {}
for v in Vs:
    if v in hists.keys():
        hists[v] += 1
    else:
        hists[v] = 1

hists_l = sorted(hists.items(),reverse = True)

res = 0
if hists_l[0][1] > math.floor(len(Vs) / 2):
    res += hists_l[0][1] - math.floor(len(Vs) / 2)
if len(hists_l) > 1 and hists_l[1][1] > math.floor(len(Vs) / 2):
    res += hists_l[1][1] - math.floor(len(Vs) / 2)
if len(hists_l) >= 3:
    for h in hists_l[2:]:
        res += h[1]


print(res)

Submission status: Wrong Answer

Solution code:
import math

N = int(input().strip())

Vs = list(map(int,input().strip().split()))

hists = {}
for v in Vs:
    if v in hists.keys():
        hists[v] += 1
    else:
        hists[v] = 1

hists_l = sorted(hists.items(),reverse = True)

res = 0
if len(hists_l) <= 1:
    res += math.floor(len(Vs) / 2)
elif len(hists_l) >= 3:
    for h in hists_l[2:]:
        res += h[1]


print(res)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
e_list = []
o_list = []
if n > 1:
    b_list = [int(i) for i in input().split()]
    for i in range(n):
        if i % 2 == 0:
            o_list.append(b_list[i])
        else:
            e_list.append(b_list[i])
    c_o = collections.Counter(o_list)
    c_e = collections.Counter(e_list)
    if (len(c_o) == 1) & (len(c_e) == 1):
        if o_list[0] == e_list[0]:
            print(len(o_list))
        else:
            print(0)
    else:
        ans = sum(c_o.values()) - max(c_o.values())
        ans += sum(c_e.values()) - max(c_e.values())
        print(ans)
else:
    a = int(input())
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
e_list = []
o_list = []
b_list = [int(i) for i in input().split()]
for i in range(n):
    if i % 2 == 0:
        o_list.append(b_list[i])
    else:
        e_list.append(b_list[i])
c_o = collections.Counter(o_list)
c_e = collections.Counter(e_list)
if (len(c_o) == 1) & (len(c_e) == 1):
    if o_list[0] == e_list[0]:
        print(len(o_list))
    else:
        print(0)
else:
    ans = sum(c_o.values()) - max(c_o.values())
    ans += sum(c_e.values()) - max(c_e.values())
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = [int(_) for _ in input().split()]
v1 = v[::2]
v2 = v[1::2]

if v1 == v2:
    print(len(v1))
else:
    cv1 = Counter(v1)
    cv2 = Counter(v2)
    if cv1.most_common()[0][0] != cv2.most_common()[0][0]:
        ch1 = len(v1) - cv1.most_common()[0][1]
        ch2 = len(v2) - cv2.most_common()[0][1]
    else:
        if cv1.most_common()[0][1] > cv2.most_common()[0][1]:
            ch1 = len(v1) - cv1.most_common()[0][1]
            ch2 = len(v2) - cv2.most_common()[1][1]
        else:
            ch1 = len(v1) - cv1.most_common()[1][1]
            ch2 = len(v2) - cv2.most_common()[0][1]
    print(ch1 + ch2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = [int(_) for _ in input().split()]
v1 = v[::2]
v2 = v[1::2]

if v1 == v2:
    print(len(v1))
else:
    cv1 = Counter(v1)
    cv2 = Counter(v2)
    if cv1.most_common()[0][0] != cv2.most_common()[0][0]:
        ch1 = len(v1) - cv1.most_common()[0][1]
        ch2 = len(v2) - cv2.most_common()[0][1]
    else:
        if cv1.most_common()[0][1] > cv2.most_common()[0][1]:
            ch1 = len(v1) - cv1.most_common()[0][1]
            ch2 = len(v2) - cv2.most_common()[1][1]
        else:
            ch1 = len(v1) - cv1.most_common()[1][1]
            ch2 = len(v2) - cv2.most_common()[0][1]
            print(ch1 + ch2)

Submission status: Wrong Answer

Solution code:
import bisect

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

a = sorted(v[::2])
b = sorted(v[1::2])	

def get_frequent_num(a):
  a_max = 0
  a_max_num = 0
  i=0
  prev_i = 0
  max_value, sec_value = 0, 0
  max_num, sec_num = 0, 0
  while i < len(a):
      i = bisect.bisect(a, a[i])
      num = (i - prev_i)
      if num > max_num:
        sec_num = max_num
        max_num = num
        sev_value = max_value
        max_value = a[i-1]
      elif num > sec_num:
        sec_num = num
        sec_value = a[i-1]
      prev_i = i
  return max_num, max_value, sec_num, sec_value

amn, amv, asn, asv = get_frequent_num(a)
bmn, bmv, bsn, bsv = get_frequent_num(b)

if amv != bmv:
  print(n-amn-bmn)
elif amv == bmv:
  if amn == asn or bmn == bsn:
    print(n-amn-bmn)
  elif asn < bsn:
    print(n-asn-bmn)
  else:
    print(n-amn-bsn)

Submission status: Wrong Answer

Solution code:
import bisect

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

a = sorted(v[::2])
b = sorted(v[1::2])	

def get_frequent_num(a):
  a_max = 0
  a_max_num = 0
  i=0
  prev_i = 0
  max_value, sec_value = 0, 0
  max_num, sec_num = 0, 0
  while i < len(a):
      i = bisect.bisect(a, a[i])
      num = (i - prev_i)
      if num > max_num:
        sec_num = max_num
        max_num = num
        sev_value = max_value
        max_value = a[i-1]
      elif num > sec_num:
        sec_num = num
        sec_value = a[i-1]
      prev_i = i
  return max_num, max_value, sec_num, sec_value

amn, amv, asn, asv = get_frequent_num(a)
bmn, bmv, bsn, bsv = get_frequent_num(b)

if amv != bmv:
  print(n-amn-bmn)
elif amv == bmv:
  if asn < bsn:
    print(n-asn-bmn)
  else:
    print(n-amn-bsn)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

li_ki = li_input[0::2]
d_ki = defaultdict(int)
for ki in li_ki:
    d_ki[ki] += 1


li_gu = li_input[1::2]
d_gu = defaultdict(int)
for gu in li_gu:
    d_gu[gu] += 1

ki_sort = sorted([(k, v) for k,v in d_ki.items()], key=lambda x : x[1], reverse=True)
gu_sort = sorted([(k, v) for k,v in d_gu.items()], key=lambda x : x[1], reverse=True)

ki_cnt = 0
gu_cnt = 0

if ki_sort[0][1] >= gu_sort[0][1]:
    ki_cnt = ki_sort[0][1]
    for g in gu_sort:
        if ki_sort[0][0] != g[0]:
            gu_cnt = g[1]
            break
else:
    gu_cnt = gu_sort[0][1]
    for k in ki_sort:
        if gu_sort[0][0] != k[0]:
            ki_cnt = k[1]
            break

print(n - ki_cnt - gu_cnt)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

li_ki = li_input[0::2]
d_ki = defaultdict(int)
for ki in li_ki:
    d_ki[ki] += 1


li_gu = li_input[1::2]
d_gu = defaultdict(int)
for gu in li_gu:
    d_gu[gu] += 1

max_ki_count = max([d for d in d_ki.values()])
max_gu_count = max([d for d in d_gu.values()])

print(n - max_ki_count - max_gu_count)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

c = Counter(V)
c = c.most_common()
if len(c) == 1:
    print(n // 2)
    quit()

e1, e2 = c[0][0], c[1][0]
ans1, ans2 = 0, 0
for i in range(n):
    if i % 2 == 0:
        if V[i] != e1:
            ans1 += 1
    elif i % 2 == 1:
        if V[i] != e2:
            ans1 += 1

for i in range(n):
    if i % 2 == 0:
        if V[i] != e2:
            ans2 += 1
    elif i % 2 == 1:
        if V[i] != e1:
            ans2 += 1

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

c = Counter(V)
c = c.most_common()
if len(c) == 1:
    print(n // 2)
    quit()

e1, e2 = c[0][0], c[1][0]
ans1, ans2 = 0, 0
for i in range(n):
    if i % 2 == 0:
        if V[i] != e1:
            ans1 += 1
    else:
        if V[i] != e2:
            ans1 += 1

for i in range(n):
    if i % 2 == 0:
        if V[i] != e2:
            ans2 += 1
    else:
        if V[i] != e1:
            ans2 += 1

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
import collections


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

c = collections.Counter(V)
c = c.most_common()
if len(c) == 1:
    print(n // 2)
    quit()

e1, e2 = c[0][0], c[1][0]
ans1, ans2 = 0, 0
for i in range(n):
    if i % 2 == 0:
        if V[i] != e1:
            ans1 += 1
    else:
        if V[i] != e2:
            ans1 += 1

for i in range(n):
    if i % 2 == 0:
        if V[i] != e2:
            ans2 += 1
    else:
        if V[i] != e1:
            ans2 += 1

print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
a = [v[i] for i in range(n) if i%2==0]
b = [v[i] for i in range(n) if i%2==1]

x = 0
y = 0
p=0
q=0

for i in range(10**5):
    if x<a.count(i):
        p=i
        x=a.count(i)
    if y<b.count(i):
        q=i
        y=b.count(i)

print(n-x-y)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
a = [v[i] for i in range(n) if i%2==0]
b = [v[i] for i in range(n) if i%2==1]

x = 0
y = 0
p=0
q=0

for i in range(10**5):
    if x<a.count(i):
        p=i
        x=a.count(i)
    if y<b.count(i):
        q=i
        y=b.count(i)

if p>q or q<p:
    print(n-x-y)
else:
    a = [i for i in a if i>p or i<p]
    b = [i for i in b if i>q or i<q]
    z = 0
    w = 0
    for i in range(10**5):
        z = max(z,a.count(i))
        w = max(w,b.count(i))
    print(n-max(x+w,y+z))

Submission status: Wrong Answer

Solution code:
import statistics as st
n=int(input())
us=input().split()#4 0,1,2,3/ 5 0,1,2,3,4
need=0
ux=[];uy=[]#ux=[1,3] uy=[2,4]
if (n%2)==0:#nは偶数
    for i in range(int(n/2)):#0,1
        ux.append(us[i*2])
    for j in range(int(n/2)):#0,1
        uy.append(us[j*2+1])
else:#nは奇数
    for i in range(int((n+1)/2)):#0,1,2
        ux.append(us[i*2])
    for j in range(int((n-1)/2)):#0,1
        uy.append(us[j*2+1])
try:
    stx=st.mode(ux)
except:
    stx=ux[0]
try:
    sty=st.mode(uy)
except:
    sty=uy[0]
#10/0,0,0,1,1 /0,1,1,1,1
if int(stx)==int(sty):
    need+=min(ux.count(stx)+uy.count(stx),ux.count(sty)+uy.count(sty))
else:
    need+=len(ux)-ux.count(stx)+len(uy)-uy.count(sty)
print(str(need))