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()))

even = {}
odd = {}


for i in range(N):
    if(i%2==0):
        if odd.get(V[i],None)==None:
            odd[V[i]]=1
        else:
            odd[V[i]]+=1
    else:
        if even.get(V[i],None)==None:
            even[V[i]]=1
        else:
            even[V[i]]+=1


max_odd_k = max(odd, key=odd.get)
max_even_k = max(even, key=even.get)
max_odd_v = max(odd.values())
max_even_v = max(even.values())
len_odd = len(odd)
len_even = len(even)

if(max_odd_k!=max_even_k):
    print(N-max_odd_v-max_even_v)
    exit()

if((len_odd==1)&(len_even==1)):
    print(N//2)
    exit()


if(len_odd==1):
    del even[max_even_k]
    max2_even_v = max(even.values())
    print(N-max_odd_v-max2_even_v)
    exit()

if(len_even==1):
    del odd[max_odd_k]
    max2_odd_v = max(odd.values())
    print(N-max2_odd_v-max_even_v)
    exit()

del even[max_even_k]
max2_even_v = max(even.values())
del odd[max_odd_k]
max2_odd_v = max(odd.values())

print(min((N-max2_odd_v-max_even_v),(N-max_odd_v-max2_even_v)))
#print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
import heapq

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

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

Veve, Vodd = [],[]
idx = 0
for v in Vs:
  if idx%2 == 0: Veve.append(v)
  else: Vodd.append(v)
  idx += 1

Veve_cnt, Vodd_cnt = [], []
[heapq.heappush(Veve_cnt, [-num,val]) for val, num in Counter(Veve).items()]
[heapq.heappush(Vodd_cnt, [-num,val]) for val, num in Counter(Vodd).items()]

neg_num, val = heapq.heappop(Veve_cnt)
eve_val = val
eve_num = -neg_num

neg_num, val = heapq.heappop(Vodd_cnt)
odd_val = val
odd_num = -neg_num

if eve_val != odd_val:
  print(N-eve_num-odd_num)
else:
  if len(Vodd_cnt) != 0:odd_num2 = -heapq.heappop(Vodd_cnt)[0]
  else:odd_num2 = -float('inf')

  if len(Veve_cnt) != 0:eve_num2 = -heapq.heappop(Veve_cnt)[0]
  else:eve_num2 = -float('inf')

  print(min(N-eve_num2-odd_num,N-eve_num-odd_num2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
N = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
  print(int(len(v)/2))
  exit()
cov = collections.Counter(v[1::2])
cev = collections.Counter(v[::2])
mov = cov.most_common()[0][0]
mev = cev.most_common()[0][0]
ans = len(v) - cov[mov] - cev[mev]

if mov == mev:
  ans1 = len(v) - cov.most_common()[1][1] - cev.most_common()[0][1]
  ans2 = len(v) - cov.most_common()[0][1] - cev.most_common()[1][1]
  ans = min(ans1, ans2)

print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
  print(int(len(v)/2))
  exit()
ov = [v[i] for i in range(1,len(v),2)]
ev = [v[i] for i in range(0, len(v), 2)]

cov = collections.Counter(ov)
cev = collections.Counter(ev)
mov = cov.most_common()[0][0]
mev = cev.most_common()[0][0]
ans = len(v) - cov[mov] - cev[mev]

if mov == mev:
  ans1 = len(v) - cov.most_common()[1][1] - cev.most_common()[0][1]
  ans2 = len(v) - cov.most_common()[0][1] - cev.most_common()[1][1]
  ans = min(ans1, ans2)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
v1 = Counter(v[::2]).most_common()
v2 = Counter(v[1::2]).most_common()
v1.append((0, 0))
v2.append((0, 0))
if v1[0][0] != v2[0][0]:
    print(n - v1[0][1] - v2[0][1])
else:
    print(min(n - v1[0][1] - v2[1][1], n - v1[1][1] - v2[0][1]))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
v1 = sorted(Counter(v[::2]).items(), key=lambda x: x[1], reverse=True)
v2 = sorted(Counter(v[1::2]).items(), key=lambda x: x[1], reverse=True)
v1.append((0, 0))
v2.append((0, 0))
if v1[0][0] != v2[0][0]:
    print(n - v1[0][1] - v2[0][1])
else:
    print(min(n - v1[0][1] - v2[1][1], n - v1[1][1] - v2[0][1]))

Submission status: Accepted

Solution code:
n = int(input())
v_list = list(map(int, input().split()))
count1 = [[0, i] for i in range(10**5)]
count2 = [[0, i] for i in range(10**5)]  # [v-1][数, 数値]

for i in range(0, n, 2):
    count1[v_list[i]-1][0] += 1
    count2[v_list[i+1]-1][0] += 1

count1 = sorted(count1)[::-1]
count2 = sorted(count2)[::-1]
if count1[0][1] == count2[0][1]:
    if count1[0][0] > count2[0][0]:
        ans = n - count1[0][0] - count2[1][0]
    elif count1[0][0] < count2[0][0]:
        ans = n - count2[0][0] - count1[1][0]
    else:
        ans = min(n - count2[0][0] - count1[1][0], n - count1[0][0] - count2[1][0])
else:
    ans = n - count1[0][0] - count2[0][0]
print(ans)

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = list(map(int,input().split()))
b,c = [],[]
nh = n // 2 
for i in range(nh):
    b.append(a[i*2])
    c.append(a[i*2+1])

cb = collections.Counter(b)
cc =collections.Counter(c)

cb2 = cb.most_common(2)
cc2 = cc.most_common(2)


if cb2[0] == cc2[0]:
    if len(cb2) == 1 and len(cc2) == 1:
        print(nh)
    elif len(cb2) == 1:
        print(nh - cc2[1][1])
    elif len(cc2) == 1:
        print(nh - cb2[1][1])
    elif cb2[1][1] >= cc2[1][1]:
        print(n - cb2[1][1] - cc2[0][1])
    else:
        print(n - cb2[0][1] - cc2[1][1])
else:
    print(n-cb2[0][1]-cc2[0][1])

Submission status: Accepted

Solution code:
N = int(input())
V = list(map(int,input().split()))
V1 = V[::2]
V2 = V[1::2]
V1_s = list(set(V1))
V2_s = list(set(V2))
S1 = len(V1_s)
S2 = len(V2_s)
if S1 == 1 and S2 == 1:
  if V1[0] != V2[0]:
    print(0)
  else:
    print(len(V) // 2)
else:
  V1_l = [0] * ((10 ** 5) + 1)
  V2_l = [0] * ((10 ** 5) + 1)
  for i in range(N // 2):
    V1_l[V1[i]] += 1
  for i in range(N // 2):
    V2_l[V2[i]] += 1
  S1_MAX = [V1_l.index(max(V1_l)),max(V1_l)]
  S2_MAX = [V2_l.index(max(V2_l)),max(V2_l)]
  if S1_MAX[0] != S2_MAX[0]:
    print(N - S1_MAX[1] - S2_MAX[1])
  else:
    V2_l.pop(S2_MAX[0])
    S2_MAX_s = [V2_l.index(max(V2_l)),max(V2_l)]
    ans1 = N - S1_MAX[1] - S2_MAX_s[1]
    V1_l.pop(S1_MAX[0])
    S1_MAX = [V1_l.index(max(V1_l)),max(V1_l)]
    ans2 = N - S1_MAX[1] - S2_MAX[1]
    print(min(ans1,ans2))

Submission status: Accepted

Solution code:
n = int(input())
low = [[0,i] for i in range(10**5+1)]
high = [[0,i] for i in range(10**5+1)]

v = list(map(int,input().split()))
for i,a in enumerate(v):
    if i%2==0:
        low[a][0] +=1
    else:
        high[a][0] +=1

low.sort(reverse=True)
high.sort(reverse=True)



if low[0][1] !=high[0][1]:
    ans = n-(low[0][0] +high[0][0])
else:
    ans = n - (low[0][0] + max(low[1][0],high[1][0]))
print(ans)

Submission status: Accepted

Solution code:
import collections

n=int(input())
V=list(map(int,input().split()))
V1=collections.Counter(V[0::2])
V2=collections.Counter(V[1::2])
V1v,V1c = zip(*V1.most_common())
V2v,V2c = zip(*V2.most_common())
V1v=list(V1v)
V1c=list(V1c)
V2v=list(V2v)
V2c=list(V2c)
V1v.append(-1)
V2v.append(-2)
V1c.append(0)
V2c.append(0)

if V1v[0] != V2v[0]:
    print(n-V1c[0]-V2c[0])
else:
    if V1c[1] >= V2c[1]:
        print(n-V1c[1]-V2c[0])
    else:
        print(n-V1c[0]-V2c[1])

Submission status: Accepted

Solution code:
from collections import Counter


def f(d, val):
    res = 0
    for elem, amount in d.items():
        if elem == val:
            continue
        res += amount
    return res


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

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

e1 = e.most_common()[0]
o1 = o.most_common()[0]

ans = 0
if e1 != o1:
    ans += f(e, e1[0])
    ans += f(o, o1[0])
else:
    if e1[1] > o1[1]:
        if len(o) < 2:
            ans += o1[1]
        else:
            ans += f(o, o.most_common()[1][0])
        ans += f(e, e1[0])
    elif e1[1] < o1[1]:
        if len(e) < 2:
            ans += e1[1]
        else:
            ans += f(e, e.most_common()[1][0])
        ans += f(o, o1[0])
    else:
        if len(o) == len(e) == 1:
            ans += e1[1]
        elif len(o) == 1:
            ans += f(e, e.most_common()[1][0])
        elif len(e) == 1:
            ans += f(o, o.most_common()[1][0])
        else:
            e2 = e.most_common()[1]
            o2 = o.most_common()[1]

            if e2[1] > o2[1]:
                ans += f(e, e2[0])
                ans += f(o, o1[0])
            else:
                ans += f(e, e1[0])
                ans += f(o, o2[0])
print(ans)

Submission status: Accepted

Solution code:
n, *v = map(int, open(0).read().split())
o, e = v[::2], v[1::2]
o.sort();e.sort()

on = []
prev = 0
cnt = 0
for i in o:
  if i==prev: cnt += 1
  else: on.append([prev,cnt]);cnt=1
  prev = i
on.append([prev,cnt])
on.sort(key=lambda x:x[1])


en = []
prev = 0
cnt = 0
for i in e:
  if i==prev: cnt += 1
  else: en.append([prev,cnt]);cnt=1
  prev = i
en.append([prev,cnt])
en.sort(key=lambda x:x[1])

if on[-1][0]==en[-1][0]:
  o=list(zip(*on))[1]
  e=list(zip(*en))[1]
  ans = sum(o)+sum(e)
  print(ans-max(o[-2]+e[-1],o[-1]+e[-2]))
else:
  o=list(zip(*on))[1]
  e=list(zip(*en))[1]
  print(sum(o)+sum(e)-o[-1]-e[-1])

Submission status: Accepted

Solution code:
n, *v = map(int, open(0).read().split())
o, e = v[::2], v[1::2]
o.sort();e.sort()

on = []
prev = 0
cnt = 0
for i in o:
  if i==prev: cnt += 1
  else: on.append([prev,cnt]);cnt=1
  prev = i
on.append([prev,cnt])
on.sort(key=lambda x:x[1])


en = []
prev = 0
cnt = 0
for i in e:
  if i==prev: cnt += 1
  else: en.append([prev,cnt]);cnt=1
  prev = i
en.append([prev,cnt])
en.sort(key=lambda x:x[1])

if on[-1][0]==en[-1][0]:
  o=list(zip(*on))[1]
  e=list(zip(*en))[1]
  ans = sum(o)+sum(e)
  print(ans-max(o[-2]+e[-1],o[-1]+e[-2]))
else:
  o=list(zip(*on))[1]
  e=list(zip(*en))[1]
  print(sum(o)+sum(e)-o[-1]-e[-1])

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
V = list(map(int, input().split()))
S1 = Counter([V[i] for i in range(0, N, 2)])
S2 = Counter([V[i] for i in range(1, N, 2)])

S1 = sorted(S1.items(), key=lambda x: x[1], reverse=True)
S2 = sorted(S2.items(), key=lambda x: x[1], reverse=True)
S1.append([0, 0])
S2.append([0, 0])

if S1[0][0] == S2[0][0]:
    ans = min(N-(S1[0][1]+S2[1][1]), N-(S1[1][1]+S2[0][1]))
else:
    ans = N - (S1[0][1] + S2[0][1])
print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
a_tmp = set(a)
if len(a_tmp) == 1:
    print(N//2)
    exit()
kisu = []
guu = []
for i in range(N):
    if i %2 ==0:
        guu.append(a[i])
    else:
        kisu.append(a[i])
kisu_c = collections.Counter(kisu)
guu_c = collections.Counter(guu)

kisu_max = kisu_c.most_common()[0][0]
guu_max = guu_c.most_common()[0][0]

if kisu_max == guu_max:
    tmp = len(a)-kisu.count(kisu_c.most_common()[0][0])-guu.count(guu_c.most_common()[1][0])
    tmp2 = len(a)-kisu.count(kisu_c.most_common()[1][0])-guu.count(guu_c.most_common()[0][0])
    if tmp < tmp2:
        print(tmp)
    else:
        print(tmp2)
    exit()

print(len(a)-kisu.count(kisu_max)-guu.count(guu_max))

Submission status: Accepted

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

#11
#6 7 1 2 1 2 1 2 6 5 6

import collections as cl
a0 = cl.Counter(o[0::2]).most_common()
a1 = cl.Counter(o[1::2]).most_common()
a0.append((0,0))
a1.append((0,0))
if a0[0] != a1[0]:
    count = n - a0[0][1] - a1[0][1]
else:
    count = min(n - a0[1][1] - a1[0][1], n - a0[0][1] - a1[1][1])

print(count)

Submission status: Accepted

Solution code:
n=int(input())

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

ki=[0]*100001
gu=[0]*100001

for i in range(n):
    if i%2==0:
        ki[l[i]]+=1
    else:
        gu[l[i]]+=1
km1=[max(ki),ki.index(max(ki))]
km2=[sorted(ki)[-2],ki.index(sorted(ki)[-2])]
gm1=[max(gu),gu.index(max(gu))]
gm2=[sorted(gu)[-2],gu.index(sorted(gu)[-2])]

if km1[1]!=gm1[1]:
    print(n-km1[0]-gm1[0])
else:
    if km1[0]-km2[0]>=gm1[0]-gm2[0]:
        print(n-km1[0]-gm2[0])
    else:
        print(n-gm1[0]-km2[0])

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
v = list(map(int, input().split()))
v_odd = []
v_even = []
for i in range(n):
  if i%2 == 0:
    v_odd.append(v[i])
  else:
    v_even.append(v[i])

vs_odd = np.array(v_odd)
vs_even = np.array(v_even)
count_odd = np.bincount(vs_odd)
count_even = np.bincount(vs_even)
mode_odd = np.argmax(count_odd)
mode_even = np.argmax(count_even)
a = v_odd.count(mode_odd)
b = v_even.count(mode_even)
if mode_odd != mode_even:
  print(n-a-b)
else:
  if len(v_odd) != v_odd.count(mode_odd):
    v_odd2 = [i for i in v_odd if i != mode_odd]
    vs_odd2 = np.array(v_odd2)
    count_odd2 = np.bincount(vs_odd2)
    mode_odd2 = np.argmax(count_odd2)
    a2 = v_odd.count(mode_odd2)
  else:
    a2 = 0
  if len(v_even) != v_even.count(mode_even):
    v_even2 = [i for i in v_even if i != mode_even]
    vs_even2 = np.array(v_even2)
    count_even2 = np.bincount(vs_even2)
    mode_even2 = np.argmax(count_even2)
    b2 = v_even.count(mode_even2)
  else:
    b2 = 0
  if a2 > b2:
    print(n-a2-b)
  else:
    print(n-a-b2)

Submission status: Accepted

Solution code:
import sys

def mode(list1):
    dic = {}
    for n in list1:
        if n in dic:
            dic[n] += 1
        else:
            dic[n] = 1
    max1 = 0
    num1  = -1
    for key in dic:
        if max1 < dic[key]:
            max1 = dic[key] 
            num1 = key

    max2 = 0
    num2 = -1
    for key in dic:
        if key == num1:
            continue
        if max2 < dic[key]:
            max2 = dic[key] 
            num2 = key
    return max1,num1,max2,num2

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

if min(vlist) == max(vlist):
    print(n//2)
    sys.exit()

alist=[]
blist=[]
for i in range(n//2):
    alist.append(vlist[2*i])
    blist.append(vlist[2*i+1])

amax,ka,amax2,ka2 = mode(alist)
bmax,kb,bmax2,kb2 = mode(blist)

if ka != kb:
    ans = n - amax - bmax
else:
    if amax2 <= bmax2:
        ans =n - amax -bmax2
    else:
        ans =n - bmax -amax2
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

ans = int(input())
V = [int(i) for i in input().split()]

v1 = []
v2 = []

for i, v in enumerate(V):
    if i % 2 == 0:
       v1.append(v)
    else:
        v2.append(v)

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

k1, v1 = v1c[0][0], v1c[0][1]
k2, v2 = v2c[0][0], v2c[0][1]

if k1 == k2:
    ans -= v2
    m = 0
    if len(v1c) >= 2:
        m = max(m, v1c[1][1])
    if len(v2c) >= 2:
        m = max(m, v2c[1][1])
    ans -= m
else:
    ans -= v1 + v2

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

E = list(Counter(V[0::2]).most_common())+[(10001,0)]
O = list(Counter(V[1::2]).most_common())+[(10002,0)]

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

Submission status: Accepted

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

even = list(Counter(V[0::2]).most_common())
even.append((100001,0))
odd = list(Counter(V[1::2]).most_common())
odd.append((100001,0))
if even[0][0] == odd[0][0]:
    o = []
    o.append(even[0][1]+odd[1][1])
    o.append(even[1][1]+odd[0][1])
    print(N-max(o))
else:
    print(N-even[0][1]-odd[0][1])

Submission status: Accepted

Solution code:
from collections import Counter

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

E = list(Counter(V[0::2]).most_common())
O = list(Counter(V[1::2]).most_common())
E.append((10001,0))
O.append((10002,0))

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

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())

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

odds = []
evens = []

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

evens_c = Counter(evens).most_common(2)
odds_c = Counter(odds).most_common(2)

if evens_c[0][0] != odds_c[0][0]:
    print(n - evens_c[0][1] - odds_c[0][1])
    exit()

if len(evens_c) == 1 or len(odds_c) == 1:
    print(n // 2)
    exit()

print(n - max(evens_c[0][1] + odds_c[1][1], evens_c[1][1] + odds_c[0][1]))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input()) # even
    V=list(map(int,input().split()))
    # 1種類しかないときはindexの関係上別処理する
    if len(set(V))==1:
        print(n//2)
        return
    from collections import Counter
    E=Counter(V[::2]).most_common() # list of tuple
    O=Counter(V[1::2]).most_common()
    if E[0][0]!=O[0][0]:
        print(n-E[0][1]-O[0][1])
    elif E[0][1]>O[0][1]:
        print(n-E[0][1]-O[1][1])
    elif E[0][1]<O[0][1]:
        print(n-E[1][1]-O[0][1])
    else:
        print(min(n-E[0][1]-O[1][1],n-E[1][1]-O[0][1]))
resolve()

Submission status: Accepted

Solution code:
import collections

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


odd=collections.Counter(v[::2])
even = collections.Counter(v[1::2])

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

Submission status: Accepted

Solution code:
import numpy as np

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

list1=[0]*(1+10**5)
list2=[0]*(1+10**5)

for i in range(0, n, 2):
  list1[v[i]]+=1
  
for i in range(1, n, 2):
  list2[v[i]]+=1
  
n1=np.max(list1)
m1=np.argmax(list1)
n2=np.max(list2)
m2=np.argmax(list2)

if m1!=m2:
  print(n-(n1+n2))
else:
  list1[m1]=0
  list2[m2]=0
  n12=np.max(list1)
  n22=np.max(list2)
  print(n-max(n1+n22, n2+n12))

Submission status: Accepted

Solution code:
import collections

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


v_odd = v[1::2]
v_even = v[::2]

vc_odd = collections.Counter(v_odd)
vc_even = collections.Counter(v_even)

odd_common = vc_odd.most_common()
even_common = vc_even.most_common()
if odd_common[0][0] != even_common[0][0]:
    print(n - odd_common[0][1] - even_common[0][1])
else:
    if len(odd_common) == 1 and len(even_common) == 1:
        print(len(v_even))
    elif len(odd_common) == 1:
        print(n - odd_common[0][1] - even_common[1][1])
    elif len(even_common) == 1:
        print(n - odd_common[1][1] - even_common[0][1])
    else:
        cnt1 = n - odd_common[1][1] - even_common[0][1]
        cnt2 = n - odd_common[0][1] - even_common[1][1]
        print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
import collections

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])
evenc = collections.Counter(even)
oddc = collections.Counter(odd)
#print(evenc, oddc)

evenm = evenc.most_common()
oddm = oddc.most_common()
if evenm[0][0] == oddm[0][0]:
    if len(oddm) == 1:
        ans = n // 2
    else:
        ans = min(n - evenm[0][1] - oddm[1][1], n - evenm[1][1] - oddm[0][1])
else:
    ans = n - evenm[0][1] - oddm[0][1]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
v = list(map(int, input().split()))
even_list = [0] * (100000 + 1)
odd_list = [0] * (100000 + 1)

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

    else:
        odd_list[v[i]] += 1

if even_list.index(max(even_list)) == odd_list.index(max(odd_list)):
    even_sorted, odd_sorted = sorted(even_list), sorted(odd_list)
    print(min(n - even_sorted[-1] - odd_sorted[-2], n - even_sorted[-2] - odd_sorted[-1]))

else:
    print(n - max(even_list) - max(odd_list))

Submission status: Accepted

Solution code:
n = int(input())
V = list(map(int,input().split()))
De = {}
Do = {}
for i in range(n):
    x = V[i]
    if i%2==0:
        if x not in De:
            De[x] = 0
        De[x] += 1
    else:
        if x not in Do:
            Do[x] = 0
        Do[x] += 1
DeL = sorted(list(De.items()),key=lambda x:x[1],reverse=True)
DoL = sorted(list(Do.items()),key=lambda x:x[1],reverse=True)
y = DeL[0][0]
z = DoL[0][0]
if y!=z:
    n0 = n//2-De[y]
    n1 = n//2-Do[z]
elif y==z:
    if De[y]>Do[z]:
        z = DoL[1][0]
        n0 = n//2-De[y]
        n1 = n//2-Do[z]
    elif De[y]<Do[z]:
        y = DeL[1][0]
        n0 = n//2-De[y]
        n1 = n//2-Do[z]
    elif De[y]==Do[z]:
        if De[y]==n//2:
            n0 = 0
            n1 = n//2
        elif DeL[1][1]>=DoL[1][1]:
            y = DeL[1][0]
            n0 = n//2-De[y]
            n1 = n//2-Do[z]
        else:
            z = DoL[1][0]
            n0 = n//2-De[y]
            n1 = n//2-Do[z]
print(n0+n1)

Submission status: Accepted

Solution code:
from collections import Counter
if __name__ == '__main__':
    N = int(input())
    V = list(map(int, input().split()))
    V_low = []
    V_up = []
    for i, v in enumerate(V):
        if i%2 == 0:
            V_low.append(v)
        else:
            V_up.append(v)
    

    count_low = Counter(V_low).most_common()
    count_up = Counter(V_up).most_common()
    
    low_most = count_low[0][0]
    up_most = count_up[0][0]
    
    if low_most != up_most:
        print(len(V_low) + len(V_up) - count_low[0][1] - count_up[0][1])
    else:
        if count_low[0][1] > count_up[0][1]:
            if(len(count_up) == 1):
                print(len(V_low) + len(V_up) - count_low[0][1])
            else:
                print(len(V_low) + len(V_up) - count_low[0][1] - count_up[1][1])
        elif count_low[0][1] <  count_up[0][1]:
            if(len(count_low) == 1):
                print(len(V_low) + len(V_up) - count_up[0][1])
            else:
                print(len(V_low) + len(V_up) - count_up[0][1] - count_low[1][1])
        else:
            if len(count_up) != 1 and len(count_low) != 1:
                if count_low[1][1] <= count_up[1][1]:
                    print(len(V_low) + len(V_up) - count_low[0][1] - count_up[1][1])
                else:
                    print(len(V_low) + len(V_up) - count_up[0][1] - count_low[1][1])
            else:
                if len(count_low) == 1 and len(count_up) == 1:
                    print(len(V_low) + len(V_up) - count_low[0][1])
                elif len(count_low) == 1:
                    print(len(V_low) + len(V_up) - count_low[0][1] - count_up[1][1])
                else:
                    print(len(V_low) + len(V_up) - count_up[0][1] - count_low[1][1])

Submission status: Accepted

Solution code:

from collections import Counter as ct

n = int(input())
a = [int(i) for i in input().split()]
oddlists=[a[i] for i in range(n)if i%2==0]
evenlists=[a[i]for i in range(n) if i%2!=0]

a1=ct(oddlists).most_common()
a2=ct(evenlists).most_common()


min1=a1[0][1]
min2=a2[0][1]
if a1[0][0]!=a2[0][0]:
    print(n-min1-min2)
if a1[0][0]==a2[0][0]:
    if a1[0][1]==int(n/2):
        print(int(n/2))
    elif a1[0][1]<int(n/2):
        print(min(n-a1[0][1]-a2[1][1],n-a2[0][1]-a1[1][1]))

Submission status: Accepted

Solution code:
n = int(input())
V = [int(v) for v in input().split(' ')]

even_map = {}
odd_map = {}

for i in range(0, n, 2):
    v = V[i]
    if not v in even_map:
        even_map[v] = 1
    else:
        even_map[v] += 1


for i in range(1, n, 2):
    v = V[i]
    if not v in odd_map:
        odd_map[v] = 1
    else:
        odd_map[v] += 1

even_map[0] = 0
odd_map[0] = 0
even_sorted = sorted(even_map.items(), key=lambda x: -x[1])
odd_sorted = sorted(odd_map.items(), key=lambda x: -x[1])

even1 = even_sorted[0][0]
odd1 = odd_sorted[0][0]

if even1 != odd1:
    print(n - (even_sorted[0][1] + odd_sorted[0][1]))
    exit()

print(min(n - (even_sorted[0][1] + odd_sorted[1][1]), n - (odd_sorted[0][1] + even_sorted[1][1])))

Submission status: Accepted

Solution code:
def sura_backsura():
    import collections

    N = int(input())
    a = [int(i) for i in input().split()]

    fp = collections.Counter(a[0::2]).most_common()
    sp = collections.Counter(a[1::2]).most_common()

    fp.append((0, 0))
    sp.append((0, 0))

    if fp[0] != sp[0]:
        count = N - fp[0][1] - sp[0][1]
    else:
        count = min(N - fp[0][1] - sp[1][1], N - fp[1][1] - sp[0][1])

    print(count)
    
if __name__ == "__main__":
    sura_backsura()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
#一時保存
import collections

n=int(input())
li=list(map(int,input().split()))
l=[]
r=[]

for i in range(n):
    if i%2==0:
        l.append(li[i])
    else:
        r.append(li[i])

l_cnt=collections.Counter(l)
r_cnt=collections.Counter(r)


ll=l_cnt.most_common(2)
rr=r_cnt.most_common(2)
#if文多すぎ

if ll[0][0]==rr[0][0]:
    if len(ll)==1 and len(rr)==1:
        print(n//2)
    elif len(ll)==1:
        print(n//2-rr[-1][1])
    elif len(rr)==1:
        print(n//2-ll[-1][1])
    else:
        print((n-max(ll[0][1]+rr[1][1],ll[1][1]+rr[0][1])))
else:
    print(n-ll[0][1]-rr[0][1])

Submission status: Accepted

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

odd = collections.defaultdict(int)

even = collections.defaultdict(int)

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

    else:
        odd[v[i]] += 1

even = list(even.items())
odd = list(odd.items())

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

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

Submission status: Accepted

Solution code:
import collections as col
N= int(input())
A = [int(x) for x in input().split()]
a = A[::2]

a = col.Counter(a)
b = A[1::2]

b = col.Counter(b)
ans = 0
i = 0
j = 0
if len(a.most_common())==1 and len(b.most_common())==1 and a.most_common()[i][0]==b.most_common()[j][0]:
  print(N//2)
  exit()
while a.most_common()[i][0]==b.most_common()[j][0]:
  m=a.most_common()[i][1]
  n=b.most_common()[j][1]
  if m>n:
    j +=1
  elif m==n:
      if a.most_common()[i+1][1]>b.most_common()[j+1][1]:
        i+=1
      else:
        j +=1
  else:
    i +=1
#print(i,j,a,b)
ans += sum(a.values())+sum(b.values())-a.most_common()[i][1]-b.most_common()[j][1]
print(ans)

Submission status: Accepted

Solution code:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

count = 0

from collections import Counter

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

od = Counter(odd)
ev = Counter(even)

# これをいれとかないと、最頻値が１しか無い時に２つめを取得できなくなる
od[0] = 0
ev[0] = 0

# 1要素だけ取得
co1 = od.most_common(1)
ce1 = ev.most_common(1)

# 多い順に2要素だけ取得
co2 = od.most_common(2)
ce2 = ev.most_common(2)

# 最頻値が同じ場合は、odd/evenの片方を二番目の最頻値にして、少ない方を採用
if co1[0][0] == ce1[0][0]:
    print(min(N - co1[0][1] - ce2[1][1], N - co2[1][1] - ce1[0][1]))
else:
    # 違う場合は、出現回数を引いてやればいい
    print(N - co1[0][1] - ce1[0][1])

Submission status: Accepted

Solution code:
n = int(input())
vs = list(map(int, input().split()))
es = {}
os = {}
for i, v in enumerate(vs):
    if i % 2 == 0:
        v0 = es.get(v, 0)
        es[v] = v0 + 1
    else:
        v0 = os.get(v, 0)
        os[v] = v0 + 1

es_max = max(es, key=es.get)
es_cnt = sum(es.values())
es_ch_len = es_cnt - es[es_max]
del es[es_max]

os_max = max(os, key=os.get)
os_cnt = sum(os.values())
os_ch_len = os_cnt - os[os_max]
del os[os_max]

if os_max == es_max:
    if es == {}:
        es_len = 0
    else:
        es_snd = max(es, key=es.get)
        es_len = es[es_snd]
    if os == {}:
        os_len = 0
    else:
        os_snd = max(os, key=os.get)
        os_len = os[os_snd]
    if es_len > os_len:
        es_ch_len = es_cnt - es_len
    else:
        os_ch_len = os_cnt - os_len

print(os_ch_len+es_ch_len)

Submission status: Accepted

Solution code:
from collections import Counter

input()
V = [int(v) for v in input().split()]
count1 = 0
count2 = 0
c11 = Counter(V[::2]).most_common()[0][0]
c12 = Counter(V[1::2]).most_common()[0][0]
for v1, v2 in zip(V[::2], V[1::2]):
    if v1 != c11:
        count1 += 1
    if v2 != c12:
        count2 += 1
c21 = Counter(V[1::2]).most_common()
c22 = Counter(V[::2]).most_common()
c21.append((0, 1))
c22.append((0, 1))
c21 = c21[0][0] if c21[0][0] != c11 else c21[1][0]
c22 = c22[0][0] if c22[0][0] != c12 else c22[1][0]
for v1, v2 in zip(V[1::2], V[::2]):
    if v1 != c21:
        count1 += 1
    if v2 != c22:
        count2 += 1
print(min(count1, count2))