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:
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]
need+=len(ux)-ux.count(stx)
if int(stx)==int(sty):
    need+=uy.count(sty)
else:
    need+=len(uy)-uy.count(sty)
print(str(need))

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
us=input().split()#str
u=[]
need=0
for i in us:
    u.append(int(i))
if (n/2).is_integer():#nは偶数
    xs=[];ys=[]
    for j in range(int(n/2)):
        xs.append(u[j*2])
        ys.append(u[j*2+1])
    x=collections.Counter(xs)
    all=[]
    for k in x.keys():
        all.append(x[k])
    if len(all)!=1:
        need+=min(all)
    all2=[]
    y=collections.Counter(ys)
    for k in y.keys():
        all2.append(y[k])
    if len(all2)!=1:
        need+=min(all2)
else:#nは奇数
    for j in range(int((n+1)/2)):
        xs.append(j*2)
    for k in range(int((n-1)/2)):
        ys.append(j*2+1)
    x=collections.Counter(xs)
    all=[]
    for k in x.keys():
        all.append(x[k])
    if len(all)!=1:
        need+=min(all)
    all2=[]
    y=collections.Counter(ys)
    for k in y.keys():
        all2.append(y[k])
    if len(all2)!=1:
        need+=min(all2)
print(str(need))

Submission status: Wrong Answer

Solution code:
import collections
def func(v1,v2):
    ans=0
    c1=dict(collections.Counter(v1))
    c1_val=list(c1.values())
    c1=list(c1.items())
    
    c2=dict(collections.Counter(v2))
    c2_val=list(c2.values())
    c2=list(c2.items())
    if len(c1)==1:
        pass
    else:
        ans+=sum(c1_val[1:])
    if c1[0][0]==c2[0][0]:
        ans+=c2_val[0]+sum(c2_val[2:])
    else:
        ans+=sum(c2_val[1:])
    return ans
n=int(input())
v=list(map(int,input().split()))
v1,v2=v[::2],v[1::2]
if len(set(v1))<len(set(v2)):
    print(func(v1,v2))
elif set(v1)==set(v2) and len(v1)==1:
    print(len(v1))
else:
    print(func(v2,v1))

Submission status: Wrong Answer

Solution code:
import collections
def func(v1,v2):
    ans=0
    c1=dict(collections.Counter(v1))
    c1_val=list(c1.values())
    c1=list(c1.items())
    
    c2=dict(collections.Counter(v2))
    c2_val=list(c2.values())
    c2=list(c2.items())
    if len(c1)==1:
        pass
    else:
        ans+=sum(c1_val[1:])
    if c1[0][0]==c2[0][0]:
        ans+=c2_val[0]+sum(c2_val[2:])
    else:
        ans+=sum(c2_val[1:])
    return ans
n=int(input())
v=list(map(int,input().split()))
v1,v2=v[::2],v[1::2]
if set(v1)<set(v2):
    print(func(v1,v2))
elif set(v1)>set(v2):
    print(func(v2,v1))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
v=[v[::2],v[1::2]]
ans=0
for i in v:
    if len(set(i))==1:
        continue
    else:
        c=collections.Counter(i)
        
        c=list(c.values())
        c.sort(reverse=True)
        ans+=sum(c[1:])
if v[0]==v[1]:
    print(len(v[1]))
else:
    print(ans)

Submission status: Wrong Answer

Solution code:

# Your code here!
import collections
n=int(input())
a=input().split(" ")
a_c=collections.Counter(a)
a_m=a_c.most_common()
ans=n-a_m[0][1]
if(len(a_m)>=2):
    ans-=a_m[1][1]
if(n==a_m[0][1]):
    ans+=n/2
print(round(ans))

Submission status: Wrong Answer

Solution code:
#Miccさんのコードを参考にさせていただきました
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
e = v[1::2] #偶数番号
o = v[0::2] #奇数番号
ans = 0

a = Counter(e) #Counterオブジェクトを作成(dictのサブクラスでキーに要素、値に出現回数をもつ)
b = Counter(o)

c = a.most_common(2) #出現回数が2番目に多い数までのCounterオブジェクト作成
d = b.most_common(2)

if c[0][0] != d[0][0]: #出現回数が１番多いものが違う時
    ans = n -c[0][1] -d[0][1]
