Problem:


Score : 300 points

Problem Statement

A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:

For each i = 1,2,..., n-2, a_i = a_{i+2}.

Exactly two different numbers appear in the sequence.

You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

Print the minimum number of elements that needs to be replaced.

Sample Input 1

4
3 1 3 2

Sample Output 1

1

The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

The sequence 105,119,105,119,105,119 is /\/\/\/.

Sample Input 3

4
1 1 1 1

Sample Output 3

2

The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
v=list(input().split())
v1=Counter(v[0::2]).most_common()
v2=Counter(v[1::2]).most_common()
ans=0
if v1[0][0]!=v2[0][0]:
  ans=(len(v[0::2])-v1[0][1])+(len(v[1::2])-v2[0][1])
elif len(v1)==1 and len(v2)==1:
  ans=min(v1[0][1],v2[0][1])
elif len(v1)==1:
  ans=len(v[1::2])-v2[1][1]
elif len(v2)==1:
  ans=(len(v[0::2])-v1[1][1])
else:
  ans=min((len(v[0::2])-v1[1][1])+(len(v[1::2])-v2[0][1]),(len(v[0::2])-v1[0][1])+(len(v[1::2])-v2[1][1]))
print(ans)

Submission status: Accepted

Solution code:
from itertools import permutations
import collections
N = int(input())
nums = list(map(int, input().split()))
odd_nums = []
even_nums = []
for i, num in enumerate(nums):
    if i % 2 == 1:
        even_nums.append(num)
    else:
        odd_nums.append(num)

useable_nums = set(nums)
even_length = len(even_nums)
odd_length = len(odd_nums)
even_counter = collections.Counter(even_nums).most_common()
odd_counter = collections.Counter(odd_nums).most_common()
even_counter.append((0, 0))
odd_counter.append((0, 0))
even_counter.sort(key=lambda x: x[1], reverse=True)
odd_counter.sort(key=lambda x: x[1], reverse=True)
# print(even_counter)
# print(odd_counter)


min_ans = None
if even_counter[0][0] == odd_counter[0][0]:
    min_ans = min((odd_length - odd_counter[0][1]) + (even_length - even_counter[1][1]),
                  (odd_length - odd_counter[1][1]) + (even_length - even_counter[0][1]))
else:

    min_ans = odd_length - odd_counter[0][1] + even_length - even_counter[0][1]
print(min_ans)

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
v=list(map(int,input().split()))
even={}
odd={}
for i in range(n):
    if i%2==0:
        if v[i] not in even:
            even[v[i]]=1
        else:
            even[v[i]]+=1
    else:
        if v[i] not in odd:
            odd[v[i]]=1
        else:
            odd[v[i]]+=1
    
even=sorted(even.items(),key=lambda x: x[1],reverse=True)
odd=sorted(odd.items(),key=lambda x:x[1],reverse=True)
if even[0][0]==odd[0][0]:
    e1=even[0][1]
    e2=even[1][1] if len(even)>1 else 0
    o1=odd[0][1]
    o2=odd[1][1] if len(odd)>1 else 0
    print(min((n-e1-o2),(n-e2-o1)))
else:
    e=even[0][1]
    o=odd[0][1]
    print(n-e-o)

Submission status: Accepted

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

odd_list =[]
num_list =[]

for i in range(n):
    if i%2 == 0:
        odd_list.append(arr[i])
    if i%2 != 0:
        num_list.append(arr[i])

odd_count = Counter(odd_list)
num_count = Counter(num_list)
odd1 = odd_count[odd_count.most_common()[0][0]]
num1 = num_count[num_count.most_common()[0][0]]

if odd1 != num1:
    print(n-odd_count.most_common()[0][1]-num_count.most_common()[0][1])
    exit()

if len(set(arr)) == 1:
    print(int(n/2))
    exit()

if len(set(num_list))==1 and len(set(odd_list))==1:
    print(0)
    exit()

if len(set(odd_count)) == 1 and len(set(num_count)) != 1:
    num2 = num_count[num_count.most_common()[1][0]]
    if odd_list[0] == num_count.most_common()[0][0]:
        print(int(n/2)-num2)
        exit()
    if odd_list[0] != num_count.most_common()[0][0]:
        print(int(n/2)-num1)
        exit()

