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:
import collections
N = int(input())
V = list(map(int, input().split()))

ans = 0
eve = V[0::2]
odd = V[1::2]
cntEve = collections.Counter(eve)
cntOdd = collections.Counter(odd)

if cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]:
    if len(cntEve) == 1 and len(cntOdd) > 1:
        ans = N - max(cntEve.most_common()[0][1],cntOdd.most_common()[0][1]) - cntOdd.most_common()[1][1]
    elif len(cntEve) > 1 and len(cntOdd) == 1:
        ans = N - max(cntEve.most_common()[0][1],cntOdd.most_common()[0][1]) - cntEve.most_common()[1][1]
    elif len(cntEve) == 1 and len(cntOdd) == 1:
        ans = N - max(cntEve.most_common()[0][1],cntOdd.most_common()[0][1])
    else:
        ans = N - max(cntEve.most_common()[0][1],cntOdd.most_common()[0][1]) - max(cntEve.most_common()[1][1],cntOdd.most_common()[1][1])
else:
    ans = N - int(cntEve.most_common()[0][1]) - int(cntOdd.most_common()[0][1])

print(ans)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
#import numpy as np
#import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()

cnt_even = Counter(a[::2]).most_common()+[(0,0)]
cnt_odd = Counter(a[1::2]).most_common()+[(0,0)]

ans = 0
if cnt_even[0][0] == cnt_odd[0][0]:
  ans = n - max(cnt_even[0][1],cnt_odd[0][1]) - max(cnt_even[1][1],cnt_odd[1][1])
else:
  ans = n - cnt_even[0][1] - cnt_odd[0][1]

print(ans)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
#import numpy as np
#import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()

cnt_even = defaultdict(int)
cnt_odd = defaultdict(int)
for i in range(0,n,2):
  cnt_even[a[i]] += 1
for i in range(1,n,2):
  cnt_odd[a[i]] += 1

cnt_even = list(reversed(sorted(cnt_even.items(),key=lambda x:x[1])))
cnt_odd  = list(reversed(sorted(cnt_odd.items(),key=lambda x:x[1])))

flg = False
for i in range(min(2,len(cnt_even),len(cnt_odd))):
  a,b = (cnt_even[i],cnt_odd[i])
  if a[0] != b[0]:
    if flg == False:
      n -= a[1]+b[1]
    else:
      n -= max(a[1],b[1])
    break
  else:
    n -= a[1]
    flg = True

print(n)

Submission status: Accepted

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

A={0:0}
B={0:0}
for i in range(N):
    v=V[i]
    if i%2==0:
        if v in A:
            A[v]+=1
        else:
            A[v]=1
    else:
        if v in B:
            B[v]+=1
        else:
            B[v]=1

P=max(A,key=lambda x:A[x])
Q=max(B,key=lambda x:B[x])

if P!=Q:
    print(N-(A[P]+B[Q]))
else:
    X=A[P]
    del A[P]
    R=max(A,key=lambda x:A[x])

    Y=B[Q]
    del B[Q]
    S=max(B,key=lambda x:B[x])

    print(N-max(X+A[R],Y+B[S]))

Submission status: Accepted

Solution code:
from collections import defaultdict
ODD = defaultdict(int)
EVEN = defaultdict(int)
ALL = set([])
N = int(input())

A = list(map(int,input().split()))
for i in range(N):
  ALL.add(A[i])
  if i%2 == 0:
    EVEN[A[i]] += 1
  else:
    ODD[A[i]] += 1
if len(ALL) == 1:
  ans = N//2
  print(ans)
  exit()
modd = max(ODD.values())
meven = max(EVEN.values())
mlodd = [];mleven = []
dicodd = sorted(ODD.items(), key=lambda x:x[1], reverse = True)
diceven = sorted(EVEN.items(), key=lambda x:x[1], reverse = True)
ans = N
if len(dicodd) > 1:
  X = [dicodd[0],dicodd[1]]
else:
  X = [dicodd[0]]
if len(diceven) > 1:
  Y = [diceven[0],diceven[1]]
else:
  Y = [diceven[0]]