else:                  #出現回数が１番多いものが同じ時
    if len(c) == 1:
        if len(d) == 1:
            ans = n//2
        else:
            ans = n -d[0][1]
    elif len(d) == 1 and len(c) != 1:
        ans = n -c[0][1]
    elif c[0][1] > d[0][1]:
        ans = n -c[0][1] -d[1][1]
    else:
        ans = n -c[1][1] -d[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
#Miccさんのコードを参考にさせていただきました
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
e = v[1::2] #偶数番号
o = v[0::2] #奇数番号
ans = 0

a = Counter(e) #Counterオブジェクトを作成(dictのサブクラスでキーに要素、値に出現回数をもつ)
b = Counter(o)

c = a.most_common(2) #出現回数が2番目に多い数までのCounterオブジェクト作成
d = b.most_common(2)

if c[0][0] != d[0][0]: #出現回数が１番多いものが違う時
    ans = n -c[0][1] -d[0][1]
else:                  #出現回数が１番多いものが同じ時
    if len(c) == 1:
        if len(d) == 1:
            ans = n//2
        else:
            ans = n -d[0][1]
    elif len(d) == 1 and len(c) != 1:
        ans = n -c[0][1]
    else:
        s = n - c[0][1] -d[1][0]
        t = n - c[1][0] -d[0][0]
        ans = min(s,t)

print(ans)

Submission status: Wrong Answer

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

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][1] > sorted_odd[0][1]:
        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: Wrong Answer

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

type_number = 0
for i in range(0, int(1e5 + 1)):
    if odd[i][0] + even[i][0] > 0:
        type_number += 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][1] > sorted_odd[0][1]:
        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