if len(set(odd_count)) != 1 and len(set(num_count)) == 1:
    odd2 = odd_list[odd_count.most_common()[1][0]]
    if num_list[0] == odd_count.most_common()[0][0]:
        print(int(n/2)-odd2)
        exit()
    if num_list[0] != odd_count.most_common()[0][0]:
        print(int(n/2)-odd1)
        exit()

odd2 = odd_count[odd_count.most_common()[1][0]]
num2 = num_count[num_count.most_common()[1][0]]

if odd_count.most_common()[0][0] != num_count.most_common()[0][0]:
    print(n-odd1-num1)

if odd_count.most_common()[0][0] == num_count.most_common()[0][0]:
    print(min(n-odd1-num2, n-odd2-num1))

Submission status: Accepted

Solution code:
# 初期入力
from collections import Counter
import sys
input = sys.stdin.readline  #文字列では使わない
n = int(input())
v = list(map(int, input().split()))
vo1 =v[1::2]
ve2 =v[0::2]
co1_k,co1_v = zip(*Counter(vo1).most_common())
ce2_k,ce2_v = zip(*Counter(ve2).most_common())

ans =0

if vo1 ==ve2:
    if len(ce2_k) <=2:
        ans =sum(ce2_v)
    else:
        ans =sum(ce2_v) +sum(co1_v[2:])   
elif len(co1_v) ==len(ce2_v) ==1:
    ans =0
elif co1_k[0] ==ce2_k[0]:
    if len(co1_v) ==1:
        ans =sum(ce2_v[1:])
    elif len(ce2_v) ==1:
        ans =sum(co1_v[1:])
    elif len(co1_v) ==len(ce2_v) ==2:
        ans1 =co1_v[1] +ce2_v[0]
        ans2 =co1_v[0] +ce2_v[1]
        ans =min(ans1,ans2)
    elif len(co1_v) ==2:
        ans1 =co1_v[1] +ce2_v[0] +sum(ce2_v[2:])
        ans2 =co1_v[0] +sum(ce2_v[1:])
        ans =min(ans1,ans2)
    elif len(ce2_v) ==2:
        ans1 =ce2_v[1] +co1_v[0] +sum(co1_v[2:])
        ans2 =ce2_v[0] +sum(co1_v[1:])
        ans =min(ans1,ans2)
    else:
        ans1 =sum(co1_v[1:]) +ce2_v[0] +sum(ce2_v[2:] )
        ans2 =sum(ce2_v[1:]) +co1_v[0] +sum(co1_v[2:] )
        ans =min(ans1,ans2)
