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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
n = N//2
l = IL()

l1 = l[::2]
l2 = l[1::2]

dic1 = DD(int)
dic2 = DD(int)

for x in l1:
  dic1[x] += 1
for x in l2:
  dic2[x] += 1
  
l1 = list(dic1.items())
l2 = list(dic2.items())

l1 = sorted(l1,key=lambda x:x[1])
l2 = sorted(l2,key=lambda x:x[1])

l1_1st = l1.pop()
l2_1st = l2.pop()
l1_2nd = l2_2nd = (INF,0)

if l1:
  l1_2nd = l1.pop()
if l2:
  l2_2nd = l2.pop()
  
if l1_1st[0] != l2_1st[0]:
  print(N-l1_1st[1]-l2_1st[1])
else:
  if l1_2nd[1]>l2_2nd[1]:
    print(N-l1_2nd[1]-l2_1st[1])
  else:
    print(N-l1_1st[1]-l2_2nd[1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(n: int, v: "List[int]"):
    from collections import Counter
    a = Counter(v[::2]).most_common()
    b = Counter(v[1::2]).most_common()
    if a[0][0] != b[0][0]:
        return n - a[0][1] - b[0][1]
    a = a + [(0, 0)]
    b = b + [(0, 0)]
    return n - max(a[0][1] + b[1][1],
                   a[1][1] + b[0][1])


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    print(solve(n, v))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(n: int, v: "List[int]"):
    from collections import Counter
    a = sorted(Counter(v[::2]).items(), key=lambda x: (x[1], x[0]))
    b = sorted(Counter(v[1::2]).items(), key=lambda x: (x[1], x[0]))
    if a[-1][0] != b[-1][0]:
        return n - a[-1][1] - b[-1][1]
    a = [(0, 0)] + a
    b = [(0, 0)] + b
    return n - max(a[-1][1] + b[-2][1],
                   a[-2][1] + b[-1][1])


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    print(solve(n, v))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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

    from collections import Counter
    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])))
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

n=int(input())
l=[int(i) for i in input().split()]
n=len(l)
l1=l[0::2]
l2=l[1::2]
c1=Counter(l1).most_common(2)
c2=Counter(l2).most_common(2)

if c1[0][0]!=c2[0][0]:
    ans=n-c1[0][1]-c2[0][1]
    print(int(ans))