if type_number == 1:
    print(N // 2)
else:
    print(count)

Submission status: Wrong Answer

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=len(e)-c[0][1]+len(o)-d[0][1]
else:#同じ→どちらかは2番目の方に揃える
    if len(c)==1:#偶数列が1種類の数から
        if len(d)==1:
            ans=n//2
        else:
            ans=len(d)-d[1][1]
    if len(d)==1:#奇数列が1種類の数から
        if len(c)==1:
            ans=n//2
        else:
            ans=len(c)-c[1][1]
print(ans)

Submission status: Wrong Answer

Solution code:

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

odd = [0] * int(1e5 + 1)
even = [0] * int(1e5 + 1)

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

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

max_even = max(even)
max_odd = max(odd)

count = 0
count += N // 2 - max_even
count += N // 2 - max_odd

if type_number == 1:
    print(N // 2)
else:
    print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[a[2*i] for i in range(int(n/2))]
c=[a[2*i-1] for i in range(1,int(n/2)+1)]
print(b)
print(c)
d=[b.count(i) for i in list(set(b))]
e=[c.count(i) for i in list(set(c))]
if list(set(b))[d.index(max(d))] != list(set(c))[e.index(max(e))]:
    print(n-max(d)-max(e))
else:
    f=max(d)
    g=max(e)
    del list(set(b))[d.index(max(d))]
    del list(set(c))[e.index(max(e))]
    d.remove(f)
    e.remove(g)
    if len(d)==0:
        h=0
    else:
        h=max(d)
    if len(e)==0:
        i=0
    else:
        i=max(e)
    print(n-max(f+i,g+h))

Submission status: Wrong Answer

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
    
    #最頻値の比較
    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) < 0:
        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: Wrong Answer

Solution code:
l1=[]
l2=[]
n=int(input())
l0=list(map(int,input().split()))
n=0
for x in l0:
  if n%2==0:
    l1.append(x)
  else:
    l2.append(x)
  n+=1
l1.sort()
l2.sort()
setl1=list(set(l1))
setl2=list(set(l2))
a=setl1[0]
b=setl2[0]
a_c=0
a_c_max=[0,0]
maxa=maxb=0
b=setl2[0]
b_c=0
b_c_max=[0,0]
for x in l1:
  if a!=x:
    if a_c_max[0]<a_c:
      a_c_max[1]=a_c_max[0]
      a_c_max[0]=a_c
      maxa=a
    a=x
    a_c=1
  else:
    a_c+=1
if a_c_max[0]<a_c:
  a_c_max[1]=a_c_max[0]
  a_c_max[0]=a_c
  maxa=a
for x in l2:
  if b!=x:
    if b_c_max[0]<b_c:
      b_c_max[1]=b_c_max[0]
      b_c_max[0]=b_c
      maxb=b
    b=x
    b_c=1
  else:
    b_c+=1
if b_c_max[0]<b_c:
  b_c_max[1]=b_c_max[0]
  b_c_max[0]=b_c
  maxb=b
if a_c_max[1]==0:
  a_c_max[1]=1
if b_c_max[1]==0:
  b_c_max[1]=1
if maxa!=maxb:
  print(n-(a_c_max[0]+b_c_max[0]))
else:
  print(min(n-(a_c_max[0]+b_c_max[1]),
    n-(a_c_max[1]+b_c_max[0])))

Submission status: Wrong Answer

Solution code:
l1=[]
l2=[]
n=int(input())
l0=list(map(int,input().split()))
n=0
for x in l0:
  if n%2==0:
    l1.append(x)
  else:
    l2.append(x)
  n+=1
l1.sort()
l2.sort()
setl1=list(set(l1))
setl2=list(set(l2))
a=setl1[0]
b=setl2[0]
a_c=0
a_c_max=[0,0]
maxa=maxb=0
b=setl2[0]
b_c=0
b_c_max=[0,0]
for x in l1:
  if a!=x:
    if a_c_max[0]<a_c:
      a_c_max[1]=a_c_max[0]
      a_c_max[0]=a_c
      maxa=a
    a=x
    a_c=1
  else:
    a_c+=1
if a_c_max[0]<a_c:
  a_c_max[1]=a_c_max[0]
  a_c_max[0]=a_c
  maxa=a
for x in l2:
  if b!=x:
    if b_c_max[0]<b_c:
      b_c_max[1]=b_c_max[0]
      b_c_max[0]=b_c
      maxb=b
    b=x
    b_c=1
  else:
    b_c+=1
if b_c_max[0]<b_c:
  b_c_max[1]=b_c_max[0]
  b_c_max[0]=b_c
  maxb=b
if a!=b:
  print(n-(a_c_max[0]+b_c_max[0]))
else:
  print(min(n-(a_c_max[0]+b_c_max[1]),
    n-(a_c_max[1]+b_c_max[0])))

Submission status: Wrong Answer

Solution code:
l1=[]
l2=[]
n=int(input())
l0=list(map(int,input().split()))
n=0
for x in l0:
  if n%2==0:
    l1.append(x)
  else:
    l2.append(x)
  n+=1
l1.sort()
l2.sort()
setl1=list(set(l1))
setl2=list(set(l2))
a=setl1[0]
b=setl2[0]
a_c=0
a_c_max=[0,0]
maxa=maxb=0
b=setl2[0]
b_c=0
b_c_max=[0,0]
for x in l1:
  if a!=x:
    if a_c_max[0]<a_c:
      a_c_max[1]=a_c_max[0]
      a_c_max[0]=a_c
      maxa=a
    a=x
    a_c=0
  else:
    a_c+=1
if a_c_max[0]<a_c:
  a_c_max[1]=a_c_max[0]
  a_c_max[0]=a_c
  maxa=a
for x in l2:
  if b!=x:
    if b_c_max[0]<b_c:
      b_c_max[1]=b_c_max[0]
      b_c_max[0]=b_c
      maxb=b
    b=x
    b_c=0
  else:
    b_c+=1
if b_c_max[0]<b_c:
  b_c_max[1]=b_c_max[0]
  b_c_max[0]=b_c
  maxb=b
if a!=b:
  print(n-(a_c_max[0]+b_c_max[0]))
else:
  print(min(n-(a_c_max[0]+b_c_max[1]),
    n-(a_c_max[1]+b_c_max[0])))

Submission status: Wrong Answer

Solution code:
l1=[]
l2=[]
n=int(input())
l0=list(map(int,input().split()))
n=0
for x in l0:
  if n%2==0:
    l1.append(x)
  else:
    l2.append(x)
  n+=1
l1.sort()
l2.sort()
setl1=list(set(l1))
setl2=list(set(l2))
a=setl1[0]
b=setl2[0]
a_c=0
a_c_max=[0,0]
maxa=maxb=0
b=setl2[0]
b_c=0
b_c_max=[0,0]
for x in l1:
  if a!=x:
    if a_c_max[0]<a_c:
      a_c_max[1]=a_c_max[0]
      a_c_max[0]=a_c
      maxa=a
    a=x
    a_c=0
  else:
    a_c+=1
if a_c_max[0]<a_c:
  a_c_max[1]=a_c_max[0]
  a_c_max[0]=a_c
  maxa=a
for x in l2:
  if b!=x:
    if b_c_max[0]<b_c:
      b_c_max[1]=b_c_max[0]
      b_c_max[0]=b_c
      maxb=b
    b=x
    b_c=0
  else:
    b_c+=1
if b_c_max[0]<b_c:
  b_c_max[1]=b_c_max[0]
  b_c_max[0]=b_c
  maxb=b
if a!=b:
  print(n-(a_c_max[0]+b_c_max[0]))
else:
  print(max(n-(a_c_max[0]+b_c_max[1]),
    n-(a_c_max[1]+b_c_max[0])))

Submission status: Wrong Answer

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_ap = counter.most_common()[0][0]
    l = len(list)
    cnt = 0
    for i in range(l):
        if list[i] != m_ap:
            cnt += 1
    return cnt, m_ap
cnta, m_a = change(a)
cntb, m_b = change(b)
ans = cnta + cntb
if ans or m_a!=m_b:
    print(ans)
else:
    print(n//2)

Submission status: Wrong Answer

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_ap = counter.most_common()[0][0]
    l = len(list)
    cnt = 0
    for i in range(l):
        if list[i] != m_ap:
            cnt += 1
    return cnt
ans = change(a) + change(b)
if ans or a!=b:
    print(ans)
else:
    print(n//2)

Submission status: Wrong Answer

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]
print(s)
s = [(d + [(0, 0)])[:2] for d in s]
keep = 0
for e, o in product(*s):
    print(e, o)
    if e[0] == o[0]:
        continue
    tmp = e[1] + o[1]
    if tmp > keep:
        keep = tmp
ans = n - keep
print(ans)

Submission status: Wrong Answer

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

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

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) >= max(p2):
		pp1 = p1.index(max(p1))
		if len(p2) == 1:
			pp2 = pp1 + 1
		else:
			pp2 = p2.index(sorted(p2)[-2])
	else:
		pp2 = p2.index(max(p2))
		if len(p1) == 1:
			pp1 = pp2 + 1
		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: Wrong Answer

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)
    # print(kisuu)
    # print('len: ', len(guusuu), ', ', len(kisuu))
    if guusuu[0][0]==kisuu[0][0]:
        if len(guusuu)==1 and len(kisuu)==1:
            print(len(ki))
        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: Wrong Answer

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)
    # print(kisuu)
    # print('len: ', len(guusuu), ', ', len(kisuu))
    if guusuu[0][0]==kisuu[0][0]:
        if len(guusuu)==1 and len(kisuu)==1:
            print(len(gu))
        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: Wrong Answer

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)
    print(kisuu)
    print('len: ', len(guusuu), ', ', len(kisuu))
    if guusuu[0][0]==kisuu[0][0]:
        if len(guusuu)==1 and len(kisuu)==1:
            print(len(gu))
        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: Wrong Answer

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) >= max(p2):
		pp1 = p1.index(max(p1))
		pp2 = p2.index(sorted(p2)[-2])
	elif max(p2) > max(p1):
		pp1 = p1.index(sorted(p1)[-2])
		pp2 = p2.index(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

print(cnt1 + cnt2)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

    guusuu = guusuu.most_common()
    kisuu = kisuu.most_common()


    if guusuu[0][0]==kisuu[0][0]:
        if len(guusuu)==1 and len(kisuu)==1:
            print(len(guusuu))
        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: Wrong Answer

Solution code:
from collections import Counter


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

    guusuu = guusuu.most_common()
    kisuu = kisuu.most_common()


    if guusuu[0][0]==kisuu[0][0]:
        if len(guusuu)==1 and len(kisuu)==1:
            print(guusuu)
        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: Wrong Answer

Solution code:
from collections import Counter


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

    guusuu = guusuu.most_common()
    kisuu = kisuu.most_common()

    if len(set(guusuu)) == 1:
        # 偶数番目１種類
        print(n//2 - kisuu[0][1])
    elif len(set(kisuu)) == 1:
        # 奇数番目１種類
        print(n//2 - guusuu[0][1])
    # ２種類以上
    elif guusuu[0][0] == kisuu[0][0]:
        # 最頻値が同じ時，どちらがは譲らないといけない
        # => ２番目の最頻値で書き換えるべき
        result = min(n - guusuu[0][1] - kisuu[1][1], n- guusuu[1][1] - kisuu[0][1])
        print(result)
    else:
        # 最頻値が違う時，どちらも最頻値で書き換え
        print(n - guusuu[0][1] - kisuu[0][1])
    





main()

Submission status: Wrong Answer

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

p1 = lst[0]
p2 = lst[1]
new_lst = []
for idx in range(n):
	if idx%2 == 0:
  		new_lst.append(p1)
	else:
		new_lst.append(p2)

cnt = 0
for o, l in zip(lst, new_lst):
	if not o == l:
		cnt +=1

if p1 == p2:
  print(int(n/2))
else:
  print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

    a_n = a_n.most_common()
    a_n2 = a_n2.most_common()


    # print(a_n)
    # print(a_n2)

    max_a_n = a_n[0][1]
    max_a_n2 = a_n2[0][1]

    # print(max_a_n)
    # print(max_a_n2)


    print(n - max_a_n - max_a_n2)




main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    v_n = input().split(' ')

    
    
    a_n = Counter(v_n[::2])
    a_n2 = Counter(v_n[1::2])


    # print(a_n)
    # print(a_n2)

    a_n = a_n.most_common()
    a_n2 = a_n2.most_common()



    # print(a_n)
    # print(a_n2)

    max_an = a_n[0][1]
    max_an2 = a_n2[0][1]

    # print(max_an)
    # print(max_an2)

    if len(set(a_n)) == 1:
      print(n/2 - 1)
    elif len(set(a_n2)) == 1:
      print(n/2 - 1)




main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v_n = input().split(' ')


    result = 0
    for i in range(len(v_n)-2):
        a_n = int(v_n[i])
        a_n2 = int(v_n[i+2])

        if not (a_n - a_n2) == 0:
            result += 1

    num = set(v_n)
    if len(num) != 1:
        print(result)
    else:
        print(len(v_n)//2)



main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
def ans(l):
    max = 0
    b = set(l)
    if len(b)==1:
        return 0
    else:
        c = Counter(l)
        return int(n/2) - c.most_common(1)[0][1]
if len(set(a)) == 1:
    p = int(n/2)
else:
    p = ans(a[::2]) + ans(a[1::2])
print(p)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
def ans(l):
    max = 0
    b = set(l)
    if len(b)==1:
        return 0
    else:
        c = Counter(l)
        return n/2 - c.most_common()[0][1]
if n == 2:
    p = 0
else:
    if len(set(a)) == 1:
        p = int(n/2)
    else:
        p = int(ans(a[::2]) + ans(a[1::2]))
print(p)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
def ans(l):
    max = 0
    b = set(l)
    if len(b)==1:
        return 0
    else:
        c = Counter(l)
        return n/2 - c.most_common()[0][1]
if len(set(a)) == 1:
    p = int(n/2)
else:
    p = int(ans(a[::2]) + ans(a[1::2]))
print(p)

Submission status: Wrong Answer

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]
	else:
		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:
		count1 =  len(lst1) - dict1.most_common()[0][1]
		count2 =  len(lst2) - dict2.most_common()[0][1]

print(count1 + count2)

Submission status: Wrong Answer

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]
	else:
		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()[0][1]

print(count1 + count2)

Submission status: Wrong Answer

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:
        v1 = N - l1[0][1] - l2[1][1]
    print(min(v1, v2))

Submission status: Wrong Answer

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 len(l1) == 1 and len(l2) == 1 and l1[0][0] == l2[0][0]:
    print(N // 2)
elif l1[0][0] != l2[0][0]:
    print(N - l1[0][1] - l2[0][1])
elif l1[0][1] >= l2[1][1]:
    print(N - l1[0][1] - l2[1][1])
else:
    print(N - l1[1][1] - l2[0][1])

Submission status: Wrong Answer

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 len(l1) == 1 and len(l2) == 1:
    print(N // 2)
elif l1[0][0] != l2[0][0]:
    print(N - l1[0][1] - l2[0][1])
elif l1[0][1] >= l2[1][1]:
    print(N - l1[0][1] - l2[1][1])
else:
    print(N - l1[1][1] - l2[0][1])

Submission status: Wrong Answer

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
    return di

d1 = calc(0)
d2 = calc(1)

min_v = 10000000000
for k1 in d1.keys():
    for k2 in d2.keys():
        if k1 == k2:
            continue
        v = N - d1[k1] - d2[k2]
        if v < min_v:
            v = min_v
if min_v == 10000000000:
    print(N // 2)
else:
    print(min_v)

Submission status: Wrong Answer

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
    max_count = 0
    for k in di.keys():
        v = di[k]
        if v > max_count:
            max_count = v
    total = 0
    n = set()
    for k in di.keys():
        v = di[k]
        if v == max_count:
            n.add(k)
        total += v
    total -= max_count
    return [n, total]

n1, r1 = calc(0)
n2, r2 = calc(1)

n3 = n1 - n2

if len(n3) == 0:
    print(N // 2)
else:
    print(r1 + r2)

Submission status: Wrong Answer

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
    n1 = 0
    max_count = 0
    for k in di.keys():
        v = di[k]
        if v > max_count:
            max_count = v
            n1 = k
    remain = 0
    for k in di.keys():
        if k != n1:
            v = di[k]
            remain += v
    return [n1, remain]

n1, r1 = calc(0)
n2, r2 = calc(1)

if n1 == n2:
    print(N // 2)
else:
    print(r1 + r2)