#print(X)
#print(Y)
for x,v in X:
  for y,w in Y:
    if x == y:
      continue
    temp = N-(v+w)
    ans = min(ans,temp)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()//2
lis=LI()
lis1=[]
lis2=[]
for i in range(n):
    lis1.append(lis[2*i])
    lis2.append(lis[2*i+1])
x=Counter(lis1).most_common(2)
y=Counter(lis2).most_common(2)
#print(x)
#print(y)
if len(x)==1:
    x.append((0,0))
if len(y)==1:
    y.append((-1,0))
#print(x)
#print(y)
if x[0][0]!=y[0][0]:
    print(2*n-x[0][1]-y[0][1])
else:
    cands=[]
    #print(2*n-x[0][1]-y[1][]))
    if x[1][0]!=y[0][0]:
        cands.append(2*n-x[1][1]-y[0][1])
    if x[0][0]!=y[1][0]:
        cands.append(2*n-x[0][1]-y[1][1])
    if x[1][0]!=y[1][0]:
        cands.append(2*n-x[1][1]-y[1][1])
    print(min(cands))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
V = list(map(int,input().split()))
Ce = {}
Co = {}
for i in range(n):
    v = V[i]
    if i%2==0:
        if v not in Ce:
            Ce[v]=0
        Ce[v] += 1
    else:
        if v not in Co:
            Co[v]=0
        Co[v] += 1
Ce = sorted(list(Ce.items()),key=lambda x:x[1],reverse=True)
Co = sorted(list(Co.items()),key=lambda x:x[1],reverse=True)
if Ce[0][0]!=Co[0][0]:
    cnt = 0
    for i in range(1,len(Ce)):
        cnt += Ce[i][1]
    for i in range(1,len(Co)):
        cnt += Co[i][1]
    print(cnt)
else:
    cnt1 = 0
    for i in range(1,len(Ce)):
        cnt1 += Ce[i][1]
    if Ce[0][1]>n//2:
        cnt1 += Ce[0][1]-n//2
    cnt1 += Co[0][1]
    for i in range(2,len(Co)):
        cnt1 += Co[i][1]
    cnt2 = 0
    for i in range(1,len(Co)):
        cnt2 += Co[i][1]
    if Co[0][1]>n//2:
        cnt2 += Co[0][1]-n//2
    cnt2 += Ce[0][1]
    for i in range(2,len(Ce)):
        cnt2 += Ce[i][1]
    print(min(cnt1,cnt2))

Submission status: Accepted

Solution code:
from collections import Counter
from heapq import heappop,heappush

N = int(input())
V = list(map(int, input().split()))
odd = Counter(V[::2])
odd[10**6] = 0
even = Counter(V[1::2])
even[10**6] = 0
heapodd = []
heapeven = []
for k,v in odd.items():
    heappush(heapodd,(-v,k))
for k,v in even.items():
    heappush(heapeven,(-v,k))

vo1,odd1 = heappop(heapodd)
vo2,odd2 = heappop(heapodd)
ve1,even1 = heappop(heapeven)
ve2,even2 = heappop(heapeven)

if odd1 != even1:
  print(N + vo1 + ve1)
else:
  print(min(N+ve1+vo2,N+vo1+ve2))

Submission status: Accepted

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

zero_d = {}
one_d = {}
for i,v in enumerate(vl):
    if i%2 == 0:
        zero_d.setdefault(v,0)
        zero_d[v] += 1
    else:
        one_d.setdefault(v,0)
        one_d[v] += 1

zero_l = sorted(zero_d.items(), reverse=True, key=lambda x:x[1])
one_l = sorted(one_d.items(), reverse=True, key=lambda x:x[1])


zero_l.append((-1,0))
one_l.append((-1,0))

zero_cnt = (n+1)//2
one_cnt = n//2
if zero_l[0][0] != one_l[0][0]:
    ans = n - zero_l[0][1] - one_l[0][1]
else:
    ans1 = n - zero_l[0][1] - one_l[1][1]
    ans2 = n - zero_l[1][1] - one_l[0][1]
    ans = min(ans1,ans2)

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