else:
    if len(c1)==1 or len(c2)==1:
        print(n//2)
    else:
        res1=n-c1[1][1]-c2[0][1]
        res2=n-c1[0][1]-c2[1][1]
        ans=min(res1,res2)
        print(int(ans))

Submission status: Accepted

Solution code:
n=int(input())
v=list(map(int,input().split()))
temp1=[]
temp2=[]
for i in range(0,n):
  if i%2==0:
    temp1.append(v[i])
  else:
    temp2.append(v[i])
count=0
from collections import Counter
c1=Counter(temp1)
values1,counts1=zip(*c1.most_common())
counts1=list(counts1)
mode1=counts1[0]
if len(counts1)>1:
  mode1s=counts1[1]
c2=Counter(temp2)
values2,counts2=zip(*c2.most_common())
counts2=list(counts2)
mode2=counts2[0]
if len(counts2)>1:
  mode2s=counts2[1]
if len(counts1)==1 and len(counts2)==1 and c1.most_common()[0][0]==c2.most_common()[0][0]:
  count=min(mode1,mode2)
elif c1.most_common()[0][0]==c2.most_common()[0][0]:
  if len(temp1)-mode1s>=len(temp2)-mode2s:
    count=len(temp1)-mode1+len(temp2)-mode2s
  else:
    count=len(temp2)-mode2+len(temp1)-mode1s
else:
  count=len(temp1)-mode1+len(temp2)-mode2
print(count)

Submission status: Accepted

Solution code:
from collections import Counter
import heapq

n = int(input())
v = list(map(int, input().split()))
o = [x for x in v[0:n:2]]
e = [x for x in v[1::2]]
oc = Counter(o)
ec = Counter(e)
ocfreq = [(x[1]*(-1),x[0]) for x in oc.items()]
ecfreq = [(x[1]*(-1),x[0]) for x in ec.items()]
heapq.heapify(ocfreq)
heapq.heapify(ecfreq)
o1 = heapq.heappop(ocfreq)
e1 = heapq.heappop(ecfreq)
if o1[1] != e1[1]:
    print(n+o1[0]+e1[0])
else:
    if len(ocfreq) == 0 and len(ecfreq) == 0:
        print(n//2)
    elif len(ocfreq) == 0:
        e2 = heapq.heappop(ecfreq)
        print((n//2)+e2[0])
    elif len(ecfreq) == 0:
        o2 = heapq.heappop(ocfreq)
        print((n//2)+o2[0])
    else:
        e2 = heapq.heappop(ecfreq)
        o2 = heapq.heappop(ocfreq)
        print(n+min(o1[0]+e2[0],o2[0]+e1[0]))

Submission status: Accepted

Solution code:
def main():
    n, *v = map(int, open(0).read().split())
    be = [0] * int(1e5)
    bo = [0] * int(1e5)
    for e, o in zip(*[iter(v)] * 2):
        be[e - 1] += 1
        bo[o - 1] += 1
    ve = max(be)
    vo = max(bo)
    ke = be.index(ve)
    ko = bo.index(vo)
    if ke == ko:
        be[ke] = 0
        bo[ko] = 0
        print(min(n - ve - max(bo), n - vo - max(be)))
    else:
        print(n - ve - vo)
    return


main()

Submission status: Accepted

Solution code:
from collections import Counter

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

if len(set(V)) == 1:
    print(len(V)//2)
    exit()

V_odd = [i for i in V[::2]]
V_even = [i for i in V[1::2]]
V_odd_counter = Counter(V_odd)
V_even_counter = Counter(V_even)

vodd = V_odd_counter.most_common()
veven = V_even_counter.most_common()
vlen = len(V)
while True:
    if vodd[0][0] != veven[0][0]:
        print(vlen - vodd[0][1] - veven[0][1])
        exit()
    else:
        print(min(vlen - vodd[1][1] - veven[0][1],
                    vlen - vodd[0][1] - veven[1][1]))
        exit()

Submission status: Accepted

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

if len(set(v)) == 1:
    print(len(v)//2)
else:
    from collections import Counter
    ve = v[0::2]
    vec = Counter(ve).most_common()
    most_even = vec[0]

    vo = v[1::2]
    voc = Counter(vo).most_common()
    most_odd = voc[0]

    if most_even[0] == most_odd[0]:
        o2 = voc[1][1]
        e2 = vec[1][1]
        ans = n - max(most_even[1] + o2,
                      e2 + most_odd[1])
    else:
        ans = n - most_even[1] - most_odd[1]
    print(ans)

Submission status: Accepted

Solution code:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import Counter
def resolve():
    n = int(input())
    odd = Counter()
    even = Counter()
    for i, a in enumerate(map(int, input().split())):
        if i & 1:
            odd[a] += 1
        else:
            even[a] += 1
    odd[-1] = even[-1] = 0

    res = n
    for key0, val0 in odd.most_common()[:2]:
        for key1, val1 in even.most_common()[:2]:
            if key0 != key1:
                res = min(res, n - val0 - val1)
    print(res)
resolve()

Submission status: Accepted

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

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

from collections import Counter

v1c = Counter(v1).most_common()
v2c = Counter(v2).most_common()

v1c.append([0,0])
v2c.append([0,0])

if v1c[0][0] == v2c[0][0]:
    ans = max(v1c[0][1] + v2c[1][1], v1c[1][1] + v2c[0][1])
else:
    ans = v1c[0][1] + v2c[0][1]

print(n-ans)

Submission status: Accepted

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

ki = li[::2]
gu = li[1::2]

ki.sort()
gu.sort()

from itertools import groupby

ki_li = []
gu_li = []

for key, value in groupby(ki):
    ki_li.append((key,len(list(value))))

for key, value in groupby(gu):
    gu_li.append((key,len(list(value))))

ki_li.sort(key=lambda x:(x[1]*(-1)))
gu_li.sort(key=lambda x:(x[1]*(-1)))

if ki_li[0][0] == gu_li[0][0]:
    if ki_li[0][1] > gu_li[0][1]:
        if len(gu_li) >= 2:
            ans = n-ki_li[0][1]-gu_li[1][1]
        else:
            ans = n-ki_li[0][1]
    elif ki_li[0][1] == gu_li[0][1]:
        if len(ki_li) >= 2:
            if ki_li[1][1] >= gu_li[1][1]:
                ans = n-gu_li[0][1]-ki_li[1][1]
            else:
                ans = n-ki_li[0][1]-gu_li[1][1]
        else:
            ans = n-ki_li[0][1]
    else:
        if len(ki_li) >= 2:
            ans = n-gu_li[0][1]-ki_li[1][1]
        else:
            ans = n-gu_li[0][1]
else:
    ans = n-gu_li[0][1]-ki_li[0][1]

print(ans)

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 111
# C - /\/\/\/
# https://atcoder.jp/contests/abc111/tasks/arc103_a
from collections import Counter

N, *A = map(int, open(0).read().split())

ev = A[0::2]
od = A[1::2]

ev_C = Counter(ev)
od_C = Counter(od)


if ev == od and ev_C.most_common()[0][1] == N//2:
    print(N//2)
else:
    ans = N
    ev_common = ev_C.most_common()
    od_common = od_C.most_common()
    ev_most = ev_common[0][1]
    od_most = od_common[0][1]
    if ev_common[0][0] == od_common[0][0]:
        ev_second = ev_common[1][1]
        od_second = od_common[1][1]
        ans = min(ans, N-ev_most-od_second)
        ans = min(ans, N-ev_second-od_most)
    else:
        ans = min(ans, N-ev_most-od_most)

    print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    v=list(map(int,readline().split()))

    cnt1=[0]*(10**5+1)
    cnt2=[0]*(10**5+1)

    for i in range(n):
        if i%2==0:
            cnt1[v[i]]+=1
        else:
            cnt2[v[i]]+=1

    max1=0
    m=0
    for i in range(1,10**5+1):
        if max1<cnt1[i]:
            max1=cnt1[i]
            m=i
    
    max2=0
    l=0
    for i in range(1,10**5+1):
        if max2<cnt2[i]:
            if i!=m:
                max2=cnt2[i]
                l=i

    max3=0
    o=0
    for i in range(1,10**5+1):
        if max3<cnt2[i]:
            max3=cnt2[i]
            o=i

    max4=0
    p=0
    for i in range(1,10**5+1):
        if max4<cnt1[i]:
            if i!=o:
                max4=cnt1[i]
                p=i

    ans=min(n-max1-max2,n-max3-max4)
    print(ans)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
v = list(map(int,input().split()))
from collections import Counter
even = Counter(v[::2]).most_common(2)
odd = Counter(v[1::2]).most_common(2)
even.append((0,0))
odd.append((0,0))
youso = n//2
if even[0][0] == odd[0][0]: # 一緒だったら、差が小さい方を優先するのです?
    print(min(youso - even[1][1] + youso - odd[0][1],youso - odd[1][1] + youso - even[0][1]))
else: # 違うやつなら、それに合わせよう
    print(youso - even[0][1] + youso - odd[0][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 len(Ce)==1 and len(Co)==1 and Ce[0][0]==Co[0][0]:
    m = n//2
else:
    if Ce[0][0]!=Co[0][0]:
        m = n-Ce[0][1]-Co[0][1]
    else:
        m1 = n-Ce[1][1]-Co[0][1]
        m2 = n-Ce[0][1]-Co[1][1]
        m = min(m1,m2)
print(m)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N = int(input())
lst1 = [[0, i] for i in range(10 ** 5  +10)]
lst2 = [[0, i] for i in range(10 ** 5 + 10)]

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

for i in range(N):
    if i % 2 == 0:
        lst1[V[i]][0] += 1
    else:
        lst2[V[i]][0] += 1

lst1.sort(key = lambda x: x[0],reverse = True)
lst2.sort(key = lambda x: x[0],reverse = True)

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

Submission status: Accepted

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

A = V[::2]
B = V[1::2]

cntA = list(Counter(A).items())
cntB = list(Counter(B).items())

cntA.sort(key=lambda a: a[1], reverse=True)
cntB.sort(key=lambda a: a[1], reverse=True)

ans = 10**18
for a, c in cntA[:2]:
    for b, d in cntB[:2]:
        if a != b:
            ans = min(ans, N - c - d)
        elif max(len(cntA), len(cntB)) == 1:
                ans = min(ans, min(len(A), len(B)))

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
e = [a[k] for k in range(0,n,2)]
o = [a[k] for k in range(1,n,2)]
C = Counter(e).most_common()
D = Counter(o).most_common()
if C[0][0] != D[0][0]:
    print(n-C[0][1]-D[0][1])
else:
    if len(C) == len(D) == 1:
        print(n//2)
    elif len(C) == 1 and len(D) > 1:
        print(n-C[0][1]-D[1][1])
    elif len(D) == 1 and len(C) > 1:
        print(n-D[0][1]-C[1][1])
    else:
        print(n-max(D[0][1]+C[1][1],C[0][1]+D[1][1]))

Submission status: Accepted

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

cnt_o = {'*' : 0}
for vi in v[0::2]:
    key = str(vi)
    cnt_o.setdefault(key, 0)
    cnt_o[key] += 1
cnt_o = sorted(cnt_o.items(), key=lambda x: -x[1])

cnt_e = {'*' : 0}
for vi in v[1::2]:
    key = str(vi)
    cnt_e.setdefault(key, 0)
    cnt_e[key] += 1
cnt_e = sorted(cnt_e.items(), key=lambda x: -x[1])

key0, val0 = cnt_o[0]
key1, val1 = cnt_o[1]

ans = N
for key, val in cnt_e:
    if key != key0:
        ans_tmp = N - val0 - val
    else:
        ans_tmp = N - val1 - val
    #
    ans = min(ans, ans_tmp)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
T = [int(hoge) for hoge in input().split()]
A = T[::2]
B = T[1::2]
Adic = Counter(A)
AA = sorted(list(Adic.items()),key = lambda x: x[1],reverse=True)
AA.append((-2,0))
Bdic = Counter(B)
BB = sorted(list(Bdic.items()),key = lambda x: x[1],reverse=True)
BB.append((-1,0))
print(N - max([AA[x][1]+BB[y][1] 
for x,y in((0,0),(1,0),(0,1),(1,1)) 
if AA[x][0] != BB[y][0] ]))

Submission status: Accepted

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

a = Counter(lis[::2])
b = Counter(lis[1::2])

aa = sorted(a.items(), key=lambda x:x[1], reverse=True)
bb = sorted(b.items(), key=lambda x:x[1], reverse=True)

aa.append((0, 0))
bb.append((0, 0))

if aa[0][0] == bb[0][0]:
    res = n - max(aa[0][1]+bb[1][1], aa[1][1]+bb[0][1])
else:
    res = n - aa[0][1] - bb[0][1]
print(res)

Submission status: Accepted

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

a = Counter(lis[::2])
b = Counter(lis[1::2])

aa = sorted(a.items(), key=lambda x:x[1], reverse=True)
bb = sorted(b.items(), key=lambda x:x[1], reverse=True)

if aa[0][0] == bb[0][0]:
    if len(aa) > 1 and len(bb) > 1:
        res = n - max(aa[0][1]+bb[1][1], aa[1][1]+bb[0][1])
    elif len(aa) == 1 and len(bb) > 1:
        res = n - aa[0][1] - bb[1][1]
    elif len(aa) > 1 and len(bb) == 1:
        res = n - aa[1][1] - bb[0][1]
    else:
        res = n - aa[0][1]
else:
    res = n - aa[0][1] - bb[0][1]

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

ls1 = v[::2]
ls2 = v[1::2]

c1 = collections.Counter(ls1)
c2 = collections.Counter(ls2)

ch1, cnt1 = c1.most_common()[0][0], c1.most_common()[0][1]
ch2, cnt2 = c2.most_common()[0][0], c2.most_common()[0][1]

ret = 0
if ch1 != ch2:
    ret = n - cnt1 - cnt2
else:
    if cnt1 > cnt2:
        ret = n - cnt1 - c2.most_common()[1][1]
    elif cnt1 < cnt2:
        ret = n - cnt2 - c1.most_common()[1][1]
    else:
        if len(c1.most_common()) > 1 and len(c2.most_common()) > 1:
            cn1 = c1.most_common()[1][1]
            cn2 = c2.most_common()[1][1]
            ret = n - cnt1 - max(cn1, cn2)
        elif len(c1.most_common()) == 1 and len(c2.most_common()) > 1:
            ret = n - cnt1 - c2.most_common()[1][1]
        elif len(c1.most_common()) > 1 and len(c2.most_common()) == 1:
            ret = n - cnt2 - c1.most_common()[1][1]
        else:
            ret = n // 2

print(ret)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
vn = list(map(int, input().split()))
odd = []
even = []
for i in range(n):
    if i % 2 == 0:
        even.append(vn[i])
    else:
        odd.append(vn[i])
ans = len(even) + len(odd)
count_odd = Counter(odd).most_common()
count_even = Counter(even).most_common()
if count_odd[0][0] == count_even[0][0]:
    if len(set(even)) != 1 and len(set(odd)) != 1:
        even2 = count_even[1][1]
        odd2 = count_odd[1][1]
        ans -= max(even2 + count_odd[0][1], odd2 + count_even[0][1])
    elif len(set(even)) != 1 and len(set(odd)) == 1:
        ans -= count_odd[0][1] + count_even[1][1]
    elif len(set(even)) == 1 and len(set(odd)) != 1:
        ans -= count_even[0][1] + count_odd[1][1]
    else:
        ans -= max(count_even[0][1], count_odd[0][1])
else:
    ans -= count_odd[0][1] + count_even[0][1]
print(ans)

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[0::2])
    c2 = Counter(v[1::2])
    
    c1m = c1.most_common(2)
    c2m = c2.most_common(2)
    
    if c1m[0][0] != c2m[0][0]:
        print(n-c1m[0][1]-c2m[0][1])
    else:
        mn = n
        if len(set(c1)) > 1:
            mn = min(mn, n-c1m[1][1]-c2m[0][1])
        if len(set(c2)) > 1:
            mn = min(mn, n-c1m[0][1]-c2m[1][1])
            
        print(mn)

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
import copy

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

kisu = [0]*(10**6)
gusu = [0]*(10**6)
for i in range(n):
    if i % 2 == 0:
        gusu[v[i]] += 1
    else:
        kisu[v[i]] += 1

count = 0
gusu_m = gusu.index(max(gusu))
kisu_m = kisu.index(max(kisu))

if gusu_m == kisu_m:

    gusu[gusu_m] = 0
    kisu[kisu_m] = 0
    if max(gusu) > max(kisu):
        gusu_m = gusu.index(max(gusu))
    else:
        kisu_m = kisu.index(max(kisu))

for i in range(n):
    if i % 2 == 0 and gusu_m != v[i]:
        count += 1
    if i % 2 != 0 and kisu_m != v[i]:
        count += 1

print(count)

Submission status: Accepted

Solution code:
n=int(input())
v=list(map(int,input().split()))
odd=[[0,0] for i in range(10**5+1)]
even=[[0,0] for i in range(10**5+1)]
for i in range(1,10**5+1):
    odd[i][1]=i
    even[i][1]=i
for i in range(n):
    if (i+1)%2==1:
        odd[v[i]][0]+=1
    else:
        even[v[i]][0]+=1
odd=sorted(odd,reverse=True)
even=sorted(even,reverse=True)
ans=0
if(odd[0][0]+even[0][0]==n): #odd[0][0]=n//2
    if(odd[0][1]==even[0][1]):
        ans=n//2
    else:
        ans=0

else:
    # odd 19,1 even 20,19のときに、(1+20)=21よりも(19+19)=38のほうがいいい。
    if(odd[0][1]==even[0][1]):
        if(odd[0][0]+even[1][0]<=odd[1][0]+even[0][0]):
            ans=(n//2-odd[1][0])+(n//2-even[0][0])
        else:
            ans=(n//2-odd[0][0])+(n//2-even[1][0])

    else:
        ans=(n//2-odd[0][0])+(n//2-even[0][0])
print(ans)

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
from collections import Counter

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

v_odd = v_list[0::2]
v_even = v_list[1::2]

c_odd = Counter(v_odd).most_common(2)
c_even = Counter(v_even).most_common(2)

if c_odd[0][0] == c_even[0][0]:
    if len(c_odd) > 1 and len(c_even) > 1:
        if c_odd[1][1] > c_even[1][1]:
            print(len(v_odd) - c_odd[1][1] + len(v_even) - c_even[0][1])
            exit()
        else:
            print(len(v_odd) - c_odd[0][1] + len(v_even) - c_even[1][1])
            exit()
    elif len(c_odd) >= 2:
        print(len(v_odd) - c_odd[1][1] + len(v_even) - c_even[0][1])
        exit()
    elif len(c_even) >= 2:
        print(len(v_odd) - c_odd[0][1] + len(v_even) - c_even[1][1])
        exit()
    else:
        print(len(v_even))
        exit()

print(len(v_odd) - c_odd[0][1] + len(v_even) - c_even[0][1])

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
ac = Counter(v[::2]).most_common(2)
bc = Counter(v[1::2]).most_common(2)



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

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
V = getList()

# 条件を満たすもののうちで最も多く現れる多い２数を採用する方針
even = [0] * (10 ** 5 + 1)
odd = [0] * (10 ** 5 + 1)
for i in range(N):
    if i % 2 == 0:
        even[V[i]] += 1
    else:
        odd[V[i]] += 1
# 偶数列、奇数列に現れる数字の中で一番多かったもの
topeven = even.index(max(even))
topodd = odd.index(max(odd))
even.sort()
odd.sort()

ans = 0
if topeven == topodd:
    # 偶数列で一番多かった数、奇数列で２番目に多かった数
    opt1 = N - even[-1] - odd[-2]
    # 偶数列で２番目に多かった数、奇数列で一番多かった数
    opt2 = N - even[-2] - odd[-1]
    # どちらか小さい方
    ans = min(opt1, opt2)
else:
    ans = N - even[-1] - odd[-1]
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
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
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()
lis=LI()
ev,od=[],[]
for i in range(n):
    if i%2==0:
        ev.append(lis[i])
    else:
        od.append(lis[i])
c=Counter(ev)
d=Counter(od)
#print(c.most_common()[0][1])
#-c.most_common()[0]-d.most_common()[0]
if c.most_common()[0][0]==d.most_common()[0][0]:
    if c.most_common()[0][1]==n//2:
        ans=n//2
    elif c.most_common()[1][1]>=d.most_common()[1][1]:
        ans=len(od)-d.most_common()[0][1]+len(ev)-c.most_common()[1][1]
    elif c.most_common()[1][1]<d.most_common()[1][1]:
        ans=len(od)-c.most_common()[0][1]+len(ev)-d.most_common()[1][1]
else:
    ans=len(ev)+len(od)-c.most_common()[0][1]-d.most_common()[0][1]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
ac = Counter(v[::2]).most_common(2)
bc = Counter(v[1::2]).most_common(2)



if ac[0][0] != bc[0][0]:            #奇数列と偶数列の最頻数が同じ要素でない場合
    ans =  n - ac[0][1] - bc[0][1]  #全体の数から書き換える必要がない数（それぞれの最頻値）を引けばよい
else:                               #奇数列と偶数列の最頻数が同じ要素の数の場合
    if len(bc) == 1 or len(ac) == 1:#全部同じ数の場合 
        ans = n // 2
    else: #２番目の最頻数を比較し、大きいほうの列の最も多大きい最頻数ともう一方の列の2番目に大きい最頻数を書き換える
        ans = n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
V = LI()
odd = [V[i] for i in range(n) if i % 2 != 0]
even = [V[i] for i in range(n) if i % 2 == 0]
A = Counter(odd).most_common(2) + [(0, 0)]
B = Counter(even).most_common(2) + [(0, 0)]
ans = INF
for a in A:
    for b in B:
        if a[0] == b[0]:
            continue
        else:
            ans = min(ans, n-a[1]-b[1])
print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
odd = []
even = []
for i in range(n):
    if i % 2 == 0:
        even.append(v[i])
    else:
        odd.append(v[i])
o = collections.Counter(odd)
o_list = list(o.items())
o_sorted = sorted(o_list, key=lambda x: x[1], reverse=True)
e = collections.Counter(even)
e_list = list(e.items())
e_sorted = sorted(e_list, key=lambda x: x[1], reverse=True)

if len(o_sorted) == 1 and len(e_sorted) == 1:
    if o_sorted[0][0] != e_sorted[0][0]:
        print(0)
    else:
        print(o_sorted[0][1])
else:
    if o_sorted[0][0] != e_sorted[0][0]:
        a = n//2-o_sorted[0][1]
        b = n//2-e_sorted[0][1]
        print(int(a+b))
    else:
        a = n//2-o_sorted[1][1]
        b = n//2-e_sorted[0][1]
        c = n//2-o_sorted[0][1]
        d = n//2-e_sorted[1][1]
        ans = min(a+b, c+d)
        print(int(ans))