else: 
    if len(co1_v) ==1:
        ans =sum(ce2_v[1:])
    elif len(ce2_v) ==1:
        ans =sum(co1_v[1:])
    else:
        ans =sum(co1_v[1:]) +sum(ce2_v[1:])  
   
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
odd = [v[2*i] for i in range(n//2)]
even = [v[2*i+1] for i in range(n//2)]

co = Counter(odd)
ce = Counter(even)
co = co.most_common()
ce = ce.most_common()
if co[0][0] == ce[0][0]:
  if (len(co)>1) and (len(ce)>1):
    ans = min(n//2-co[1][1]+n//2-ce[0][1], n//2-co[0][1]+n//2-ce[1][1])
  elif len(co) > 1:
    ans = n//2 - co[1][1]
  elif len(ce) > 1:
    ans = n//2 - ce[1][1]
  else:
    ans = n//2
else:
  ans = n//2-co[0][1] + n//2-ce[0][1]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n, *v = map(int, open(0).read().split())
vo = Counter(v[::2])
ve = Counter(v[1::2])
vomc = vo.most_common() + [(0, 0)]
vemc = ve.most_common() + [(0, 0)]
if vomc[0][0] == vemc[0][0]:
    ans = min(n//2 - vomc[0][1] + n//2 - vemc[1][1], n//2 - vomc[1][1] + n//2 - vemc[0][1])
else:
    ans = n//2 - vomc[0][1] + n//2 - vemc[0][1]
print(ans)

Submission status: Accepted

Solution code:
"""
与えられた数列の奇数番目の数と偶数番目の数をそれぞれ確認し、
要素数の多いものにそれぞれ書き換える。
文字種が1種類にならないように注意する
"""
from collections import Counter

N = int(input())
V_LI = list(map(int, input().split()))
if len(set(V_LI)) == 1:
    # そもそも一種類しかなかったら
    print(N // 2)
    exit()
odd_li = [V_LI[i] for i in range(0, N, 2)]
even_li = [V_LI[i] for i in range(1, N, 2)]
odd_c = sorted(Counter(odd_li).items(), key=lambda x: -x[1])
even_c = sorted(Counter(even_li).items(), key=lambda x: -x[1])
if odd_c[0][0] == even_c[0][0]:
    cnt_1 = N
    cnt_2 = N
    # 偶数側を固定する
    if len(even_c) > 1:
        odd_cnt = len(odd_li) - odd_c[0][1]
        even_cnt = len(even_li) - even_c[1][1]
        cnt_1 = odd_cnt + even_cnt

    # 奇数側を固定する
    if len(odd_c) > 1:
        odd_cnt = len(odd_li) - odd_c[1][1]
        even_cnt = len(even_li) - even_c[0][1]
        cnt_2 = odd_cnt + even_cnt

    print(min(cnt_1, cnt_2))
else:
    odd_cnt = len(odd_li) - odd_c[0][1]
    even_cnt = len(even_li) - even_c[0][1]
    print(odd_cnt + even_cnt)

Submission status: Accepted

Solution code:
import collections
N = int(input())
V = list(map(int,input().split()))
E = []
O = []
for i in range(N):
    if i % 2 == 0:
        O.append(V[i])
    else:
        E.append(V[i])
EC = collections.Counter(E).most_common()
OC = collections.Counter(O).most_common()
if len(EC) == 1 and len(OC) == 1:
    if EC[0][0] == OC[0][0]:
        print(N//2)
    else:
        print(0)
elif len(EC) == 1 and len(OC) != 1:
    if EC[0][0] == OC[0][0]:
        print(N-EC[0][1]-OC[1][1])
    else:
        print(N//2-OC[0][1])
elif len(EC) != 1 and len(OC) == 1:
    if EC[0][0] == OC[0][0]:
        print(N//2-EC[1][1])
    else:
        print(N//2-EC[0][1])
elif EC[0][0] == OC[0][0]:
    if EC[0][1]+OC[1][1] == EC[1][1]+OC[0][1]:
        print(N-EC[0][1]-OC[1][1])
    elif EC[0][1]+OC[1][1] > EC[1][1]+OC[0][1]:
        print(N-EC[0][1]-OC[1][1])
    else:
        print(N-EC[1][1]-OC[0][1])
else:
    print(N-EC[0][1]-OC[0][1])

Submission status: Accepted

Solution code:
from collections import Counter

n, *v = map(int, open(0).read().split())
vo = Counter(v[::2])
ve = Counter(v[1::2])
vo_mc = vo.most_common()[0]
ve_mc = ve.most_common()[0]
if vo_mc[0] == ve_mc[0]:
    ans = n
    if ve_mc[1] != n//2:
        ans = min(n//2 - vo_mc[1] + n//2 - ve.most_common()[1][1], ans)
    if vo_mc[1] != n//2:
        ans = min(n//2 - vo.most_common()[1][1] + n//2 - ve_mc[1], ans)
    ans = min(n//2 - vo_mc[1] + n//2, ans)
else:
    ans = n//2 - vo_mc[1] + n//2 - ve_mc[1]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n, *v = map(int, open(0).read().split())
vo = Counter(v[::2])
ve = Counter(v[1::2])
vo_mc = vo.most_common()[0]
ve_mc = ve.most_common()[0]
if vo_mc[0] == ve_mc[0]:
    if vo_mc[1] > ve_mc[1]:
        ans = n//2 - vo_mc[1]
        if ve_mc[1] != n//2:
            ans += n//2 - ve.most_common()[1][1]
        else:
            ans += n//2
    elif vo_mc[1] < ve_mc[1]:
        ans =  n//2 - ve_mc[1]
        if vo_mc[1] != n//2:
            ans += n//2 - vo.most_common()[1][1]
        else:
            ans += n//2
    else:
        ans = n
        if ve_mc[1] != n//2:
            ans = min(n//2 - vo_mc[1] + n//2 - ve.most_common()[1][1], ans)
        if vo_mc[1] != n//2:
            ans = min(n//2 - vo.most_common()[1][1] + n//2 - ve_mc[1], ans)
        ans = min(n//2 - vo_mc[1] + n//2, ans)
else:
    ans = n//2 - vo_mc[1] + n//2 - ve_mc[1]
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    # n, m = [int(x) for x in input().split()]
    n = int(input())
    a = [int(x) for x in input().split()]
    e = defaultdict(int)
    o = defaultdict(int)
    for i in range(n):
        if i % 2:
            e[a[i]] += 1
        else:
            o[a[i]] += 1
    ee = n // 2
    oo = n // 2 + 1
    x = [(e[el], el) for el in e] + [(0, 0)]
    y = [(o[el], el) for el in o] + [(0, 0)]
    x.sort(reverse=True)
    y.sort(reverse=True)
    ans = n
    if x[0][1] == y[0][1]:
        ans = min(ans, n - x[0][0] - y[1][0])
        ans = min(ans, n - x[1][0] - y[0][0])
    else:
        ans = n - x[0][0] - y[0][0]
    print(ans)

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=Counter(v[::2])
v2=Counter(v[1::2])
v1[0]=0
v2[0]=0
v1_max=v1.most_common()[0]
v2_max=v2.most_common()[0]
v1_second=v1.most_common()[1]
v2_second=v2.most_common()[1]
if v1_max[0]!=v2_max[0]:
    print(n-v1_max[1]-v2_max[1])
else:
    print(min(n-v1_max[1]-v2_second[1],n-v2_max[1]-v1_second[1]))

Submission status: Accepted

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

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

    c1 = Counter(v[::2])
    c2 = Counter(v[1::2])
    o = c1.most_common(2)
    e = c2.most_common(2)
    o.append((0,0))
    e.append((0,0))
    if o[0][0] == e[0][0]:
        print(min(n-o[1][1]-e[0][1],n-o[0][1]-e[1][1]))
    else:
        print(n-o[0][1]-e[0][1])

Submission status: Accepted

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

if len(set(v)) == 1:
    print(n // 2)
else:
    c1 = Counter(v[::2])
    c2 = Counter(v[1::2])
    c1m = c1.most_common()
    c2m = c2.most_common()

    if c1m[0][0] == c2m[0][0]:
        print(min(n - c1m[0][1] - c2m[1][1], n - c1m[1][1] - c2m[0][1]))
    else:
        print(n - c1m[0][1] - c2m[0][1])

Submission status: Accepted

Solution code:

from collections import Counter
N = int(input())
V = list(map(int, input().split()))
evens = Counter(V[0::2]).most_common()
odds = Counter(V[1::2]).most_common()
evens.append((0, 0))
odds.append((0, 0))

if evens[0][0] == odds[0][0]:
    print(min(N - evens[1][1] - odds[0][1], N - evens[0][1] - odds[1][1]))
else:
    print(N - evens[0][1] - odds[0][1])

Submission status: Accepted

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

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

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

if sorted_even[0][0] != sorted_odd[0][0]:
    print(n - sorted_even[0][1] - sorted_odd[0][1])
elif sorted_even[0][1] == sorted_odd[0][1]:#最頻値とその出現回数が等しい
    if len(sorted_even) == 1 and len(sorted_odd) == 1:
        print(n//2)
    elif len(sorted_even) == 1:
        print(n - sorted_even[0][1] - sorted_odd[1][1])
    elif len(sorted_odd) == 1:
        print(n - sorted_even[1][1] - sorted_odd[0][1])
    elif sorted_even[1][1] > sorted_odd[1][1]:
        print(n - sorted_even[1][1] - sorted_odd[0][1])
    elif sorted_even[1][1] < sorted_odd[1][1]:
        print(n - sorted_even[0][1] - sorted_odd[1][1])
    else:
        print(n - sorted_even[0][1] - sorted_odd[1][1])#2番目の最頻値とその出現回数も等しい
elif sorted_even[0][1] > sorted_odd[0][1]:
    print(n - sorted_even[0][1] - sorted_odd[1][1])
else:
    print(n - sorted_even[1][1] - sorted_odd[0][1])

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
a = Counter(v[::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(min(n-a[1][1]-b[0][1],n-a[0][1]-b[1][1]))

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    n=int(input())
    v=list(map(int,input().split()))
    v0=sorted(Counter(v[::2]).items(), key=lambda x: x[1])
    v1=sorted(Counter(v[1::2]).items(), key=lambda x: x[1])
    
    if v0[-1][0] != v1[-1][0]:
        print(n-v0[-1][1]-v1[-1][1])
    else:
        if len(v0) == 1 and len(v1) == 1:
            print(n//2)
        else:
            a = (v0[-1][1] + v1[-2][1]) if len(v1) > 1 else 0
            b = (v0[-2][1] + v1[-1][1]) if len(v0) > 1 else 0
            print(n - max(a, b))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    n=int(input())
    v=list(map(int,input().split()))
    v0=sorted(Counter(v[::2]).items(), key=lambda x: x[1])
    v1=sorted(Counter(v[1::2]).items(), key=lambda x: x[1])
    
    #print(n, v0[-1], v1[-1])
    if v0[-1][0] != v1[-1][0]:
        print(n-v0[-1][1]-v1[-1][1])
    else:
        if len(v0) == 1 and len(v1) == 1:
            print(n//2)
        else:
            try:
                a = v0[-1][1] + v1[-2][1]
            except:
                a = 0
            try:
                b = v0[-2][1] + v1[-1][1]
            except:
                b = 0
            print(n - max(a, b))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    n=int(input())
    v=list(map(int,input().split()))
    v0=Counter(v[0::2]).most_common(2)
    v1=Counter(v[1::2]).most_common(2)
    
    if v0[0][0] != v1[0][0]:
        print(n - v0[0][1] - v1[0][1])
    else:
        if len(v0) == 1 and len(v1) == 1:
            print(n//2)
        else:
            print(n-max(v0[0][1]+v1[1][1], v0[1][1]+v1[0][1]))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
 
dico = {}
dice = {}
for i in range(N):
  if i % 2 == 0:
    if As[i] not in dice:
      dice[As[i]] = 1
    else:
      dice[As[i]] += 1
  else:
    if As[i] not in dico:
      dico[As[i]] = 1
    else:
      dico[As[i]] += 1
    
cnto = [0,0]
cnte = [0,0]
 
o = -1
e = -1
for k in dico:
  if dico[k] > cnto[0]:
    cnto[1] = cnto[0]
    cnto[0] = dico[k]
    o = k
  elif dico[k] > cnto[1]:
    cnto[1] = dico[k]
    
for k in dice:
  if dice[k] > cnte[0]:
    cnte[1] = cnte[0]
    cnte[0] = dice[k]
    e = k
  elif dice[k] > cnte[1]:
    cnte[1] = dice[k]
  
if o == e:
  print(N-max(cnto[0]+cnte[1],cnte[0]+cnto[1]))
else:  
  print(N-cnto[0]-cnte[0])

Submission status: Accepted

Solution code:
from collections import Counter


def solve(V):
    n = len(V)
    ac = Counter(V[::2]).most_common(2)
    bc = Counter(V[1::2]).most_common(2)

    if ac[0][0] != bc[0][0]:
        return n - ac[0][1] - bc[0][1]
    else:
        if len(bc) == 1 or len(ac) == 1:
            return n // 2
        else:
            return n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))

Submission status: Accepted

Solution code:
from collections import Counter

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

d1 = Counter(l[::2]).most_common()
d2 = Counter(l[1::2]).most_common()
d1.append([0,0])
d2.append([0,0])

if d1[0][0] != d2[0][0]:
    print(n//2-d1[0][1] + n//2-d2[0][1])
else:
    ans1 = n//2 - d1[0][1] + n//2 - d2[1][1]
    ans2 = n//2 - d1[1][1] + n//2 - d2[0][1]
    print(min(ans1, ans2))

Submission status: Accepted

Solution code:
n=int(input())
lst=list(map(int,input().split()))
if len(set(lst))==1:
    print(n//2)
    exit()
a=sorted(lst[::2])
b=sorted(lst[1::2])

import collections
a=collections.Counter(a)
b=collections.Counter(b)
a=a.most_common()
b=b.most_common()
if a[0][0]!=b[0][0]:
    print(n//2-a[0][1]+n//2-b[0][1])
else:
    print(min(n//2-a[0][1]+n//2-b[1][1],n//2-a[1][1]+n//2-b[0][1]))

Submission status: Accepted

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

if len(counter.values()) == 1:
    print(n // 2)
    exit()

num_cnt = list(counter.items())
num_cnt.sort(key=lambda x: x[1], reverse=True)
max_num = num_cnt[0][0]
second_max_num = num_cnt[1][0]
tmp_ans = 0
for i in range(n):
    if i % 2 == 0 and max_num == lst[i] or \
            i % 2 == 1 and second_max_num == lst[i]:
        continue
    tmp_ans += 1
ans = 0
for i in range(n):
    if i % 2 == 1 and max_num == lst[i] or \
            i % 2 == 0 and second_max_num == lst[i]:
        continue
    ans += 1
print(min(ans, tmp_ans))

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
tmp = list(map(int, input().split()))
# 偶奇で分けて辞書作る
odd = defaultdict(int)
even = defaultdict(int)
for i in range(n):
    if i % 2 == 0:
        odd[tmp[i]] += 1
    else:
        even[tmp[i]] += 1

# 降順ソート
odd = sorted(odd.items(), key=lambda x: -x[1])
even = sorted(even.items(), key=lambda x: -x[1])
# 各配列の最頻，二番目を取ってくる
o1 = odd[0]
e1 = even[0]
# 1種類しかない場合は適当に二番目を作成
if len(odd) != 1:
    o2 = odd[1]
else:
    o2 = (0, 0)
if len(even) != 1:
    e2 = even[1]
else:
    e2 = (0, 0)

# 最多文字が異なる
if o1[0] != e1[0]:
    print(n - (o1[1] + e1[1]))
# 最多文字が同じ
else:
    ans = min((n - (o2[1] + e1[1])), (n - (o1[1] + e2[1])))
    print(ans)

Submission status: Accepted

Solution code:
import collections

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

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

count_even = collections.Counter(even).most_common()
count_sort_even = sorted(count_even, key = lambda x: x[1])[::-1]

count_odd = collections.Counter(odd).most_common()
count_sort_odd = sorted(count_odd, key = lambda x: x[1])[::-1]

if count_sort_even[0][0] != count_sort_odd[0][0]:  ans = N - count_sort_even[0][1] - count_sort_odd[0][1]
    
else:
    if len(count_sort_even) == 1:
        if len(count_sort_odd) == 1:  ans = N // 2
        else:  ans = N - count_sort_even[0][1] - count_sort_odd[1][1]
    elif len(count_sort_odd) == 1:  ans = N - count_sort_even[1][1] - count_sort_odd[0][1]
    else:
        ans1 = N - count_sort_even[1][1] - count_sort_odd[0][1]
        ans2 = N - count_sort_even[0][1] - count_sort_odd[1][1] 
        ans = min(ans1, ans2)    
    
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    N = int(input())
    V = list(map(int, input().split()))
    c0 = Counter(V[::2])
    c1 = Counter(V[1::2])
    cc0 = sorted([(0, 0)] + [(v, k) for k, v in c0.items()], reverse=True)
    cc1 = sorted([(0, 0)] + [(v, k) for k, v in c1.items()], reverse=True)
    m0, v0 = cc0[0]
    m1, v1 = cc1[0]
    if v0 != v1:
        return N - m0 - m1
    return min(N - m0 - cc1[1][0], N - m1 - cc0[1][0])
print(main())

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
odd = Counter(v[0::2])
even = Counter(v[1::2])
odd["$"] = 0
even["#"] = 0
ans = 0
if odd.most_common()[0][0] == even.most_common()[0][0]:
    if odd.most_common()[1][1] > even.most_common()[1][1]:
        ans = n - odd.most_common()[1][1] - even.most_common()[0][1]
    else:
        ans = n - odd.most_common()[0][1] - even.most_common()[1][1]
else:
    ans = n - odd.most_common()[0][1] - even.most_common()[0][1]
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

n = ni()
v = nl()
odd = Counter(v[0::2])
even = Counter(v[1::2])
odd["$"] = 0
even["#"] = 0
ans = 0
if odd.most_common()[0][0] == even.most_common()[0][0]:
    if odd.most_common()[1][1] > even.most_common()[1][1]:
        ans = n - odd.most_common()[1][1] - even.most_common()[0][1]
    else:
        ans = n - odd.most_common()[0][1] - even.most_common()[1][1]
else:
    ans = n - odd.most_common()[0][1] - even.most_common()[0][1]
"""if len(odd) == 1:
    pass
else:
    for v in odd.values():
        max_odd = max(max_odd, v)
    ans += len(odd) - max_odd

if len(even) == 1:
    pass
else:
    for v in even.values():
        max_even = max(max_even, v)
    ans += len(even) - max_even"""

print(ans)

Submission status: Accepted

Solution code:
import collections

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

even = V[::2]
odd = V[1::2]

even_c = collections.Counter(even)
odd_c = collections.Counter(odd)

even_max1_num = 0
even_max1_cnt = 0
even_max2_num = 0
even_max2_cnt = 0
for k, v in even_c.items():
    if v > even_max1_cnt:
        even_max2_cnt = even_max1_cnt
        even_max2_num = even_max1_num
        even_max1_cnt = v
        even_max1_num = k
    elif v > even_max2_cnt:
        even_max2_cnt = v
        even_max2_num = k

odd_max1_num = 0
odd_max1_cnt = 0
odd_max2_num = 0
odd_max2_cnt = 0
for k, v in odd_c.items():
    if v > odd_max1_cnt:
        odd_max2_cnt = odd_max1_cnt
        odd_max2_num = odd_max1_num
        odd_max1_cnt = v
        odd_max1_num = k
    elif v > odd_max2_cnt:
        odd_max2_cnt = v
        odd_max2_num = k

ans = 0
if even_max1_num == odd_max1_num:
    if even_max1_cnt == odd_max1_cnt:
        if even_max2_cnt > odd_max2_cnt:
            ans = N-(even_max2_cnt+odd_max1_cnt)
        else:
            ans = N-(even_max1_cnt+odd_max2_cnt)
    elif even_max1_cnt > odd_max1_cnt:
        ans = N-(even_max1_cnt+odd_max2_cnt)
    else:
        ans = N-(even_max2_cnt+odd_max1_cnt)
else:
    ans = N-(even_max1_cnt+odd_max1_cnt)
print(ans)

Submission status: Accepted

Solution code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
v = LIST()

e = Counter(v[0:n:2])
o = Counter(v[1:n:2])

if e.most_common()[0][0] != o.most_common()[0][0]:
    ans = n - e.most_common()[0][1] - o.most_common()[0][1]
else:
    try:
        tmp0 = n - e.most_common()[0][1] - o.most_common()[1][1]
    except:
        tmp0 = n - e.most_common()[0][1]
    try:
        tmp1 = n - e.most_common()[1][1] - o.most_common()[0][1]
    except:
        tmp1 = n - o.most_common()[0][1]
    ans = min( tmp0, tmp1 )

print( ans )

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
E = []
O = []
for i,v in enumerate(V):
    if i%2==0:
        O.append(v)
    else:
        E.append(v)

cO = Counter(O).most_common(); cO.append((-1,0))
cE = Counter(E).most_common(); cE.append((-1,0))
if cO[0][0]==cE[0][0]: 
    ans = min(n-cO[0][1]-cE[1][1], n-cO[1][1]-cE[0][1])
else:
    ans = n-cO[0][1]-cE[0][1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
v = list(map(int, input().split()))
from collections import Counter
cnt = Counter(v)
ocnt = sorted(Counter(v[::2]).items(), key=lambda x: x[1], reverse=True)
ecnt = sorted(Counter(v[1::2]).items(), key=lambda x: x[1], reverse=True)
if len(cnt) == 1:
    print(n//2)
elif len(ocnt) == 1 and len(ecnt) == 1:
    print(0)
else:
    onum = ocnt[0][1]
    enum = ecnt[0][1]
    if ocnt[0][0] != ecnt[0][0]:
        print(n - onum - enum)
    else:
        if len(ocnt) > 1 and len(ecnt) > 1 and ocnt[1][0] != ecnt[1][0]:
            print(min(n - onum - ecnt[1][1], n - enum - ocnt[1][1], n - ecnt[1][1] - ocnt[1][1]))
        else:
            print(min(n - onum - ecnt[1][1], n - enum - ocnt[1][1]))

Submission status: Accepted

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
a1 = []
a2 = []
for i in range(0,n,1):#スライスで絶対もっときれいにかけるなりねー
    if i%2==0:
        a1.append(v[i])
    if i%2==1:
        a2.append(v[i])

c1 = collections.Counter(a1)#配列を渡す
c2 = collections.Counter(a2)#配列を渡す
if c1.most_common()[0][0]!=c2.most_common()[0][0]:
    print(len(a1) - c1.most_common()[0][1] + len(a2) - c2.most_common()[0][1])#最も出現回数が多いものの出現回数
else:
    c12bannte = c1.most_common()[1][1] if len(c1)>1 else 0
    c22bannte = c2.most_common()[1][1] if len(c2)>1 else 0
    ans = min(len(a1) - c1.most_common()[0][1] + len(a2) - c22bannte,len(a1) - c12bannte + len(a2) - c2.most_common()[0][1])
    print(ans)

Submission status: Accepted

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

from collections import Counter
V_1=V[::2]
V_2=V[1::2]

V_1_counter=Counter(V_1).most_common()
V_2_counter=Counter(V_2).most_common()
# print(V_1_counter,V_2_counter)

V_1_max_1 = V_1_counter[0]
V_1_max_2=(0,0)
if len(V_1_counter)>1:
    V_1_max_2 = V_1_counter[1]
    
V_2_max_1=V_2_counter[0]
V_2_max_2=(0,0)
if len(V_2_counter)>1:
    V_2_max_2 = V_2_counter[1]
    
if V_1_max_1[0] != V_2_max_1[0]:
    ans = N-V_1_max_1[1]-V_2_max_1[1]
    
else:
    ans=N-max(V_1_max_1[1]+V_2_max_2[1],V_1_max_2[1]+V_2_max_1[1])
    
print(ans)

Submission status: Accepted

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

from collections import Counter
V_1=V[::2]
V_2=V[1::2]

V_1_counter=Counter(V_1).most_common()
V_2_counter=Counter(V_2).most_common()
c1 = V_1_counter
c2 = V_2_counter

if c1[0][0]!=c2[0][0]:
    print(n-c1[0][1]-c2[0][1])
if c1[0][0]==c2[0][0]:
    if len(c1)==len(c2)==1:
        print(n//2)
    if len(c1)==1 and len(c2)!=1:
        print(n-c1[0][1]-c2[1][1])
    if len(c2)==1 and len(c1)!=1:
        print(n-c1[1][1]-c2[0][1])    
    if len(c1)>1 and len(c2)>1:    
        print(n-max(c1[1][1]+c2[0][1],c1[0][1]+c2[1][1]))

Submission status: Accepted

Solution code:
from collections import Counter
n,*v = map(int,open(0).read().split())
v1 = Counter(v[::2])
v2 = Counter(v[1::2])
v1 = sorted([(i,v1[i]) for i in v1.keys()],key =lambda x:x[1],reverse=True)
v2 = sorted([(i,v2[i]) for i in v2.keys()],key =lambda x:x[1],reverse=True)
if v1[0][0] != v2[0][0]:
  print(n-v1[0][1]-v2[0][1])
else:
  e1 = n-v2[0][1] if len(v1) == 1 else n-v1[1][1]-v2[0][1]
  e2 = n-v1[0][1] if len(v2) == 1 else n-v1[0][1]-v2[1][1]
  print(min(e1,e2))

Submission status: Accepted

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

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

odd_mx=0
odd_sec=0
even_mx=0
even_sec=0
for i in range(len(odd)):
    if odd[i]>odd_mx:
        odd_sec=odd_mx
        odd_mx=odd[i]
        odd_idx=i
    elif odd[i]>odd_sec:
        odd_sec=odd[i]
for i in range(len(even)):
    if even[i]>even_mx:
        even_sec=even_mx
        even_mx=even[i]
        even_idx=i
    elif even[i]>even_sec:
        even_sec=even[i]

if odd_idx!=even_idx:
    ans=n-(odd_mx+even_mx)
elif odd_mx==even_mx and odd_sec==0 and even_sec==0:
    ans=n//2
else:
    a=max(even_mx+odd_sec,odd_mx+even_sec)
    ans=n-a

print(ans)