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 collections


def solve():

    n = int(input())
    v = list(map(int, input().split()))
    v0 = v[::2]
    v0_counter = collections.Counter(v0)
    v0_value = v0_counter.most_common()[0][0]
    v1 = v[1::2]
    v1_counter = collections.Counter(v1)
    v1_value = v1_counter.most_common()[0][0]

    if v.count(v0_value) == n:
        print(n//2)
        exit()
    if v0_value == v1_value:
        if v0_counter.most_common()[1][1] >= v1_counter.most_common()[1][1]:
            v0_value == v0_counter.most_common()[1][0]
        else:
            v1_value == v1_counter.most_common()[1][0]

    print(len([x for x in v0 if x != v0_value]) + len([x for x in v1 if x != v1_value]))



if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import collections


def solve():

    n = int(input())
    v = list(map(int, input().split()))
    v0 = v[::2]
    v0_counter = collections.Counter(v0)
    v0_value = v0_counter.most_common()[0][0]
    v1 = v[1::2]
    v1_counter = collections.Counter(v1)
    v1_value = v1_counter.most_common()[0][0]

    if v.count(v0_value) == n:
        print(n//2)
        exit()
    if v0_value == v1_value:
        if v0_counter.most_common()[1][1] > v1_counter.most_common()[1][1]:
            v0_value == v0_counter.most_common()[1][0]
        else:
            v1_value == v1_counter.most_common()[1][0]

    print(len([x for x in v0 if x != v0_value]) + len([x for x in v1 if x != v1_value]))



if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import collections


def solve():

    n = int(input())
    v = list(map(int, input().split()))
    v0 = v[::2]
    v0_counter = collections.Counter(v0)
    v0_value = v0_counter.most_common()[0][0]
    v1 = v[1::2]
    v1_counter = collections.Counter(v1)
    v1_value = v1_counter.most_common()[0][0]

    if v.count(v0_value) == n:
        print(n//2)
        exit()
    if v0_value == v1_value:
        if v0_counter.most_common()[1][1] > v1_counter.most_common()[1][1]:
            v0_value == v0_counter.most_common()[1][0]
        else:
            v1_value == v1_counter.most_common()[1][1]

    print(len([x for x in v0 if x != v0_value]) + len([x for x in v1 if x != v1_value]))



if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
L = list(map(int, input().split()))
L1, L2 = [], []
for i in range(n):
    if i % 2:
        L1.append(L[i])
    else:
        L2.append(L[i])
c1 = Counter(L1)
c2 = Counter(L2)
sc1 = sorted(c1, key=lambda x: c1[x], reverse=True)
sc2 = sorted(c2, key=lambda x: c2[x], reverse=True)
if sc1 != sc2:
    ans = n - c1[sc1[0]] - c2[sc2[0]]
else:
    lst = []
    if len(c1) > 1:
        lst.append(n - c2[sc2[0]] - c1[sc1[0]])
    else:
        lst.append(n - c2[sc2[0]])
    if len(c2) > 1:
        lst.append(n - c1[sc1[0]] - c2[sc2[1]])
    else:
        lst.append(n - c1[sc1[0]])
    ans = min(lst)
print(ans)

Submission status: Wrong Answer

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

V_ODD = [v for i,v in enumerate(V) if i%2==1]
V_EVEN = [v for i,v in enumerate(V) if i%2==0]

import collections

V_ODD_SORTED = sorted(list(zip(collections.Counter(V_ODD).values(), collections.Counter(V_ODD).keys())), reverse=True)
V_EVEN_SORTED = sorted(list(zip(collections.Counter(V_EVEN).values(), collections.Counter(V_EVEN).keys())), reverse=True)

ans_list = []

if V_ODD_SORTED[0][1] == V_EVEN_SORTED[0][1]:
    if len(V_ODD_SORTED) > 1:
        tmp = len(V)//2 - V_ODD_SORTED[1][0]
        tmp += len(V)//2 - V_EVEN_SORTED[0][0]
        ans_list.append(tmp)
        
    elif len(V_EVEN_SORTED) > 1:
        tmp = len(V)//2 - V_ODD_SORTED[0][0]
        tmp += len(V)//2 - V_EVEN_SORTED[1][0]
        ans_list.append(tmp)

    else:
        ans_list.append(len(V)//2)
        
else:
    tmp = len(V)//2 - V_ODD_SORTED[0][0]
    tmp += len(V)//2 - V_EVEN_SORTED[0][0]
    ans_list.append(tmp)
    
print(min(ans_list))

Submission status: Wrong Answer

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

V_ODD = [v for i,v in enumerate(V) if i%2==1]
V_EVEN = [v for i,v in enumerate(V) if i%2==0]

import collections

if len(collections.Counter(V)) == 1:
    ans = len(V) // 2

else:
    ans = 999999
    
    for (c_odd, v_odd) in sorted(list(zip(collections.Counter(V_ODD).values(), collections.Counter(V_ODD).keys())), reverse=True):
        ans_tmp = len(V)//2 - c_odd

        for (c_even, v_even) in sorted(list(zip(collections.Counter(V_EVEN).values(), collections.Counter(V_EVEN).keys())), reverse=True):
            if v_even == v_odd:
                pass
            else:
                ans_tmp += len(V)//2 - c_even

        ans = min(ans, ans_tmp)

print(ans)

Submission status: Wrong Answer

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

odds = []
evens = []

for i in range(N):
    if i % 2 == 1:
        odds.append(numbers[i])
    else :
        evens.append(numbers[i])
        
odds_c = Counter(odds)
evens_c = Counter(evens)

odds_max_key = max(odds_c, key=odds_c.get)
evens_max_key = max(evens_c, key=evens_c.get)

if odds_max_key == evens_max_key:
    if odds_c[odds_max_key] >= evens_c[evens_max_key]:
        if len(evens_c) == 1:
            evens_max_value = 0
            odds_max_value = odds_c[odds_max_key]
        else: 
            evens_max_value = sorted(evens_c.values())[-2]
            odds_max_value = odds_c[odds_max_key]
    else :
        odds_max_value = sorted(odds_c.values())[-2]
        evens_max_value = evens_c[evens_max_key]
else :
    evens_max_value = max(odds_c.values())
    odds_max_value = max(evens_c.values())

output = (N - odds_max_value - evens_max_value)

print(output)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
odd=0
even=0

for i in range(N):
    a=A[i]
    if i%2==1:
        odd+=a

    else:
        even+=a

x=N//2
if abs(odd-x*(odd//x))<=abs(odd-x*(odd//x+1)):
    ans1=abs(odd-x*(odd//x))
    n1=odd//x
else:
    ans1=abs(odd-x*(odd//x+1))
    n1=odd//x+1

if abs(even-x*(even//x))<=abs(odd-x*(even//x+1)):
    ans2=abs(even-x*(even//x))
    n2=even//x
else:
    ans2=abs(even-x*(even//x+1))
    n2=even//x+1

if n1==n2:
    ans=min(abs(odd-x*(n1-1))+ans2,abs(odd-x*(n1+1))+ans2,ans1+abs(even-x*(n2-1)),ans1+abs(even-x*(n2+1)))
else:
    ans=ans1+ans2
print(ans)
#print(n1,n2,ans1,ans2)
#print(abs(odd-x*(n1-1))+ans2,abs(odd-x*(n1+1))+ans2,ans1+abs(even-x*(n2-1)),ans2,ans1+abs(even-x*(n2+1)))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
odd=0
even=0

for i in range(N):
    a=A[i]
    if i%2==1:
        odd+=a

    else:
        even+=a

x=N//2
if abs(odd-x*(odd//x))<=abs(odd-x*(odd//x+1)):
    ans1=abs(odd-x*(odd//x))
    n1=odd//x
else:
    ans1=abs(odd-x*(odd//x+1))
    n1=odd//x+1

if abs(even-x*(even//x))<=abs(odd-x*(even//x+1)):
    ans2=abs(even-x*(even//x))
    n2=even//x
else:
    ans2=abs(even-x*(even//x+1))
    n2=even//x+1

if n1==n2:
    ans=min(abs(odd-x*(n1-1))+ans2,abs(odd-x*(n1+1))+ans2,ans1+abs(even-x*(n2-1))+ans2,ans1+abs(even-x*(n2+1)))
else:
    ans=ans1+ans2
print(ans)
#print(n1,n2,ans1,ans2)
#print(abs(odd-x*(n1-1))+ans2,abs(odd-x*(n1+1))+ans2,ans1+abs(even-x*(n2-1)),ans2,ans1+abs(even-x*(n2+1)))

Submission status: Wrong Answer

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

odd={}
even={}
total={}

for i in range(n):
    t=a[i]
    if i%2==0:
        if t in odd:
            odd[t]+=1
        else:
            odd[t]=1
    else:
        if t in even:
            even[t]+=1
        else:
            even[t]=1
    if t in total:
        total[t]+=1
    else:
        total[t]=1

l=len(odd)+len(even)

odd=sorted(odd.items(),key=lambda x: x[1],reverse=True)
even=sorted(even.items(),key=lambda x: x[1],reverse=True)
total=sorted(total.items(),key=lambda x: x[1],reverse=True)


key=total[0][0]
value=total[0][1]

ans=0

if len(total)==1:
    print(n//2)
    exit(0)

if odd[0][0]==even[0][0]:
    ans=min(n-odd[0][1]-even[1][1],n-odd[1][0]-even[0][1])
else:
    ans = n-odd[0][1] - even[0][1]


print(ans)

Submission status: Wrong Answer

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

odd={}
even={}
total={}

for i in range(n):
    t=a[i]
    if i%2==0:
        if t in odd:
            odd[t]+=1
        else:
            odd[t]=1
    else:
        if t in even:
            even[t]+=1
        else:
            even[t]=1
    if t in total:
        total[t]+=1
    else:
        total[t]=1

l=len(odd)+len(even)

odd=sorted(odd.items(),key=lambda x: x[1],reverse=True)
even=sorted(even.items(),key=lambda x: x[1],reverse=True)
total=sorted(total.items(),key=lambda x: x[1],reverse=True)


key=total[0][0]
value=total[0][1]

ans=0
#過半数を超える
if value>=n//2:
    if len(total)==1:
        ans+=n//2
    elif odd[0][1]==n//2:
        k2=even[0][0]
        if key==k2:
            ans+=n//2 -even[1][1]
        else:
            ans+=n//2 -even[0][1]
    elif even[0][1]==n//2:
        k2=odd[0][0]
        if key==k2:
            ans+=n//2 - odd[1][1]
        else:
            ans+=n//2 - odd[0][1]
    else:
        ans+=n-odd[0][1] - even[0][1]
else:
    ans+=n-odd[0][1] - even[0][1]


print(ans)

Submission status: Wrong Answer

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

from collections import Counter

odd=[]
even=[]

for i in range(n):
    if i%2==0:
        odd.append(a[i])
    else:
        even.append(a[i])

c_o=Counter(odd).most_common()[0]
c_e=Counter(even).most_common()[0]

if c_e[0]==c_o[0] and c_e[1]==c_o[1]:
    print(n//2)
elif c_e[0]!=c_o[0] and c_e[1]==c_o[1] and c_e[1]==n//2:
    print(0)
else:
    print(n - c_e[1] - c_o[1])

Submission status: Wrong Answer

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

odd=[0]*(10**5+1)
even=[0]*(10**5+1)
total=[0]*(10**5+1)

for i in range(n):
    if i%2==0:
        odd[a[i]-1]+=1
    else:
        even[a[i]-1]+=1
    total[a[i]-1]+=1

odd_max=max(odd)
even_max=max(even)

ans=(n//2 - odd_max) + (n//2 -even_max)

from collections import Counter

c=list(Counter(a).values())

if len(c)==2 and c[0]==n//2 and even_max==n//2:
    print(0)
elif len(c)==1:
    print(n//2)
else:
    print(ans)

Submission status: Wrong Answer

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

odd=[0]*(10**5+1)
even=[0]*(10**5+1)
total=[0]*(10**5+1)

for i in range(n):
    if i%2==0:
        odd[a[i]-1]+=1
    else:
        even[a[i]-1]+=1
    total[a[i]-1]+=1

odd_max=max(odd)
even_max=max(even)

ans=(n//2 - odd_max) + (n//2 -even_max)

from collections import Counter

c=list(Counter(a).values())

if len(c)==2 and c[0]==n//2:
    print(0)
elif len(c)==1:
    print(n//2)
else:
    print(ans)

Submission status: Wrong Answer

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

odd=[0]*(10**5+1)
even=[0]*(10**5+1)
total=[0]*(10**5+1)

for i in range(n):
    if i%2==0:
        odd[a[i]-1]+=1
    else:
        even[a[i]-1]+=1
    total[a[i]-1]+=1

odd_max=max(odd)
even_max=max(even)

ans=(n//2 - odd_max) + (n//2 -even_max)

if max(total)>n/2:
    print(max(total)- n//2)
else:
    print(ans)

Submission status: Wrong Answer

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

odd=[0]*(10**5+1)
even=[0]*(10**5+1)
total=[0]*(10**5+1)

for i in range(n):
    if i%2==0:
        odd[a[i]-1]+=1
    else:
        even[a[i]-1]+=1
    total[a[i]-1]+=1

odd_max=max(odd)
even_max=max(even)

ans=(n//2 - odd_max) + (n//2 -even_max)

if max(total)==n:
    print(n//2)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v1 = V[::2]
v2 = V[1::2]

v1_count = Counter(v1)
v2_count = Counter(v2)

v1 = sorted([(value, key, 1) for key, value in v1_count.items()])
v2 = sorted([(value, key, 2) for key, value in v2_count.items()])

if len(v1) == 1 and len(v2) == 1:
    if v1[0][1] == v2[0][1]:
        print(N - v1[0][0])
    else:
        print(0)
elif len(v1) == 1:
    if v2[0][1] == v1[0][1]:
        print(N - v1[0][0] - v2[1][0])
    else:
        print(N - v1[0][0] - v2[0][0])
elif len(v2) == 1:
    if v1[0][1] == v2[0][1]:
        print(N - v2[0][0] - v1[1][0])
    else:
        print(N - v2[0][0] - v1[0][0])
else:
    if v1[0][1] == v2[0][1]:
        if v1[1][0] > v2[1][0]:
            print(N - v2[0][0] - v1[1][0])
        else:
            print(N - v1[0][0] - v2[1][0])
    else:
        print(N - v2[0][0] - v1[0][0])

Submission status: Wrong Answer

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

import sys
from collections import Counter

C0 = Counter(V[0::2])
C1 = Counter(V[1::2])

n0 = C0.most_common()[0][0]
n1 = C1.most_common()[0][0]

if C0 == C1:
    print(len(V)//2)
    sys.exit()

if n0 == n1:
    if C0.most_common()[1][1] >= C1.most_common()[1][1]:
        n0 = C0.most_common()[1][0]
    else:
        n1 = C1.most_common()[1][0]
    
count = 0
for v in V[0::2]:
    if v != n0:
        count += 1

for v in V[1::2]:
    if v != n1:
        count += 1
print(count)

Submission status: Wrong Answer

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

import sys
from collections import Counter

C0 = Counter(V[0::2])
C1 = Counter(V[1::2])

n0 = C0.most_common()[0][0]
n1 = C1.most_common()[0][0]

if len(C0) == len(C1) == 1:
    print(len(V)//2)
    sys.exit()

if n0 == n1:
    if C0.most_common()[1][1] >= C1.most_common()[1][1]:
        n0 = C0.most_common()[1][0]
    else:
        n1 = C1.most_common()[1][0]
    
count = 0
for v in V[0::2]:
    if v != n0:
        count += 1

for v in V[1::2]:
    if v != n1:
        count += 1
print(count)

Submission status: Wrong Answer

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

from collections import Counter

C0 = Counter(V[0::2])
C1 = Counter(V[1::2])

n0 = C0.most_common()[0][0]
n1 = C1.most_common()[0][0]

if n0 == n1:
    print(len(V)//2)
else:
    count = 0
    for v in V[0::2]:
        if v != n0:
            count += 1
    
    for v in V[1::2]:
        if v != n1:
            count += 1
    print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
even=v[0:n:2]
odd=v[1:n:2]
e_dic=dict(Counter(even))
o_dic=dict(Counter(odd))
e_dic=sorted(e_dic.items(),key=lambda x:x[1],reverse=True)
o_dic=sorted(o_dic.items(),key=lambda x:x[1], reverse=True)
if e_dic[0][0]!=o_dic[0][0]:
    ans=n-e_dic[0][1]-o_dic[0][1]
else:
    if e_dic[0][1]>=o_dic[0][1]:
        if len(o_dic)>=2:
            ans=n-e_dic[0][1]-o_dic[1][1]
        else:
            ans=n-e_dic[0][1]
    else:
        if len(e_dic)>=2:
            ans=n-e_dic[1][1]-o_dic[0][1]
        else:
            ans=n-o_dic[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


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


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


n = z()
v = zz()
a_lis = v[0::2]
b_lis = v[1::2]

a_all = [0]*(1 + 10**5)
b_all = [0]*(1 + 10**5)
for a in a_lis:
    a_all[a] += 1

for b in b_lis:
    b_all[b] += 1
nums = list(range(0, len(a_all)))
a_all = zip(a_all, nums)
b_all = zip(b_all, nums)
a_all = sorted(a_all, reverse=True)
b_all = sorted(b_all, reverse=True)
ans = 0
a_num, fixed_a_value = a_all[0]
b_num, fixed_b_value = b_all[0]
# print(a_num, b_num)
if (fixed_a_value == fixed_b_value):
    if (a_num < b_num):
        # bを固定したい
        a_num, fixed_a_value = a_all[1]
        # if (a_num == 0):
        #     a_num = n//2
    else:
        b_num, fixed_b_value = b_all[1]
        # if (b_num == 0):
        #     b_num = n//2
# print(a_num, b_num)
ans = n-a_num-b_num
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
dic1,dic2 = {},{}
c1,c2=0,0
for i in range(0,n,2):
  if v[i] in dic1.keys():
    dic1[v[i]] += 1
  else:
    dic1[v[i]] = 1
  c1 += 1

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

dic1 = sorted(dic1.items(), key = lambda x : x[1], reverse=True)
dic2 = sorted(dic2.items(), key = lambda x : x[1], reverse=True)
if len(dic1) == 1:
  dic1.append((0,0))
if len(dic2) == 1:
  dic2.append((0,0))

ans = 0
if dic1[0][0] != dic2[0][0]:
  ans = dic1[1][1] + dic2[1][1]
else:
  ans = min(dic1[0][1] + dic2[1][1] , dic1[1][1] + dic2[0][1])

print(ans)

Submission status: Wrong Answer

Solution code:

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

u = v[1::2]
d = v[0::2]
    
#print(u)
#print(d)

U = [0] * 100010
for i in range(len(u)):
    U[u[i]] += 1
    
D = [0] * 100010
for i in range(len(d)):
    D[d[i]] += 1
   
if U.index(max(U)) == D.index(max(D)):
    print(n - max(U))
    exit()
    
print(n - max(U) - max(D))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
d1 = {}
d2 = {}

for i in range(0,n//2+2,2):
  a1 = v[i]
  a2 = v[i+1]
  
  if a1 not in d1:
    d1[a1] = 1
  else:
    d1[a1] += 1
    
  if a2 not in d2:
    d2[a2] = 1
  else:
    d2[a2] += 1


l1 = list(sorted(d1.items(), key=lambda x:x[1]))
l2 = list(sorted(d2.items(), key=lambda x:x[1]))


if len(set(v)) == 1:
  print(n//2)
  exit()
if l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) >= 2:
  print(min(n - l1[-1][1] - l2[-2][1],n - l1[-2][1] - l2[-1][1]))
elif l1[-1][0] == l2[-1][0] and len(l1) == 1 and len(l2) >= 2:
  print(n - l1[-1][1] - l2[-2][1])
elif l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) == 1:
  print(n - l1[-2][1] - l2[-1][1])
else:
  print(n - l1[-1][1] - l2[-1][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
d1 = {}
d2 = {}

for i in range(0,n//2+2,2):
  a1 = v[i]
  a2 = v[i+1]
  
  if a1 not in d1:
    d1[a1] = 1
  else:
    d1[a1] += 1
    
  if a2 not in d2:
    d2[a2] = 1
  else:
    d2[a2] += 1


l1 = list(sorted(d1.items(), key=lambda x:x[1]))
l2 = list(sorted(d2.items(), key=lambda x:x[1]))


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

if l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) >= 2:
  print(min(n - l1[-1][1] - l2[-2][1],n - l1[-2][1] - l2[-1][1]))
elif l1[-1][0] == l2[-1][0] and len(l1) == 1 and len(l2) >= 2:
  print(n - l1[-1][1] - l2[-2][1])
elif l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) == 1:
  print(n - l1[-2][1] - l2[-1][1])
else:
  print(n - l1[-1][1] - l2[-1][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
d1 = {}
d2 = {}

for i in range(0,n//2+2,2):
  a1 = v[i]
  a2 = v[i+1]
  print(a1,a2)
  if a1 not in d1:
    d1[a1] = 1
  else:
    d1[a1] += 1
    
  if a2 not in d2:
    d2[a2] = 1
  else:
    d2[a2] += 1


l1 = list(sorted(d1.items(), key=lambda x:x[1]))
l2 = list(sorted(d2.items(), key=lambda x:x[1]))


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

if l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) >= 2:
  print(min(n - l1[-1][1] - l2[-2][1],n - l1[-2][1] - l2[-1][1]))
elif l1[-1][0] == l2[-1][0] and len(l1) == 1 and len(l2) >= 2:
  print(n - l1[-1][1] - l2[-2][1])
elif l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) == 1:
  print(n - l1[-2][1] - l2[-1][1])
else:
  print(n - l1[-1][1] - l2[-1][1])

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
n=int(input())
v=[int(x) for x in input().split()]

v1=[] # odd
v2=[] # even

for i in range(n):
    if i%2==0:
        v1.append(v[i])
    else:
        v2.append(v[i])

m1=Counter(v1).most_common()
m2=Counter(v2).most_common()




ans=0
for i in range(min(len(m1),len(m2))):
    # 最頻値が異なる
    if m1[i][0]!=m2[i][0]:
        ans=sum(list(m1[j][1] for j in range(i+1,len(m1))))+sum(list(m2[j][1] for j in range(i+1,len(m2))))
        print(ans)
        sys.exit()
    # 最頻値が同じ
    else:
        # v1の最頻値の回数のほうが大きい
        if m1[i][1]>m2[i][1]:
            ans=m2[i][1]+sum(list(m1[j][1] for j in range(i+1,len(m1))))+sum(list(m2[j][1] for j in range(i+2,len(m2))))
            print(ans)
            sys.exit()
        
        # v2の最頻値の回数ほうが大きい
        elif m1[i][1]<m2[i][1]:
            ans=m1[i][1]+sum(list(m1[j][1] for j in range(i+2,len(m1))))+sum(list(m2[j][1] for j in range(i+1,len(m2))))
            print(ans)
            sys.exit()
            
        # 最頻値の回数同じだった
        else:
            # 最頻値の回数が少ないほうを探す
            ans=min(sum(list(m1[j][1] for j in range(i,len(m1))))+sum(list(m2[j][1] for j in range(i+1,len(m2)))),sum(list(m1[j][1] for j in range(i+1,len(m1))))+sum(list(m2[j][1] for j in range(i,len(m2)))))
            print(ans)
            sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
a = l()
b1 = []
b2 = []
for i in range(N):
    if i%2==0:
        b1.append(a[i])
    else:
        b2.append(a[i])
c1 = Counter(b1)
c2 = Counter(b2)
k1,v1 = list(c1.items())[0]
k2,v2 = list(c2.items())[0]
ans = v1+v2
v3 = 0
v4 = 0
if k1 == k2:
    if len(list(c2.values())) > 1:
        v4 = list(c2.values())[1]
    if len(list(c1.values())) > 1:
        v3 = list(c1.values())[1]
    ans = max(v1+v4,v2+v3)
print(N-ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
a = l()
b1 = []
b2 = []
for i in range(N):
    if i%2==0:
        b1.append(a[i])
    else:
        b2.append(a[i])
c1 = Counter(b1)
c2 = Counter(b2)
F1 = 0
F2 = 0
if len(list(c1)) > 1:
    F1 = 1
if len(list(c2)) > 1:
    F2 = 1
k1,v1 = list(c1.items())[0]
k2,v2 = list(c2.items())[0]
ans = v1+v2
if k1 == k2:
    if F2 == 1:
        v4 = list(c2.values())[1]
        v3 = list(c1.values())[1]
        ans = max(v1+v4,v2+v3)
    else:
        if v1 > v2:
            ans = v1
        else:
            ans = v2
print(N-ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
a = l()
b1 = []
b2 = []
for i in range(N):
    if i%2==0:
        b1.append(a[i])
    else:
        b2.append(a[i])
c1 = Counter(b1)
c2 = Counter(b2)
F1 = 0
F2 = 0
if len(list(c1)) > 1:
    F1 = 1
if len(list(c2)) > 1:
    F2 = 1
k1,v1 = list(c1.items())[0]
k2,v2 = list(c2.items())[0]
if k1 == k2:
    if v1 > v2 and F2 == 1:
        v2 = list(c2.values())[1]
    elif v1 <= v2 and F1 == 1:
        v1 = list(c1.values())[1]
    else:
        if v1 > v2:
            v2 = 0
        else:
            v1 = 0
print(N-v1-v2)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
a = l()
b1 = []
b2 = []
for i in range(N):
    if i%2==0:
        b1.append(a[i])
    else:
        b2.append(a[i])
c1 = Counter(b1)
c2 = Counter(b2)
F1 = 0
F2 = 0
if len(list(c1)) > 1:
    F1 = 1
if len(list(c2)) > 1:
    F2 = 1
k1,v1 = list(c1.items())[0]
k2,v2 = list(c2.items())[0]
if k1 == k2:
    if v1 > v2 and F2 == 1:
        v2 = list(c2.values())[1]
    elif v1 < v2 and F1 == 1:
        v1 = list(c1.values())[1]
    else:
        if v1 > v2:
            v2 = 0
        else:
            v1 = 0
print(N-v1-v2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

x = Counter(v[::2])
y = Counter(v[1::2])

ans = n
if len(x) > 1:
  ans -= x.most_common(1)[0][1]
if len(y) > 1:
  ans -= y.most_common(1)[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
a=n//2
dp=[[0,0]for i in range(10**5+1)]
bp=[[0,0]for i in range(10**5+1)]
for i in range(n):
  if i%2==0:
    dp[v[i]][0]+=1
    dp[v[i]][1]=v[i]
  else:
    bp[v[i]][0]+=1
    bp[v[i]][1]=v[i]
dp.sort(reverse=True)
bp.sort(reverse=True)
if bp[0][1]==dp[0][1]:
  dp[0][0]=dp[1][0]
print(a-dp[0][0]+a-bp[0][0])

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
a=n//2
dp=[0]*(10**5+1)
bp=[0]*(10**5+1)
for i in range(n):
  if i%2==0:
    dp[v[i]]+=1
  else:
    bp[v[i]]+=1
x=max(bp)
y=max(dp)
for i in range(1,10**5+1):
  if x==bp[i] and y==dp[i]:
    y=0
print(a-x+a-y)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
a=n//2
dp=[0]*(10**5+1)
bp=[0]*(10**5+1)
for i in range(n):
  if i%2==0:
    dp[v[i]]+=1
  else:
    bp[v[i]]+=1
x=max(bp)
y=max(dp)
for i in range(1,10**5+1):
  if dp[i]==bp[i] and x==bp[i] and y==dp[i]:
    y=0
print(a-x+a-y)

Submission status: Wrong Answer

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

first=v[::2]#これが全部同じになればいい
f = collections.Counter(first).values()
sec=v[1::2]#これが全部同じになればいい
s = collections.Counter(sec).values()
if len(s)>1:
    ans_s=sum(s)-max(s)
else:
    ans_s=1
if len(f)>1:
    ans_f=sum(f)-max(f)
else:
    ans_f=1
print(ans_f+ans_s)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

def ii():
    return int(input())

def main():
    n = ii()
    v = list(mi())
    ve = [v[i] for i in range(n) if i%2==0]
    vo = [v[i] for i in range(n) if i%2==1]

    ce = Counter(ve)
    co = Counter(vo)

    if ce.most_common()[0][0] == co.most_common()[0][0]:
        if len(ce.most_common()) > 1:
            ne = ce.most_common()[1][1]
            no = co.most_common()[0][1]
        elif len(co.most_common()) > 1:
            ne = ce.most_common()[0][1]
            no = co.most_common()[1][1]
        else:
            ne = ce.most_common()[0][1]
            no = 0
    else:
        ne = ce.most_common()[0][1]
        no = co.most_common()[0][1]

    print(n-ne-no)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
V = Counter(v)
V[0] = 1
V =  sorted(V.items(), reverse=True)

ans1, ans2 = 0, 0
for i in range(n):
  if i % 2 == 0:
    if v[i] != V[0][0]:
      ans1 += 1
  else:
    if v[i] != V[1][0]:
      ans1 += 1
for i in range(n):
  if i % 2 == 0:
    if v[i] != V[1][0]:
      ans2 += 1
  else:
    if v[i] != V[0][0]:
      ans2 += 1
print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
d = [Counter(), Counter()]
n = int(input())
v = list(map(int, input().split()))
for i, vi in enumerate(v):
    d[i&1][vi] += 1
a = []
for i in range(2):
    a.append(sorted(d[i].keys(), key=lambda k: d[i][k], reverse=True))
c = [ai[:2] for ai in a]
if len(set(c[0]) & set(c[1])) == 1:
    print(n // 2)
else:
    ans = 1001001001
    for ci in c[0]:
        for cj in c[1]:
            if ci == cj:
                continue
            cnt = sum(v for k, v in d[0].items() if k != ci) + sum(v for k, v in d[1].items() if k != cj)
            ans = min(ans, cnt)
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
even = [0] * (10**5+5)
odd = [0] * (10**5+5)
numnum = 0
for i in range(n):
    if even[v[i]] == 0 and odd[v[i]] == 0:
        numnum += 1
    if i % 2 == 0:
        even[v[i]] += 1
    else:
        odd[v[i]] += 1
even.sort(reverse=True)
odd.sort(reverse=True)
ans = n - (even[0] + odd[0])
if numnum == 1:
    ans = n // 2
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = tuple(map(int, input().split()))
e = v[0::2]
o = v[1::2]
e_c = tuple(Counter(e).most_common())
o_c = tuple(Counter(o).most_common())
if e_c[0][0] == o_c[0][0]:
    len_e_c = len(e_c)
    len_o_c = len(o_c)
    if len_e_c == 1 and len_o_c == 1:
        print(n // 2)
    elif (len_e_c == 1 or len_o_c == 1):
        if len_e_c == 1:
            x = o_c[1]
        elif len_o_c == 1:
            x = e_c[1]
        print(x[1])
    else:
        x = e_c[1][1]+o_c[1][1]
        print(x)

else:
    print(n-e_c[0][1]-o_c[0][1])