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:
n=int(input())
v=list(map(int,input().split()))

#奇数個目
dl={}
for i in range(n//2):
    j=2*i
    if v[j] in dl:
        dl[v[j]]+=1
    else:
        dl[v[j]]=1

#偶数個目
dr={}
for i in range(n//2):
    j=2*i+1
    if v[j] in dr:
        dr[v[j]]+=1
    else:
        dr[v[j]]=1

maxli=max(dl,key=dl.get)
maxri=max(dr,key=dr.get)
if maxli!=maxri:
    print(n-dl[maxli]-dr[maxri])
else:
    lr=sorted(dr.values())
    ll=sorted(dl.values())
    
    s=max(lr[-2]+ll[-1] if len(lr)>1 else ll[-1],lr[-1]+ll[-2]if len(ll)>1 else lr[-1])
    print(n-s)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

a1 = a[::2]
a2 = a[1::2]

from collections import defaultdict

d1 = defaultdict(int)
d1[0] = 0
for ai in a1:
	d1[ai] += 1  

d2 = defaultdict(int)
d2[0] = 0
for ai in a2:
	d2[ai] += 1  

an1 = list(d1.items())
an1.sort(key = lambda x: -x[1])

an2 = list(d2.items())
an2.sort(key = lambda x: -x[1])

if an1[0][0] == an2[0][0]:
	print(n - max(an1[0][1] + an2[1][1], an1[1][1] + an2[0][1]))
else:
	print(n - an1[0][1] - an2[0][1])

Submission status: Accepted

Solution code:
n = int(input())
v = list(map(int,input().split()))
from collections import Counter
v0,v1 = [],[]
for i in range(n):
  if i % 2 == 0:
    v0.append(v[i])
  else:
    v1.append(v[i])
n0,n1 = len(v0),len(v1)
c0 = Counter(v0).most_common()
c1 = Counter(v1).most_common()
c0.append((0,0))
c1.append((0,0))
ans = n0+n1
if c0[0][0] == c1[0][0]:
  print(ans-max(c0[0][1]+c1[1][1],c0[1][1]+c1[0][1]))
else:
  print(ans-c0[0][1]-c1[0][1])

Submission status: Accepted

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

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

cnt_even = {}
for e in even:
    if e not in cnt_even:
        cnt_even[e] = 1
    else:
        cnt_even[e] += 1

cnt_odd = {}
for o in odd:
    if o not in cnt_odd:
        cnt_odd[o] = 1
    else:
        cnt_odd[o] += 1

cnt_even = [[v, k] for k, v in cnt_even.items()]
cnt_odd = [[v, k] for k, v in cnt_odd.items()]
cnt_even.sort(reverse=True)
cnt_odd.sort(reverse=True)

ce = cnt_even[0][0]
ce_num = cnt_even[0][1]
ce_res = sum([v for v, k in cnt_even[1:]])

co = cnt_odd[0][0]
co_num = cnt_odd[0][1]
co_res = sum([v for v, k in cnt_odd[1:]])

if ce_num != co_num:
    print(ce_res + co_res)
else:
    if len(cnt_even) > 1 and len(cnt_odd) > 1:
        ce_res_2 = ce_res - cnt_even[1][0] + ce
        co_res_2 = co_res - cnt_odd[1][0] + co
        res = min(ce_res + co_res_2, ce_res_2 + co_res)
    elif len(cnt_even) == 1 and len(cnt_odd) > 1:
        co_res_2 = co_res - cnt_odd[1][0] + co
        res = ce_res + co_res_2
    elif len(cnt_even) > 1 and len(cnt_odd) == 1:
        ce_res_2 = ce_res - cnt_even[1][0] + ce
        res = ce_res_2 + co_res
    else:
        res = min(ce, co)
    print(res)

Submission status: Accepted

Solution code:
from collections import Counter
 
n = int(input())
v = list(map(int, input().split()))
ve = Counter(v[::2]).most_common() # 一番個数の多いものと、その個数のタプル
vo = Counter(v[1::2]).most_common()


if ve[0][0] == vo[0][0]:
    if len(ve) == len(vo) == 1:
        ans = n - max(ve[0][1], vo[0][1])
    else:
        ans = n - max(ve[0][1]+vo[1][1], vo[0][1]+ve[1][1])
else:
    ans = n - ve[0][1] - vo[0][1]
print(ans)

Submission status: Accepted

Solution code:
import collections

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

odd = [0] * (n//2)
even = [0] * (n//2)
for i in range(n):
    if i % 2 == 0:
        even[i//2] = v[i]
    else:
        odd[i//2] = v[i]

even_cnt = collections.Counter(even)
odd_cnt = collections.Counter(odd)


if even_cnt.most_common()[0][0] != odd_cnt.most_common()[0][0]:
    ans = n - even_cnt.most_common()[0][1]- odd_cnt.most_common()[0][1]
else:
    if even_cnt.most_common()[0][1] == odd_cnt.most_common()[0][1]:
        if len(even_cnt.most_common()) >= 2:
            ans = n - even_cnt.most_common()[0][1]- max(even_cnt.most_common()[1][1],odd_cnt.most_common()[1][1])
        else:
            ans = n//2
    else:
        if even_cnt.most_common()[0][1] > odd_cnt.most_common()[0][1]:
            ans = n - even_cnt.most_common()[0][1] - odd_cnt.most_common()[1][1]
        else:
            ans = n - odd_cnt.most_common()[0][1] - even_cnt.most_common()[1][1]
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])
w1 = collections.Counter(v1)
w2 = collections.Counter(v2)
w1 = w1.most_common()
w2 = w2.most_common()

if (w1[0][0] != w2[0][0]):
    print(n-w1[0][1]-w2[0][1])
    exit()
else:
    if len(w1) ==1:
        if len(w2) ==1:
            print(n//2)
        else:
            print(n-w1[0][1]-w2[1][1])
    else:
        if len(w2) ==1:
            print(n-w2[0][1]-w1[1][1])
        else:
            if (w1[0][1]-w1[1][1]) >= (w2[0][1]-w2[1][1]):
                print(n-w1[0][1]-w2[1][1])
            else:
                print(n-w2[0][1]-w1[1][1])

Submission status: Accepted

Solution code:
from collections import Counter

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

if ve[0][0] == vo[0][0]:
    if len(ve) == len(vo) == 1:
        ans = n - max(ve[0][1], vo[0][1])
    else:
        ans = n - max(ve[0][1]+vo[1][1], vo[0][1]+ve[1][1])
else:
    ans = n - ve[0][1] - vo[0][1]
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
v = list(map(int, input().split()))
gu = [0] * (10**5 + 5)
ki = [0] * (10**5 + 5)

for i in range(n):
  if i % 2:
    ki[v[i]] += 1
  else:
    gu[v[i]] += 1
ki = np.array(ki)
gu = np.array(gu)

a = np.argmax(ki)
b = np.argmax(gu)

if a != b:
  print(n-ki[a]-gu[b])
else:
  gu = sorted(gu)
  ki = sorted(ki)
  print(min(n-ki[-1] - gu[-2], n-ki[-2]-gu[-1]))

Submission status: Accepted

Solution code:
import sys
from collections import Counter
sys.setrecursionlimit(10 ** 6)

def main():
    N = int(input())
    V = list(map(int, sys.stdin.readline().rstrip().split()))
    c0 = Counter([v for i, v in enumerate((V)) if i % 2 == 0])
    c1 = Counter([v for i, v in enumerate((V)) if i % 2 == 1])

    if c0.most_common()[0][0] == c1.most_common()[0][0]:
        if len(c0.most_common()) == 1:
            m = c1.most_common()[0][1]
            print(m)
        elif len(c1.most_common()) == 1:
            m = c0.most_common()[0][1]
            print(m)
        else:
            m = max(c0.most_common()[0][1] + c1.most_common()[1][1], c0.most_common()[1][1] + c1.most_common()[0][1])
            print(N - m)
    else:
        m = c0.most_common()[0][1] + c1.most_common()[0][1]
        print(N - m)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    V = readInts()
    from collections import Counter
    a = Counter(V[0::2]).most_common(2) # 最大のもの1こ
    b = Counter(V[1::2]).most_common(2)
    a.append([0,0])
    b.append([0,0])
    #print(a,b)
    #print(a[1][1],b[1][1])
    if a[0][0] != b[0][0]:
        # mostが違う
        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:
import collections
n=int(input())
A=list(map(int,input().split()))
A0=[]
A1=[]
for i in range(n):
  if i%2==0:
    A0.append(A[i])
  else:
    A1.append(A[i])
A00=collections.Counter(A0)
A11=collections.Counter(A1)
A000=A00.most_common()
A111=A11.most_common()
A000.append(("-1",0))
A111.append(("-1",0))
if A000[0][0]!=A111[0][0]:
  print(n-A000[0][1]-A111[0][1])
else:
  print(min(n-A000[1][1]-A111[0][1],n-A000[0][1]-A111[1][1]))

Submission status: Accepted

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

a = [v[i] for i in range(n) if i % 2 == 0]
b = [v[i] for i in range(n) if not i % 2 == 0]

a_count = Counter(a)
b_count = Counter(b)

a_sorted = sorted(a_count.items(), key=lambda x:x[1], reverse=True)
b_sorted = sorted(b_count.items(), key=lambda x:x[1], reverse=True)
ans = 0
if not a_sorted[0][0] == b_sorted[0][0]:
    ans = n - a_sorted[0][1] - b_sorted[0][1]
else:
    if len(b_sorted) == 1 and len(a_sorted) == 1:
        ans = n - a_sorted[0][1]
    elif len(b_sorted) == 1:
        ans = n - a_sorted[0][1]
    elif len(a_sorted) == 1:
        ans = n - b_sorted[0][1]
    else:
        ans = n - max(a_sorted[0][1] + b_sorted[1][1], a_sorted[1][1] + b_sorted[0][1])

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():

    n = int(input())

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

    odd = defaultdict(int)
    even = defaultdict(int)
    odd[0] = 0
    even[0] = 0

    for i, num in enumerate(v):
        # print(i % 2)
        if (i % 2) == 0:
            even[num] += 1
        elif (i % 2) == 1:
            # print(i, ": ", num)
            odd[num] += 1

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

    ans_list = []
    for ev in even_list[:2]:
        for od in odd_list[:2]:
            if ev[0] != od[0]:
                ans = 0
                ans += n - (ev[1] + od[1])
                ans_list.append(ans)

    print(min(ans_list))


main()

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():

    n = int(input())

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

    odd = defaultdict(int)
    even = defaultdict(int)
    odd[0] = 0
    even[0] = 0

    for i, num in enumerate(v):
        # print(i % 2)
        if (i % 2) == 0:
            even[num] += 1
        elif (i % 2) == 1:
            # print(i, ": ", num)
            odd[num] += 1

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

    if a[0][0] != b[0][0]:
        ans = n - a[0][1] - b[0][1]
    else:
        ans = n - max(a[0][1] + b[1][1], a[1][1] + b[0][1])

    print(ans)


main()

Submission status: Accepted

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

d_odd = {0:0}
d_even = {0:0}

ans = 0
for i in range(n):
    if i % 2 == 0:
        if v[i] in d_odd:
            d_odd[v[i]] += 1
        else:
            d_odd[v[i]] = 1
    else:
        if v[i] in d_even:
            d_even[v[i]] += 1
        else:
            d_even[v[i]] = 1

x = sorted(d_odd.items(), key=lambda x: x[1], reverse=1)
y = sorted(d_even.items(), key=lambda x: x[1], reverse=1)

if x[0][0] != y[0][0]:
    ans = n - x[0][1] - y[0][1]
else:
    ans = n - max(x[0][1]+y[1][1], x[1][1]+y[0][1])

print(ans)

Submission status: Accepted

Solution code:
import collections
n, *v = map(int, open(0).read().split())

v1 = [0] * (n // 2)
v2 = [0] * (n // 2)

for i in range(n // 2):
    v1[i] = v[2 * i]
    v2[i] = v[2 * i + 1]

v1_cnt = collections.Counter(v1)
v2_cnt = collections.Counter(v2)

v1_cnt_l = sorted(list(v1_cnt.values()))
v2_cnt_l = sorted(list(v2_cnt.values()))

#print(v1_cnt_l, v2_cnt_l)

if max(v1_cnt, key=v1_cnt.get) == max(v2_cnt, key=v2_cnt.get):
    if 1 < len(v1_cnt_l) and 1 < len(v2_cnt_l):
        #print('1 1')
        num1 = sum(v1_cnt_l) - v1_cnt_l[-1]
        num1 += sum(v2_cnt_l) - v2_cnt_l[-2]
    
        num2 = sum(v1_cnt_l) - v1_cnt_l[-2]
        num2 += sum(v2_cnt_l) - v2_cnt_l[-1]
    
        num = min(num1, num2)
    elif 1 < len(v1_cnt_l):
        #print('2 2')
        num = sum(v1_cnt_l) - v1_cnt_l[-2]
        num += sum(v2_cnt_l) - v2_cnt_l[-1]
    elif 1 < len(v2_cnt_l):
        #print('3 3')
        num = sum(v1_cnt_l) - v1_cnt_l[-1]
        num += sum(v2_cnt_l) - v2_cnt_l[-2]
    else:
        #print('4 4')
        num = n // 2
        
else:
    num = sum(v1_cnt_l) - v1_cnt_l[-1]
    num += sum(v2_cnt_l) - v2_cnt_l[-1]

print(num)

Submission status: Accepted

Solution code:
from collections import Counter


def solve():

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

    evens = []
    odds = []

    for i in range(n):
        v = vlist[i]
        if i % 2 == 0:
            evens.append(v)
        else:
            odds.append(v)

    evensCollection = Counter(evens).most_common()
    oddsCollection = Counter(odds).most_common()

    evensCollection.append([0, 0])
    oddsCollection.append([0, 0])

    if evensCollection[0][0] != oddsCollection[0][0]:
        print(n - (evensCollection[0][1] + oddsCollection[0][1]))

    else:
        print(min(n-(evensCollection[1][1]+oddsCollection[0][1]),
                  n-(evensCollection[0][1]+oddsCollection[1][1])))


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

odd = [[0, i] for i in range(100001)]
even = [[0, i] for i in range(100001)]

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

odd.sort()
even.sort()

if odd[-1][1] != even[-1][1]:
  print(n - odd[-1][0] - even[-1][0])
else:
  print(n - max(odd[-2][0] + even[-1][0], odd[-1][0] + even[-2][0]))

Submission status: Accepted

Solution code:
import sys
from collections import Counter

n, *v = map(int, sys.stdin.read().split())

def main():
    c1 = sorted(Counter(v[::2]).items(), key=lambda x: -x[1])
    c2 = sorted(Counter(v[1::2]).items(), key=lambda x: -x[1])
    if c1[0][0] != c2[0][0]: res = n - c1[0][1] - c2[0][1]
    else:
        if len(c1) > len(c2): c1, c2 = c2, c1
        if len(c2) == 1: res = n // 2
        else:
            if len(c1) == 1: res = n - c1[0][1] - c2[1][1]
            else:
                res = n - max(c1[0][1] + c2[1][1], c1[1][1] + c2[0][1])
    print(res)

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

v_even,v_odd = [],[]
for i in range(n):
    if i % 2 == 0:
        v_even.append(v[i])
    else:
        v_odd.append(v[i])

c_even = Counter(v_even)
c_odd = Counter(v_odd)

if len(set(v)) == 1:
    ans = n // 2
elif len(set(v_even)) == 1:
    if c_even.most_common()[0][0] == c_odd.most_common()[0][0]:
        ans = (n // 2) - c_odd.most_common()[1][1]
    else:
        ans = (n // 2) - c_odd.most_common()[0][1]
elif len(set(v_odd)) == 1:
    if c_odd.most_common()[0][0] == c_even.most_common()[0][0]:
        ans = (n // 2) - c_even.most_common()[1][1]
    else:
        ans = (n // 2) - c_even.most_common()[0][1]
else:
    if c_odd.most_common()[0][0] != c_even.most_common()[0][0]:
        ans = n - c_even.most_common()[0][1] - c_odd.most_common()[0][1]
    else:
        ans = n - c_even.most_common()[0][1] \
              - max(c_even.most_common()[1][1],c_odd.most_common()[1][1])

print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    V = readInts()
    from collections import Counter
    a = Counter(V[0::2]).most_common(2) # 一番頻度が高いやつ
    b = Counter(V[1::2]).most_common(2)
    a.append([0,0])
    b.append([0,0])#なんでこれする？

    #print(a,b,sep='\n')
    # もし頻度が高いやつと数字がかぶっていたら、
    # 加えた[0,0]により、差が小さいほうに合わせる
    # a,bどっちが譲るかって感じ
    if a[0][0] != b[0][0]:
        print(n-(a[0][1] + b[0][1]))
    else:
        # ここでその処理をしてる
        # aが譲って～って感じのと
        # bが譲って～って感じのやつ
        print(min(n-(a[1][1] + b[0][1]), n-(a[0][1] + b[1][1])))

    """Fi = {}
    Se = {}

    for i in range(0,n,2): # 奇数個
        print(i,len(V))
        if V[i] in Fi.keys():
            Fi[V[i]] += 1
        else:
            Fi[V[i]] = 1


    for i in range(1,n,2): # 偶数個

        if V[i] in Se.keys():
            Se[V[i]] += 1
        else:
            Se[V[i]] = 1
    #print(Fi,Se,sep='\n')
    # ソート
    sortFi = sorted(Fi.items(), key=lambda x:x[1]) # valuesでソートしてる！
    sortSe = sorted(Se.items(), key = lambda x:x[1])
    # リスト化しちゃう
    #print(Fi,Se,sep='\n')
    #na = '' # 繰り返し防止
    k,v = sortFi[0]
    mostFi = k
    #もじ、mostFiと、mostSeが一緒だったら、mostSeの方をずらす? 数字が小さいほうをずらしたほうがいい気もする?
    k,v = sortSe[0]
    mostSe = k
    if mostFi == mostSe:
        if len(sortSe) != 1:
            k,v = sortSe[1]
            mostSe = k
        else:
            mostSe = mostFi+1
    #print(mostFi)
    # 一番多くある数字に合わせる感じ
    cnt = 0
    for k,v in Fi.items():
        if mostFi == k:
            pass
        else:
            cnt += v
    for k,v in Se.items():
        if mostSe == k:
            pass
        else:
            cnt += v
    print(cnt)
    """


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v1 = v[0::2]
v2 = v[1::2]
count1 = Counter(v1)
count2 = Counter(v2)
count1[0] = 0
count2[0] = 0
items1 = []
items2 = []
key1 = max(count1.keys(), key = count1.get)
items1.append([key1, count1[key1]])
del count1[key1]
key1 = max(count1.keys(), key = count1.get)
items1.append([key1, count1[key1]])

key2 = max(count2.keys(), key = count2.get)
items2.append([key2, count2[key2]])
del count2[key2]
key2 = max(count2.keys(), key = count2.get)
items2.append([key2, count2[key2]])

if items1[0][0] != items2[0][0]:
    m = items1[0][1] + items2[0][1]
else:
    m = max(items1[0][1] + items2[1][1], items1[1][1] + items2[0][1])
print(n - m)

Submission status: Accepted

Solution code:
from collections import Counter
import sys

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

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

# print(A, B)

cnt = 0

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

A_counter = Counter(A)
B_counter = Counter(B)

A_top2 = A_counter.most_common(2)
B_top2 = B_counter.most_common(2)

if A_top2[0][0] != B_top2[0][0]:
    cnt += len(A) - A_top2[0][1]
    cnt += len(B) - B_top2[0][1]
else:
    cnt = min(
        len(A) - A_top2[0][1] + len(B) - B_top2[1][1],
        len(A) - A_top2[1][1] + len(B) - B_top2[0][1],
    )

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
if len(set(arr)) == 1:
    print(N//2)
    exit()
A = []
B = []
for i in range(N):
    if i % 2 == 0:
        A.append(arr[i])
    else:
        B.append(arr[i])
from collections import Counter
A_counter = Counter(A)
B_counter = Counter(B)
if A_counter.most_common()[0][0] != B_counter.most_common()[0][0]:
    print(N-A_counter.most_common()[0][1]-B_counter.most_common()[0][1])
elif A_counter.most_common()[0][1] > B_counter.most_common()[0][1]:
    print(N-A_counter.most_common()[0][1]-B_counter.most_common()[1][1])
elif A_counter.most_common()[0][1] < B_counter.most_common()[0][1]:
    print(N-A_counter.most_common()[1][1]-B_counter.most_common()[0][1])
else:
    print(N-A_counter.most_common()[0][1]-max(A_counter.most_common()[1][1],B_counter.most_common()[1][1]))

Submission status: Accepted

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

from collections import Counter

def minus(lis):
    if len(set(lis))==1:
        return lis[0], 0, 10**9
    c = Counter(lis)
    f_key = max(c, key=c.get)
    second,first = sorted(c.values())[-2:]
    return f_key,len(lis)-first,len(lis)-second

def solve(n,v):
    if len(set(v))==1:
        return n//2
    Odd = [v[i] for i in range(n) if i%2==1]
    Even = [v[i] for i in range(n) if i%2==0]
    odd_key, odd_f,odd_s = minus(Odd)
    # print(odd_key, odd_f,odd_s)
    even_key, even_f,even_s = minus(Even)
    if odd_key == even_key:
        return min(odd_f+even_s,even_f+odd_s)
    # print(odd,even)
    return odd_f + even_f
print(solve(n,v))

Submission status: Accepted

Solution code:
from collections import Counter

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

c1 = Counter(v[::2])
c2 = Counter(v[1::2])
c1[0] = 0
c2[0] = 0
c1 = sorted(c1.items(), key=lambda x: x[1], reverse=True)
c2 = sorted(c2.items(), key=lambda x: x[1], reverse=True)

if c1[0][0] != c2[0][0]:
    ans = n - c1[0][1] - c2[0][1]
else:
    ans = min(n - c1[0][1] - c2[1][1], n - c2[0][1] - c1[1][1],)
print(ans)

Submission status: Accepted

Solution code:
def main():
  import collections 
  n=int(input())
  v=tuple(map(int,input().split()))
  a,b=collections.Counter(v[::2]).most_common(),collections.Counter(v[1::2]).most_common()
  if len(a)==len(b)==1:
    print(n//2 if a==b else 0)
  else:
    print(n+(-a[0][1]-b[0][1] if a[0][0]!=b[0][0] else (-a[0][1]-b[1][1] if b[1][1]>=a[1][1] else -a[1][1]-b[0][1])))
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
import collections 
n=int(input())
v=list(map(int,input().split()))
c1,c2,ans=collections.Counter(v[::2]),collections.Counter(v[1::2]),0
a,b=c1.most_common(),c2.most_common()
if len(a)==len(b)==1:
  print(n//2 if a==b else 0)
  exit()
ans=n+(-a[0][1]-b[0][1] if a[0][0]!=b[0][0] else (-a[0][1]-b[1][1] if b[1][1]>=a[1][1] else -a[1][1]-b[0][1]))
print(ans)

Submission status: Accepted

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

a = [v[i] for i in range(n) if i % 2]
b = [v[i] for i in range(n) if i % 2 == 0]
aa = Counter(a)
bb = Counter(b)
ans = 0

aas = sorted(aa.keys(), key=lambda key:aa[key], reverse=True)
bbs = sorted(bb.keys(), key=lambda key:bb[key], reverse=True)
if aas[0] != bbs[0]:
    ans += len(a) - aa[aas[0]]
    ans += len(b) - bb[bbs[0]]
else:
    if len(aa) == len(bb) and len(aa) == 1 and a[0] == b[0]:
        ans += min(len(a), len(b))
    else:
        s = len(a) - aa[aas[0]] + len(b) - bb[bbs[1]]
        t = len(a) - aa[aas[1]] + len(b) - bb[bbs[0]]
        ans = min(s,t)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
V = list(map(int,input().split()))
Ve = V[::2]
Vo = V[1::2]
from collections import Counter


Ve = list(Counter(Ve).items())
Ve.sort(key = lambda x:x[1], reverse = 1)
Vo = list(Counter(Vo).items())
Vo.sort(key = lambda x:x[1], reverse = 1)

if Ve[0][0] == Vo[0][0]:
  if len(Ve) == len(Vo) == 1:
    print(n//2)
  else:
    print(n - max(Ve[0][1]+Vo[1][1], Ve[1][1]+Vo[0][1]))
else:
  print(n-Ve[0][1]-Vo[0][1])

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = list(map(int,input().split()))
s1 = []
s2 = []

#文字列を２つに分割、問題文よりs1とs2の数は同じ
for i in range(n):
  if i%2 == 1:
    s2.append(s[i])
  else:
    s1.append(s[i])
#print(s1,s2)
s1_counter = Counter(s1)
s2_counter = Counter(s2)
s1_len = len(s1)
s2_len = len(s2)
s1_most_common = s1_counter.most_common()
s2_most_common = s2_counter.most_common()

if s1_most_common[0][0] != s2_most_common[0][0]:
  print(s1_len-s1_most_common[0][1]+s2_len-s2_most_common[0][1])
else:  
  if len(s1_most_common) + len(s2_most_common) == 2:
    print(n//2)
  elif s1_most_common[0][1] > s2_most_common[0][1]:
    print(s1_len-s1_most_common[0][1]+s2_len-s2_most_common[1][1])
  elif s1_most_common[0][1] < s2_most_common[0][1]:
    print(s1_len-s1_most_common[1][1]+s2_len-s2_most_common[0][1])
  else:
    if s1_most_common[1][1] < s2_most_common[1][1]:
      print(s1_len-s1_most_common[0][1]+s2_len-s2_most_common[1][1])
    else:
      print(s1_len-s1_most_common[1][1]+s2_len-s2_most_common[0][1])

Submission status: Accepted

Solution code:
n = int(input())
v = list(map(int,input().split()))
dict1 = {0:0}
dict2 = {0:0}
ans = 0
for i in v[::2]:
    if i not in dict1:
        dict1[i] = 1
    else:
        dict1[i] += 1
for i in v[1::2]:
    if i not in dict2:
        dict2[i] = 1
    else:
        dict2[i] += 1
lisa = sorted(dict1.items(),key=lambda x: x[1],reverse=1)
lisb = sorted(dict2.items(),key=lambda x: x[1],reverse=1)
if lisa[0][0] != lisb[0][0]:
    ans = n-lisa[0][1]-lisb[0][1]
else:
    ans = n-max(lisa[0][1]+lisb[1][1],lisa[1][1]+lisb[0][1])
print(ans)

Submission status: Accepted

Solution code:
import sys

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

a1 = {}
a2 = {}
for i in range(n) :
  a = v[i]
  if i%2 == 0 :
    if a in a1 :
      a1[a] += 1
    else :
      a1[a] = 1
  else :
    if a in a2 :
      a2[a] += 1
    else :
      a2[a] = 1

a1_s = sorted(a1.items(), key = lambda x : x[1], reverse = True)
a2_s = sorted(a2.items(), key = lambda x : x[1], reverse = True)

ans = n
for i in range(min(2,len(a1_s))) :
  for j in range(min(2,len(a2_s))) :
    if a1_s[i][0] == a2_s[j][0] :
      continue
    ans = min(ans,n-a1_s[i][1]-a2_s[j][1])

if len(a1_s) == 1 and len(a2_s) == 1 and ans == n :
  ans = n//2

print(ans)

Submission status: Accepted

Solution code:
"""
# keywords
Counter
# impression
Counterを使わない場合、処理を間違えずに書くのに以外と苦労
"""
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from collections import Counter

def main():
    n = II()
    vv = MII()
    ee = Counter(vv[0::2])
    oo = Counter(vv[1::2])
    minv = 10**5
    ee1 = ee.most_common()[0]
    oo1 = oo.most_common()[0]
    if ee1[0] != oo1[0]:
        minv = min(minv, n - (ee1[1] + oo1[1]))
    else:
        ee2 = ee.most_common()[1] if len(ee) > 1 else (0, 0)
        oo2 = oo.most_common()[1] if len(oo) > 1 else (0, 0)
        minv = min(minv, n - (ee1[1] + oo2[1]))
        minv = min(minv, n - (ee2[1] + oo1[1]))
    print(minv)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=list(map(int, input().split()))
b=[a[i] for i in range(n) if i%2==0]
c=[a[i] for i in range(n) if i%2==1]
b2=Counter(b)
c2=Counter(c)
b3=b2.most_common(2)
c3=c2.most_common(2)
ans=n
for i in b3:
    for j in c3:
        if i[0]!=j[0]:
            ans=min(ans,n-i[1]-j[1])
        else:
            ans=min(ans,n-max(i[1],j[1]))
print(ans)

Submission status: Accepted

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

A=v[0::2]
B=v[1::2]
a=len(A)
b=len(B)

#print(Counter(A).most_common()[0][0])
#print(Counter(B).most_common()[0][0])

if Counter(A).most_common()[0][0] !=Counter(B).most_common()[0][0]:
    s=Counter(A).most_common()[0][1]
    t=Counter(B).most_common()[0][1]
    print( (a-s)+(b-t))
else:
  r=a
  s=b
  if Counter(A).most_common()[0][1]<a:
    o=Counter(A).most_common()[1][1]
    p=Counter(B).most_common()[0][1]
    r= (a-o)+(b-p)
  if Counter(B).most_common()[0][1]<b:
    w=Counter(A).most_common()[0][1]
    x=Counter(B).most_common()[1][1]
    s= (a-w)+(b-x)
  print(min( r, s))

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from collections import Counter

def main():
    n = II()
    vv = MII()
    ee = Counter(vv[0::2])
    oo = Counter(vv[1::2])
    minv = 10**5
    ee1 = ee.most_common()[0]
    oo1 = oo.most_common()[0]
    if ee1[0] != oo1[0]:
        minv = min(minv, n - (ee1[1] + oo1[1]))
    else:
        ee2 = ee.most_common()[1] if len(ee) > 1 else (0, 0)
        oo2 = oo.most_common()[1] if len(oo) > 1 else (0, 0)
        minv = min(minv, n - (ee1[1] + oo2[1]))
        minv = min(minv, n - (ee2[1] + oo1[1]))
    print(minv)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def split_even_or_odd(vv, n, start):
    res = {}
    for i in range(start,n,2):
        v = vv[i]
        if not v in res.keys(): res[v] = 1
        else: res[v] += 1
    return res

def find_fs(target):
    maxk1 = maxv1 = 0
    for k, v in target.items():
        if maxv1 < v:
            maxk1, maxv1 = k, v
    maxk2 = maxv2 = 0
    for k, v in target.items():
        if maxv2 < v and maxk1 != k:
            maxk2, maxv2 = k, v
    return (maxk1, maxv1), (maxk2, maxv2)

def main():
    n = II()
    vv = MII()
    ee = split_even_or_odd(vv, n, 0)
    oo = split_even_or_odd(vv, n, 1)

    e1kv, e2kv = find_fs(ee)
    o1kv, o2kv = find_fs(oo)

    minv = 10**5
    if e1kv[0] != o1kv[0]:
        minv = min(minv, n - (e1kv[1] + o1kv[1]))
    else:
        minv = min(minv, n - (e1kv[1] + o2kv[1]))
        minv = min(minv, n - (e2kv[1] + o1kv[1]))
    print(minv)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections
import sys

n = int(input())
vn = list(map(int,input().split()))
vnodd = collections.Counter(vn[1::2]).most_common()
vneven= collections.Counter(vn[0::2]).most_common()
vnodd.append([0,0])
vneven.append([0,0])

if vnodd[0][0] != vneven[0][0]:
  print(n - (vnodd[0][1] + vneven[0][1]))
else:
  print(min(n-vnodd[0][1]-vneven[1][1], n-vnodd[1][1]-vneven[0][1]))

Submission status: Accepted

Solution code:
from collections import defaultdict
odd_dic = defaultdict(int)
even_dic = defaultdict(int)
n = int(input())
ns = list(map(int, input().split()))
for i in range(0, n, 2):
    even_dic[ns[i]] += 1
for i in range(1, n, 2):
    odd_dic[ns[i]] += 1
even = sorted(even_dic.items(), key=lambda x:x[1], reverse=True)
odd = sorted(odd_dic.items(), key=lambda x:x[1], reverse=True)

if even[0][0] != odd[0][0]:
    print(n-even[0][1]-odd[0][1])
elif even[0][1]+odd[0][1]==n:
    print(n//2)
else:
    print(min(n-even[0][1]-odd[1][1], n-even[1][1]-odd[0][1]))

Submission status: Accepted

Solution code:
n = int(input())
base = list(map(int,input().split()))
even = [0]*(10**5)
odd = [0]*(10**5)

for i in range(1,n+1):
  sign = i%2
  num = base[i-1]
  
  if sign == 0:
    even[num-1] += 1
  elif sign == 1:
    odd[num-1] += 1

ans_e = max(even)
ans_o = max(odd)
even_i = even.index(ans_e)
odd_i = odd.index(ans_o)

if even_i == odd_i:
  even.sort()
  odd.sort()
  if even[10**5 - 2] <= odd[10**5 - 2]:
    ans_o = odd[10**5 - 2]
  else:
    ans_e = even[10**5 - 2]
  
print(n - ans_e - ans_o)