n = int(input())
v = list(map(int, input().split()))
cnt1 = Counter([v[i] for i in range(n) if i%2==0])
cnt2 = Counter([v[i] for i in range(n) if i%2==1])
cnt1[-1] = 0
cnt2[-1] = 0
k1 = [k for k in cnt1.keys()]
k1.sort(key=lambda x: cnt1[x], reverse=True)
k2 = [k for k in cnt2.keys()]
k2.sort(key=lambda x: cnt2[x], reverse=True)

if k1[0]!=k2[0]:
    print(n-cnt1[k1[0]]-cnt2[k2[0]])
else:
    print(min(n-cnt1[k1[0]]-cnt2[k2[1]], n-cnt1[k1[1]]-cnt2[k2[0]]))

Submission status: Accepted

Solution code:
from collections import Counter
def solve():
  ans = 0
  N = int(input())
  V = list(map(int, input().split()))
  V1 = [V[i] for i in range(0,N,2)]
  V2 = [V[i] for i in range(1,N,2)]
  v1 = Counter(V1)
  v2 = Counter(V2)
  v1 = sorted(v1.items(),key=lambda x:-x[1])
  v2 = sorted(v2.items(),key=lambda x:-x[1])
  if v1[0][0]!=v2[0][0]:
    ans = N-(v1[0][1]+v2[0][1])
  else:
    if len(v1)==1:
      if len(v2)==1:
        return N//2
      return N-(v1[0][1]+v2[1][1])
    if len(v2)==1:
      return N-(v1[1][1]+v2[0][1])
    ans = N-max(v1[1][1]+v2[0][1],v1[0][1]+v2[1][1])
  return ans
print(solve())

Submission status: Accepted

Solution code:
from collections import *
n = int(input())
v = list(map(int,input().split()))
if len(set(v))==1:
    print(len(v)//2)
    exit()
n_even = v[0::2]
n_odd = v[1::2]
a = Counter(n_even).most_common()+[(0,0)]
b = Counter(n_odd).most_common()+[(0,0)]
#print(a)
#print(b)
if a[0][0] == b[0][0]:
    ans = min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1])
else:
    ans = n - a[0][1] - b[0][1]
print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
v = list(map(int,input().split()))
v1,v2 = v[::2],v[1::2]
A1 = collections.Counter(v1)
A2 = collections.Counter(v2)
B = list(A1.values())
C = list(A2.values())
B.sort(reverse=True)
C.sort(reverse=True)

if A1.most_common()[0][0] == A2.most_common()[0][0]:
    if len(A1) == 1:
        ans = N//2
    else:
        if B[1] > C[1]: ans = N//2 - B[0] + N//2 - B[1]
        else: ans = N//2 - B[0] + N//2 - C[1]

else:
    ans = N//2 - B[0] + N//2 - C[0]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
odd = []
even = []
for i in range(n//2):
    odd.append(l[2*i])
    even.append(l[2*i+1])
c_odd = list(Counter(odd).items()) + [(-1,0)]
c_even = list(Counter(even).items()) + [(-1,0)]
c_odd = sorted(c_odd, key=lambda x:-x[1])
c_even = sorted(c_even, key=lambda x:-x[1])

c_odd = c_odd[:2]
c_even = c_even[:2]
# print(c_odd,c_even)

if c_odd[0][0] != c_even[0][0]:
    print(n-c_odd[0][1]-c_even[0][1])
    exit()
else:
    print(n-c_odd[0][1]-max(c_odd[1][1],c_even[1][1]))

Submission status: Accepted

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

from collections import*
C1=Counter(V[::2]).most_common()+[(0,0)]
C2=Counter(V[1::2]).most_common()+[(0,0)]

K1=C1[0][0]
V1=C1[0][1]
K2=C2[0][0]
V2=C2[0][1]
if K1==K2:
    if V1>V2:
        V2=C2[1][1]
    elif V2>V1:
        V1=C[1][1]
    else:
        V2=max(C1[1][1],C2[1][1])

print(N-V1-V2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter

n, *v = map(int, open(0).read().split())
odd = [v[i] for i in range(0, n, 2)]
even = [v[i] for i in range(1, n, 2)]
o = Counter(odd)
e = Counter(even)

if o.most_common()[0][0] != e.most_common()[0][0]:
    print(n - o.most_common()[0][1] - e.most_common()[0][1])
else:
    a = n - o.most_common()[0][1] - max(sorted(e.values())[:-1] + [0])
    b = n - e.most_common()[0][1] - max(sorted(o.values())[:-1] + [0])
    print(min(a, b))

Submission status: Accepted

Solution code:
n=int(input())
v=list(map(int,input().split()))
numg=[]
numk=[]
for i in range(n):
    if i%2==0:
        numk.append(v[i])
    else:
        numg.append(v[i])
numk.sort()
numg.sort()
numk2=[]
numg2=[]
num1=0
cnt=0
for i in range(len(numk)):
    if num1!=numk[i]:
        numk2.append([num1,cnt])
        num1=numk[i]
        cnt=1
    else:
        cnt+=1
numk2.append([num1,cnt])
num1=0
cnt=0
for i in range(len(numg)):
    if num1!=numg[i]:
        numg2.append([num1,cnt])
        num1=numg[i]
        cnt=1
    else:
        cnt+=1
numg2.append([num1,cnt])
str1= lambda val: val[1]
numg2.sort(key=str1)
numk2.sort(key=str1)
if numg2[-1][0]==numk2[-1][0]:
    print(n-max(numg2[-1][1]+numk2[-2][1],numg2[-2][1]+numk2[-1][1]))
else:
    print(n-(numg2[-1][1]+numk2[-1][1]))

Submission status: Accepted

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

from collections import*
C1=Counter(V[::2]).most_common()+[(0,0)]
C2=Counter(V[1::2]).most_common()+[(0,0)]

K1=C1[0][0]
V1=C1[0][1]
K2=C2[0][0]
V2=C2[0][1]
if K1==K2:
    if V1>V2:
        V2=C2[1][1]
    elif V2>V1:
        V1=C[1][1]
    else:
        V2=max(C1[1][1],C2[1][1])

print(N-V1-V2)

Submission status: Accepted

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

from collections import*
C1=Counter(V[::2])
C1=sorted(C1.items(),key=lambda x:x[1])
C2=Counter(V[1::2])
C2=sorted(C2.items(),key=lambda x:x[1])

K1=C1[-1][0]
V1=C1[-1][1]
K2=C2[-1][0]
V2=C2[-1][1]
if V1>V2:
    if K1==K2:
        V2=C2[-2][1]
elif V2>V1:
    if K1==K2:
        V1=C1[-2][1]
else:
    if K1==K2:
        if len(set(V))==1:
            V2=0
        else:
            V2=max(C1[-2][1],C2[-2][1])

print(N-V1-V2)

Submission status: Accepted

Solution code:
import copy

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

la = [0 for i in range(5+10**5)]
lb = [0 for i in range(5+10**5)]

for i in range(0, n, 2):
    la[v[i]] += 1
for i in range(1, n, 2):
    lb[v[i]] += 1

# print(sum(la))
# print(sum(lb))
# print(max(la))
# print(max(lb))
# print(la.index(max(la)))
# print(lb.index(max(lb)))

sla = sum(la)
slb = sum(lb)
maxla = max(la)
maxlb = max(lb)
argmaxla = la.index(max(la))
argmaxlb = lb.index(max(lb))

if argmaxla != argmaxlb:
    if sla-maxla == 0 and slb-maxlb == 0:
        print(0)
    else:
        print(sla-maxla+slb-maxlb)
else:
    # laの2番目に大きい値を使う
    _la = copy.deepcopy(la)
    _la[argmaxla] = 0
    _maxla = max(_la)
    aa = sla-_maxla+slb-maxlb
    # lbの2番目に大きい値を使う
    _lb = copy.deepcopy(lb)
    _lb[argmaxlb] = 0
    _maxlb = max(_lb)
    bb = sla-maxla+slb-_maxlb
    if bb > aa:
        print(aa)
    else:
        print(bb)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
V = list(map(int, input().split()))
_n = n // 2
C0 = Counter()
C1 = Counter()
for i in range(n):
    if i % 2 == 0:
        C0[V[i]] += 1
    else:
        C1[V[i]] += 1
C0 = C0.most_common()
C1 = C1.most_common()
if C0[0][0] == C1[0][0]:
    if len(C0) == 1 and len(C1) == 1:
        print(_n)
    elif C0[0][1] == C1[0][1]:
        if C0[1][1] <= C1[1][1]:
            print(abs(C0[0][1] - _n) + abs(C1[1][1] - _n))
        else:
            print(abs(C0[1][1] - _n) + abs(C1[0][1] - _n))
    else:
        if C0[0][1] < C1[0][1]:
            print(abs(C0[1][1] - _n) + abs(C1[0][1] - _n))
        else:
            print(abs(C0[0][1] - _n) + abs(C1[1][1] - _n))
else:
    print(abs(C0[0][1] - _n) + abs(C1[0][1] - _n))

Submission status: Accepted

Solution code:
from collections import Counter

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

e=Counter(v[0::2])
o=Counter(v[1::2])
e_key=sorted(e.items(),reverse=True,key=lambda x:x[1])
o_key=sorted(o.items(),reverse=True,key=lambda x:x[1])

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

Submission status: Accepted

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

import collections

if len(set(V)) == 1:
  print(N//2)
else:
  evens = [V[n] for n in range(0,N,2)]
  odds = [V[n] for n in range(1,N,2)]
  
  c_evens = collections.Counter(evens).most_common()
  c_odds = collections.Counter(odds).most_common()
  
  mode_in_evens = c_evens[0][0]
  mode_number_in_evens = c_evens[0][1]
  
  mode_in_odds = c_odds[0][0]
  mode_number_in_odds = c_odds[0][1]
  
  ans = N - (mode_number_in_evens+mode_number_in_odds)
  
  if mode_in_evens == mode_in_odds:
    if len(c_evens) != 1:
      second_mode_number_in_evens = c_evens[1][1]
    else:
      second_mode_number_in_evens = 0
    ans_candidate_1 = N - (second_mode_number_in_evens+mode_number_in_odds)      
      
    if len(c_odds) != 1:
      second_mode_number_in_odds = c_odds[1][1]
    else:
      second_mode_number_in_odds = 0
    ans_candidate_2 = N - (mode_number_in_evens+second_mode_number_in_odds) 
    
    ans = min(ans_candidate_1,ans_candidate_2)
    
  print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
v1 = []
v2 = []
for i in range(n):
    if i % 2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])
c1 = collections.Counter(v1)
c2 = collections.Counter(v2)
c1Common = c1.most_common(2)
c2Common = c2.most_common(2)
answer = 0
if c1Common[0][0] != c2Common[0][0]:
    c1Count = n // 2 - c1Common[0][1]
    c2Count = n // 2 - c2Common[0][1]
    answer = c1Count + c2Count
else:
    c1Count = n // 2 - c1Common[0][1]
    c2Count = n // 2 - c2Common[0][1]
    if len(c1Common) > 1:
        c1Count2 = n // 2 - c1Common[1][1]
    else:
        c1Count2 = n // 2
    if len(c2Common) > 1:
        c2Count2 = n // 2 - c2Common[1][1]
    else:
        c2Count2 = n // 2
    case1 = c1Count + c2Count2
    case2 = c2Count + c1Count2
    if case1 < case2:
        answer = case1
    else:
        answer = case2
print(answer)

Submission status: Accepted

Solution code:
import collections
import sys
n = int(input())
a = list(map(int,input().split()))
if len(set(a)) == 1:
  print(n//2)
  sys.exit()
a1 = [a[x] for x in range(0,n,2)]
l_a1 = len(a1)
a2 = [a[y] for y in range(1,n,2)]
l_a2 = len(a2)
c1 = collections.Counter(a1)
c2 = collections.Counter(a2)
K_a1 = c1.most_common()[0][0]
K_a2 = c2.most_common()[0][0]
F_a1 = c1.most_common()[0][1]
F_a2 = c2.most_common()[0][1]
if K_a1 == K_a2:
  if  F_a1 > F_a2:
    F_a2 = c2.most_common()[1][1]
  elif F_a1 == F_a2:
    if  c1.most_common()[1][1] >  c2.most_common()[1][1]:
      F_a1 =  c1.most_common()[1][1]
    else:
      F_a2 =  c2.most_common()[1][1]
  else:
    F_a1 = c1.most_common()[1][1]
print((l_a1 - F_a1)+(l_a2 - F_a2))

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc111/tasks/arc103_a
from collections import Counter
n = int(input())
nums = [int(i) for i in input().split()]

odd = Counter(nums[1::2]).most_common()
even = Counter(nums[::2]).most_common()
odd.append((0, 0))
even.append((0, 0))
if odd[0][0] != even[0][0]:
    ans = n - (odd[0][1] + even[0][1])
else:
    s = n - (odd[0][1] + even[1][1])
    t = n - (odd[1][1] + even[0][1])
    ans = min(s, t)
print(ans)
'''
6
1 1 1 1 2 1
'''

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
cv1 = Counter(V[::2]).most_common()
cv2 = Counter(V[1::2]).most_common()
cv1.append((-1,0)); cv2.append((-1,0))
if cv1[0][0] != cv2[0][0]:
    print(n-cv1[0][1]-cv2[0][1])
else:
    print(min(n-cv1[1][1]-cv2[0][1], n-cv1[0][1]-cv2[1][1]))

Submission status: Accepted

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

d0 = {-1: 0}
for a in la[::2]:
    d0[a] = d0.get(a, 0) + 1
d1 = {-1: 0}
for a in la[1::2]:
    d1[a] = d1.get(a, 0) + 1

n0 = sorted([(v, k) for k, v in d0.items()], reverse=True)
n1 = sorted([(v, k) for k, v in d1.items()], reverse=True)


if n0[0][1] != n1[0][1]:
    answer = n - n0[0][0] - n1[0][0]
else:
    if n0[1][0] > n1[1][0]:
        answer = n - n0[1][0] - n1[0][0]
    else:
        answer = n - n0[0][0] - n1[1][0]


print(answer)

Submission status: Accepted

Solution code:
n = int(input())
v = [i for i in input().split()]
v1 = {}
v2 = {}
for i in range(n//2):
    if  v[2 *i +1] in v1.keys():
        v1[v[2 * i +1]] += 1
    else:
        v1[v[2 * i + 1]] = 1

    if v[2 * i] in v2.keys():
        v2[v[2 * i]] += 1
    else:
        v2[v[2 * i]] = 1
v1 = sorted(v1.items(),key=lambda x:  x[1])
v2 = sorted(v2.items(),key=lambda x:  x[1])
v1.reverse()
v2.reverse()
v1.append((None,0))
v2.append((None,0))
#print(v1)
if v1[0][0] == v2[0][0]:
    ans = max(v1[0][1]+v2[1][1] , v1[1][1] + v2[0][1])
else:
    ans = v1[0][1] + v2[0][1]
print(n - ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
V = [int(X) for X in input().split()]

if len(set(V))==1:
    print(N//2)
else:
    OddV  = V[::2]
    EvenV = V[1::2]
    LenOddV  = len(set(OddV))
    LenEvenV = len(set(EvenV))
    if LenOddV==1 and LenEvenV==1:
        NOddV  = OddV[0]
        NEvenV = EvenV[0]
        print(0)
    elif LenOddV!=1 and LenEvenV==1:
        OddCount = collections.Counter(OddV)
        NEvenV   = EvenV[0]
        if OddCount.most_common()[0][0]==NEvenV:
            NOddV = OddCount.most_common()[1][0]
            print(N//2-OddCount.most_common()[1][1])
        else:
            NOddV = OddCount.most_common()[0][0]
            print(N//2-OddCount.most_common()[0][1])
    elif LenOddV==1 and LenEvenV!=1:
        NOddV     = OddV[0]
        EvenCount = collections.Counter(EvenV)
        if EvenCount.most_common()[0][0]==NOddV:
            NEvenV = EvenCount.most_common()[1][0]
            print(N//2-EvenCount.most_common()[1][1])
        else:
            NEvenV = EvenCount.most_common()[0][0]
            print(N//2-EvenCount.most_common()[0][1])
    elif LenOddV!=1 and LenEvenV!=1:
        OddCount  = collections.Counter(OddV)
        EvenCount = collections.Counter(EvenV)
        if OddCount.most_common()[0][0]!=EvenCount.most_common()[0][0]:
            NOddV  = OddCount.most_common()[0][0]
            NEvenV = EvenCount.most_common()[0][0]
            print(N-OddCount.most_common()[0][1]-EvenCount.most_common()[0][1])
        else:
            if OddCount.most_common()[0][1]>EvenCount.most_common()[0][1]:
                NOddV  = OddCount.most_common()[0][0]
                NEvenV = EvenCount.most_common()[1][0]
                print(N-OddCount.most_common()[0][1]-EvenCount.most_common()[1][1])
            elif OddCount.most_common()[0][1]<EvenCount.most_common()[0][1]:
                NOddV  = OddCount.most_common()[1][0]
                NEvenV = EvenCount.most_common()[0][0]
                print(N-OddCount.most_common()[1][1]-EvenCount.most_common()[0][1])
            else:
                if OddCount.most_common()[1][1]>=EvenCount.most_common()[1][1]:
                    NOddV  = OddCount.most_common()[1][0]
                    NEvenV = EvenCount.most_common()[0][0]
                    print(N-OddCount.most_common()[1][1]-EvenCount.most_common()[0][1])
                elif OddCount.most_common()[1][1]<EvenCount.most_common()[1][1]:
                    NOddV  = OddCount.most_common()[0][0]
                    NEvenV = EvenCount.most_common()[1][0]
                    print(N-OddCount.most_common()[0][1]-EvenCount.most_common()[1][1])

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Vs = list(mapint())

even = []
odd = []
for i in range(N):
    if i%2==1:
        even.append(Vs[i])
    else:
        odd.append(Vs[i])

from collections import Counter
ceven = Counter(even)
ans = 0
even_second = 0
for i, (num, cnt) in enumerate(ceven.most_common()):
    if i==0:
        even_most = cnt
        even_num = num
    if i==1:
        even_second = cnt
    ans += cnt
codd = Counter(odd)
odd_second = 0
for i, (num, cnt) in enumerate(codd.most_common()):
    if i==0:
        odd_most = cnt
        odd_num = num
    if i==1:
        odd_second = cnt
    ans += cnt

if even_num==odd_num:
    ans = min(ans-odd_most-even_second, ans-odd_second-even_most)
else:
    ans -= odd_most+even_most
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    n = int(input())
    vs = [int(item) for item in input().split()]
    num_max = max(vs)

    cnt_od = collections.Counter(vs[::2])
    cnt_ev = collections.Counter(vs[1::2])

    cnt_od = cnt_od.most_common()
    cnt_ev = cnt_ev.most_common()

    if cnt_od[0][0] == cnt_ev[0][0]:
        if (len(cnt_od)>1) and (len(cnt_ev)>1):
            ans = min(n - cnt_od[1][1] - cnt_ev[0][1], n - cnt_od[0][1] - cnt_ev[1][1])
        elif len(cnt_od) > 1:
            ans = n//2 - cnt_od[1][1]
        elif len(cnt_ev) > 1:
            ans = n//2 - cnt_ev[1][1]
        else:
            ans = n//2
    else:
        ans = n - cnt_ev[0][1] - cnt_od[0][1]

    print(ans)
if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
def main():
    from collections import Counter
    n = int(input())
    V = map(int,input().split())
    odds = []
    evens = []
    for i,v in enumerate(V):
        if i & 1:
            evens.append(v)
        else:
            odds.append(v)
    
    odds_modes= Counter(odds).most_common(2)
    evens_modes = Counter(evens).most_common(2)

    if odds_modes[0][0] != evens_modes[0][0]:
        print(len(odds)- odds_modes[0][1] + len(evens) - evens_modes[0][1])
    else:
        odds_modes.append((-1,0))
        evens_modes.append((-1,0))

        print(
            min(
                len(odds)-odds_modes[0][1] + len(evens) - evens_modes[1][1],
                len(odds)-odds_modes[1][1] + len(evens) - evens_modes[0][1],
            )
        )
            

main()

Submission status: Accepted

Solution code:
def main():
    from collections import Counter
    n = int(input())
    V = map(int,input().split())
    odds = []
    evens = []
    for i,v in enumerate(V):
        if i & 1:
            evens.append(v)
        else:
            odds.append(v)
    
    odds_counter = list(Counter(odds).items())
    eves_counter = list(Counter(evens).items())
    
    odds_counter.sort(reverse=True, key= lambda x: x[1])
    eves_counter.sort(reverse=True, key= lambda x: x[1])

    if odds_counter[0][0] != eves_counter[0][0]:
        print(len(odds)- odds_counter[0][1] + len(evens) - eves_counter[0][1])
    else:
        odds_counter.append((-1,0))
        eves_counter.append((-1,0))

        print(
            min(
                len(odds)-odds_counter[0][1] + len(evens) - eves_counter[1][1],
                len(odds)-odds_counter[1][1] + len(evens) - eves_counter[0][1],
            )
        )
            
        

    

    
    
    


main()

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
X = list(map(int, input().split()))
A = Counter(X[::2]).most_common()
B = Counter(X[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[0][1]-B[1][1], n-A[1][1]-B[0][1]))

Submission status: Accepted

Solution code:
from collections import *
N = int(input())
V = list(map(int,input().split()))
E = Counter(V[0::2]).most_common()+[(0,0)]
O = Counter(V[1::2]).most_common()+[(0,0)]

if E[0][0]!=O[0][0]:
  print(N-E[0][1]-O[0][1])
else:
  print(N-max(E[0][1]+O[1][1],E[1][1]+O[0][1]))

Submission status: Accepted

Solution code:
from collections import *
N = int(input())
V = list(map(int,input().split()))
C1 = Counter(V[0::2]).most_common()
C2 = Counter(V[1::2]).most_common()

if len(set(V))==1:
  ans = N//2
else:
  if C1[0][0]==C2[0][0]:
    ans = min(N-C1[0][1]-C2[1][1],N-C1[1][1]-C2[0][1])
  else:
    ans = N-C1[0][1]-C2[0][1]

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
lst = list(map(int, input().split()))
odd = Counter(lst[::2])
even = Counter(lst[1::2])
#print(odd, even)
omax = odd.most_common()[0]
emax = even.most_common()[0]
if len(odd) >= 2:
  osec = odd.most_common()[1]
if len(even) >= 2:
  esec = even.most_common()[1]
#print(omax, emax)

if omax[0] == emax[0]:
  if len(even) == 1 and len(odd) == 1:
    print(n // 2)
  elif len(even) == 1:
    print(n - emax[1] - osec[1])
  elif len(odd) == 1:
    print(n - omax[1] - esec[1])
  else:
    print(min(n - emax[1] - osec[1], n - omax[1] - esec[1]))
else:
  print(n - omax[1] - emax[1])

Submission status: Accepted

Solution code:
n = int(input())
v = list(map(int, input().split()))
from collections import Counter
odd_ary = v[::2]
even_ary = v[1::2]

# 最頻値top2
oc = Counter(odd_ary).most_common(2)
ec = Counter(even_ary).most_common(2)

if len(oc) == 1:
    oc.append((0, 0))
if len(ec) == 1:
    ec.append((0, 0))

if oc[0][0] != ec[0][0]:
    print(n - (oc[0][1] + ec[0][1]))
else:
    print(n - max(oc[0][1] + ec[1][1], oc[1][1] + ec[0][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
v1.append([0,0])
v2.append([0,0])
if v1[0][0]!=v2[0][0]:
  ans=n-v1[0][1]-v2[0][1]
else:
  ans=min(n-v1[1][1]-v2[0][1],n-v1[0][1]-v2[1][1])
print(ans)