Problem:


Score : 300 points

Problem Statement

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

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

Exactly two different numbers appear in the sequence.

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

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

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

Sample Input 1

4
3 1 3 2

Sample Output 1

1

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

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

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

Sample Input 3

4
1 1 1 1

Sample Output 3

2

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



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Accepted

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

odd_li = []
even_li = []
for i in range(n):
    if i%2==0:
        odd_li.append(v_input[i])
    else:
        even_li.append(v_input[i])

odd_count = sorted(Counter(odd_li).items(),key=lambda x:x[1],reverse=True)
even_count = sorted(Counter(even_li).items(),key=lambda x:x[1],reverse=True)

odd_max = odd_count[0][0]
even_max = even_count[0][0]

if odd_max==even_max and len(odd_count)==1:
    ans = n//2

elif odd_max==even_max:
    odd_next = odd_count[1][1]
    even_next = even_count[1][1]
    ans = n//2-odd_count[0][1] + n//2 - max(odd_next,even_next)
else:
    ans = n//2-odd_count[0][1] + n//2 - even_count[0][1]

print(ans)

Submission status: Accepted

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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    n = readint()
    v = list(readnums())
    ve = [x for i, x in enumerate(v) if not i % 2]
    vo = [x for i, x in enumerate(v) if i % 2]
    cve = Counter(ve)
    cvo = Counter(vo)
    if cve.most_common()[0][0] == cvo.most_common()[0][0]:
        if len(cve) == 1:
            print(n // 2)
        else:
            print(min(len(ve) - cve.most_common()[1][1] + len(vo) - cvo.most_common()[0][1], len(ve) - cve.most_common()[0][1] + len(vo) - cvo.most_common()[1][1]))
    else:
        print(len(ve) - cve.most_common()[0][1] + len(vo) - cvo.most_common()[0][1])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
count1 = defaultdict(int)
count2 = defaultdict(int)
for i in range(0, n, 2):
    count1[v[i]] += 1
for i in range(1, n, 2):
    count2[v[i]] += 1
res = 0
max_count1 = max(count1.values())
max_count2 = max(count2.values())
max_key1 = 0
max_key2 = 0
for key, value in count1.items():
    res += value
    if value == max_count1:
        max_key1 = key
for key, value in count2.items():
    res += value
    if value == max_count2:
        max_key2 = key
res = res - max_count1 - max_count2
ans1 = 0
ans2 = 0
ans = 0
if max_key1 == max_key2:
    ans1 = res + max_count1
    count1[max_key1] = 0
    next_max_count1 = max(count1.values())
    ans1 -= next_max_count1

    ans2 = res + max_count2
    count2[max_key2] = 0
    next_max_count2 = max(count2.values())
    ans2 -= next_max_count2
    ans = min(ans1, ans2)
else:
    ans = res
print(ans)

Submission status: Accepted

Solution code:
def main():
    from collections import Counter

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

    ctr_odd = Counter(V[::2])
    ctr_odd[-1] = 0  # 番兵

    ctr_even = Counter(V[1::2])
    ctr_even[-1] = 0  # 番兵

    ans = N
    for odd_n, odd_c in ctr_odd.most_common(2):
        for even_n, even_c in ctr_even.most_common(2):
            if odd_n == even_n: continue
            ans = min(ans, N - odd_c - even_c)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())
v = readints()
cnt = 0
tmp = [0]*(10**5+1)
tmp2 = [0]*(10**5+1)
for i in range(n):
    if i % 2 == 0:
        tmp[v[i]] += 1
    else:
        tmp2[v[i]] += 1
tmp_max = 0
tmp2_max = 0
for i in range(len(tmp)):
    if tmp[tmp_max] < tmp[i]:
        tmp_max = i
for i in range(len(tmp2)):
    if tmp2[tmp2_max] < tmp2[i]:
        tmp2_max = i
if tmp_max != tmp2_max:
    cnt += (n//2)-tmp[tmp_max]
    cnt += (n//2)-tmp2[tmp2_max]
    print(cnt)
    exit()
tmp_max2 = 0
tmp2_max2 = 0
cnt2 = 0
cnt3 = 0
for i in range(len(tmp)):
    if i != tmp_max:
        if tmp[tmp_max2] < tmp[i]:
            tmp_max2 = i
for i in range(len(tmp2)):
    if i != tmp2_max:
        if tmp2[tmp2_max2] < tmp2[i]:
            tmp2_max2 = i
cnt2 = (n//2)-tmp[tmp_max]+(n//2)-tmp2[tmp2_max2]
cnt3 = (n//2)-tmp2[tmp2_max]+(n//2)-tmp[tmp_max2]
print(min(cnt2, cnt3))
# print(tmp_max)
# print(tmp2_max)
# print(tmp_max2)
# print(tmp2_max2)

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    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 i % 2 == 1]

    # a_count = Counter.most_common(Counter(a))
    # b_count = Counter.most_common(Counter(b))

    # half_n = n // 2
    ac = Counter(v[::2]).most_common(2)
    bc = Counter(v[1::2]).most_common(2)

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

    # ans = 0

    # half_n = n // 2
    # eq = a_count[0][0] == b_count[0][0]
    # h_ac0 = half_n - a_count[0][1]
    # h_bc0 = half_n - b_count[0][1]

    # if len(a_count) == 1 and len(b_count) == 1:
    #     if eq:
    #         print(half_n)
    #         exit()
    #     else:
    #         print(ans)
    #         exit()

    # if a_count[0][1] > b_count[0][1]:
    #     ans += h_ac0
    #     if eq:
    #         ans += half_n - b_count[1][1]
    #     else:
    #         ans += h_bc0
    # elif a_count[0][1] < b_count[0][1]:
    #     ans += h_bc0
    #     if eq:
    #         ans += half_n - a_count[1][1]
    #     else:
    #         ans += h_ac0
    # else:
    #     if eq:
    #         ans += h_ac0
    #         ans += half_n - b_count[1][1]
    #     else:
    #         ans += h_ac0
    #         ans += h_bc0
    # print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

t = collections.defaultdict(int)
t2 = collections.defaultdict(int)
for x in odd:
    t[x] += 1
for x in even:
    t2[x] += 1

t = list(t.items())
t.sort(key = lambda x:x[1], reverse=True)

t2 = list(t2.items())
t2.sort(key = lambda x:x[1],reverse=True)


t.append([0, 0])
t2.append([0, 0])
ans = t[0][1] + t2[0][1]
if t[0][0] == t2[0][0]:
    ans = max(t[0][1] + t2[1][1], t[1][1]+t2[0][1])
print(n - ans)

Submission status: Accepted

Solution code:
import collections

n = int(input())

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

v1 = v[::2]

v2 = v[1::2]
        
if len(set(v))==1:
    print(n//2)
else:
    maxv1 = collections.Counter(v1).most_common()

    maxv2 = collections.Counter(v2).most_common()


    if maxv1[0][0] == maxv2[0][0]:    
        ans1 = (len(v1) - maxv1[0][1]) + (len(v2) - maxv2[1][1])
        ans2 = (len(v1) - maxv1[1][1]) + (len(v2) - maxv2[0][1])
        print(min(ans1, ans2))
    else:
        ans = (len(v1) - maxv1[0][1]) + (len(v2) - maxv2[0][1])
        print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
odd = [k for i, k in enumerate(v) if i % 2 == 1]
even = [k for i, k in enumerate(v) if i % 2 == 0]

odd = collections.Counter(odd).most_common()
even = collections.Counter(even).most_common()

odd.append([0, 0])
even.append([0, 0])
ans = odd[0][1] + even[0][1]
if odd[0][0] == even[0][0]:
    ans = max(odd[0][1] + even[1][1], odd[1][1]+even[0][1])
print(n - ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    v = list(map(int, input().split()))
    ev, od = [], []
    for i in range(n):
        if i % 2 == 0:
            ev.append(v[i])
        else:
            od.append(v[i])

    cnt_ev = sorted(Counter(ev).items(), key=lambda x: x[1], reverse=True)
    cnt_od = sorted(Counter(od).items(), key=lambda x: x[1], reverse=True)

    if len(cnt_ev) == 1 and len(cnt_od) == 1:
        if cnt_ev[0][0] == cnt_od[0][0]:
            res = n // 2
            print(res)
        else:
            res = 0
            print(res)
    elif len(cnt_ev) == 1:
        if cnt_ev[0][0] == cnt_od[0][0]:
            res = n // 2 - cnt_od[1][1]
            print(res)
        else:
            res = n // 2 - cnt_od[0][1]
            print(res)
    elif len(cnt_od) == 1:
        if cnt_ev[0][0] == cnt_od[0][0]:
            res = n // 2 - cnt_ev[1][1]
            print(res)
        else:
            res = n // 2 - cnt_ev[0][1]
            print(res)
    else:
        if cnt_ev[0][0] == cnt_od[0][0]:
            res1 = n - cnt_ev[0][1] - cnt_od[1][1]
            res2 = n - cnt_ev[1][1] - cnt_od[0][1]
            res = min(res1, res2)
            print(res)
        else:
            res = n - cnt_ev[0][1] - cnt_od[0][1]
            print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
v = list(map(int, input().split()))
freq_odd = [0] * (10 ** 5 + 1)
freq_even = [0] * (10 ** 5 + 1)
for i in range(n // 2):
    freq_odd[v[2 * i]] += 1
    freq_even[v[2 * i + 1]] += 1
# print(freq_odd[:10], freq_even[:10])
freq_even, id_even = zip(*sorted(zip(freq_even, range(10 ** 5 + 1))))
freq_odd, id_odd = zip(*sorted(zip(freq_odd, range(10 ** 5 + 1))))
# print(freq_odd[-2:], freq_even[-2:])
# print(id_even[-1], id_odd[-1])
if id_even[-1] != id_odd[-1]:
    print(n - freq_even[-1] - freq_odd[-1])
else:
    print(min(n - freq_even[-2] - freq_odd[-1], n - freq_even[-1] - freq_odd[-2]))

Submission status: Accepted

Solution code:
from collections import Counter

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

c1 = Counter(V[::2]).most_common(2)
c2 = Counter(V[1::2]).most_common(2)

c1 = dict(list(c1))
c2 = dict(list(c2))
c1[-1] = 0
c2[-2] = 0

MAX = 0
for k,v in c1.items():
    for k2,v2 in c2.items():
        if k != k2:
            MAX = max(v+v2,MAX)

print(N - MAX)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

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

cve = Counter(v_even)
cvo = Counter(v_odd)

if cve.most_common()[0][0] != cvo.most_common()[0][0]:
    ans = (n//2 - cve.most_common()[0][1]) + (n//2 - cvo.most_common()[0][1])
else:
    ans = min((n//2 - cve.most_common()[1][1]) + (n//2 - cvo.most_common()[0][1]), (n//2 - cve.most_common()[0][1]) + (n//2 - cvo.most_common()[1][1]))

print(ans)

Submission status: Accepted

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

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

t = collections.Counter(odd).most_common()
t2 = collections.Counter(even).most_common()


t.append([0, 0])
t2.append([0, 0])
ans = t[0][1] + t2[0][1]
if t[0][0] == t2[0][0]:
    ans = max(t[0][1] + t2[1][1], t[1][1]+t2[0][1])
print(n - ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
v = list(map(int,input().split()))
v1 = v[::2]
v2 = v[1::2]
from collections import Counter
cv1 = Counter(v1).most_common()
cv2 = Counter(v2).most_common()
cv1.append((0,0))
cv2.append((0,0))

if cv1[0][0] == cv2[0][0]:
    ans = n - max(cv1[0][1] + cv2[1][1], cv1[1][1] + cv2[0][1])
else:
    ans = n - cv1[0][1] - cv2[0][1]
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    v = list(map(int, input().split()))
    ol = {}
    el = {}
    for i in range(len(v)):
        if i % 2 == 0:
            if v[i] in ol:
                ol[v[i]] += 1
            else:
                ol[v[i]] = 1
        else:
            if v[i] in el:
                el[v[i]] += 1
            else:
                el[v[i]] = 1
    ol = sorted(ol.items(), key=lambda x: x[1], reverse=True)
    el = sorted(el.items(), key=lambda x: x[1], reverse=True)

    # ol 1st
    if ol[0][0] != el[0][0]:
        print(len(v)-ol[0][1]-el[0][1])
    else:
        ofix = ol[0][0]
        if len(el) == 1:
            ans1 = len(v)-ol[0][1]
        else:
            ans1 = len(v)-ol[0][1]-el[1][1]
        efix = el[0][0]
        if len(ol) == 1:
            ans2 = len(v)-el[0][1]
        else:
            ans2 = len(v)-el[0][1]-ol[1][1]
        print(min(ans1, ans2))
resolve()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[0]*100009
c=[0]*100009
for i in range(n//2):
  b[a[i*2]]+=1
  c[a[i*2+1]]+=1
t=max(b)
r=max(c)
s=b.index(t)
p=c.index(r)
if s==p:
  b[s]=0
  k=max(b)
  c[p]=0
  j=max(c)
  f=max(k+r,t+j)
else:
  f=t+r
print(n-f)

Submission status: Accepted

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

ans = float("inf")
for i in range(2):
  for j in range(2):
    if i < len(e) and j < len(o):
      if e[i][0] == o[j][0]:
        continue
      else:
        ans = min(ans,n-(e[i][1]+o[j][1]))
if ans ==  float("inf"):
  ans = n//2       
print(ans)

Submission status: Accepted

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

from collections import Counter
c1 = Counter(V[::2])
c2 = Counter(V[1::2])
m1 = c1.most_common()
m2 = c2.most_common()

if m1[0][0] != m2[0][0]:
    ans = N - m1[0][1] - m2[0][1]
    print(ans)
    exit()
if len(m1) == len(m2) == 1:
    print(N//2)
    exit()

ans = N
if len(m1) > 1 and m1[1][0] != m2[0][0]:
    ans = min(ans, N - m1[1][1] - m2[0][1])
if len(m2) > 1 and m1[0][0] != m2[1][0]:
    ans = min(ans, N - m1[0][1] - m2[1][1])
if len(m1) > 1 and len(m2) > 1 and m1[1][0] != m2[1][0]:
    ans = min(ans, N - m1[1][1] - m2[1][1])
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc111/tasks/arc103_a
# v[::2],v[1::2]に分けて考える
# vの一番多い要素をカウント
# ただし、前者と後者d一番多い要素が等しい場合は、どちらかの二番目を用いる

n = read_a_int()
V = read_ints()

cnt0 = [(0, 0)] + list(Counter(V[::2]).items())
cnt1 = [(0, 0)] + list(Counter(V[1::2]).items())
cnt0.sort(key=itemgetter(1))
cnt1.sort(key=itemgetter(1))

if cnt0[-1][0] == cnt1[-1][0]:
    second = max(cnt0[-2][1], cnt1[-2][1])
    first = max(cnt0[-1][1], cnt1[-1][1])
    print(n - (second + first))
else:
    print(n - (cnt0[-1][1] + cnt1[-1][1]))

Submission status: Accepted

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

from collections import defaultdict

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

dic1 = defaultdict(int)
dic2 = defaultdict(int)

for v in V[::2]:
    dic1[v] += 1
for v in V[1::2]:
    dic2[v] += 1

lst1 = [[dic1[i], i] for i in dic1]
lst2 = [[dic2[i], i] for i in dic2]

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

ans = N
if lst1[0][1] != lst2[0][1]:
    ans = N - lst1[0][0] - lst2[0][0]
else:
    if len(lst1) == 1:
        if len(lst2) == 1:
            ans = N // 2
        else:
            ans = N - lst1[0][0] - lst2[1][0]
    elif len(lst2) == 0:
        ans = N - lst1[1][0] - lst2[0][0]
    else:
        ans = N - max(lst1[0][0] + lst2[1][0], lst1[1][0] + lst2[0][0])

print (ans)

Submission status: Accepted

Solution code:
from collections import Counter
 
n, *v = map(int, open(0).read().split())
c1 = Counter(v[::2]).most_common()
c2 = Counter(v[1::2]).most_common()
 
c1.append([0, 0])
c2.append([0, 0])
 

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

Submission status: Accepted

Solution code:
n = int(input())
v = list(map(int, input().split()))
odds = {}
evens = {}
for i in v[0::2]:
    if i in odds:
        odds[i] += 1
    else:
        odds[i] = 1
for i in v[1::2]:
    if i in evens:
        evens[i] += 1
    else:
        evens[i] = 1
odds = list(odds.items())
evens = list(evens.items())
odds.sort(key=lambda x:-x[1])
evens.sort(key=lambda x:-x[1])
odds.append((None, 0))
evens.append((None, 0))
if odds[0][0]!=evens[0][0]:
    print(n-odds[0][1]-evens[0][1])
else:
    print(n-max(odds[0][1]+evens[1][1], odds[1][1]+evens[0][1]))

Submission status: Accepted

Solution code:
import collections
n = int(input())
v = [int(i) for i in input().split()]
kisu = []
gusu = []

kisu = v[::2]
gusu = v[1::2]

kisu_cnt = collections.Counter(kisu)
gusu_cnt = collections.Counter(gusu)

kisu_cnt = kisu_cnt.most_common(2)#引数にnを用意すると，出現回数の多い順にn子だけ呼び出せる
gusu_cnt = gusu_cnt.most_common(2)
kisu_most  = 0
gusu_most = 0
if kisu_cnt[0][0]!=gusu_cnt[0][0]:
    print(n-kisu_cnt[0][1]-gusu_cnt[0][1])
    exit()
else:
    if len(kisu_cnt)==1 or len(gusu_cnt)==1:
        print(n//2)
        exit()
    else:
        print(n-max(kisu_cnt[0][1]+gusu_cnt[1][1],kisu_cnt[1][1]+gusu_cnt[0][1]))

Submission status: Accepted

Solution code:
from collections import Counter

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


o = Counter(l[::2]).most_common()
e = Counter(l[1::2]).most_common()

if o[0][0] == e[0][0]:
    if len(o) == 1:
        print(N//2)
    else:
        e1, e2 = o[0][1], o[1][1]
        o1, o2 = e[0][1], e[1][1]

        res = min(N-e1-o2, N-e2-o1)
        print(res)
else:
    print(N - o[0][1] - e[0][1])

Submission status: Accepted

Solution code:
#ABC111C
import collections
def main():
    n=int(input())
    v=list(map(int,input().split()))
    ve=[]
    vo=[]
    for i in range(n//2):
        ve.append(v[2*i])
        vo.append(v[2*i+1])
    ce=collections.Counter(ve)
    co=collections.Counter(vo)
    ans=n
    if ce.most_common()[0][0]!=co.most_common()[0][0]:
        ans=n-ce.most_common()[0][1]-co.most_common()[0][1]
    elif len(ce)==1 and len(co)==1:
        ans=n-ce.most_common()[0][1]
    elif len(ce)==1:
        ans=n-ce.most_common()[0][1]-co.most_common()[1][1]
    elif len(co)==1:
        ans=n-ce.most_common()[1][1]-co.most_common()[0][1]
    else:
        ans=min(n-ce.most_common()[0][1]-co.most_common()[1][1],n-ce.most_common()[1][1]-co.most_common()[0][1])
    print(ans)
if __name__=="__main__":
    main()

Submission status: Accepted

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

n = len(v)
from collections import defaultdict
c0 = defaultdict(int)
for vi in v[0::2]:
    c0[vi] += 1
c1 = defaultdict(int)
for vi in v[1::2]:
    c1[vi] += 1

sc0 = sorted(c0.items(), key=lambda x: x[1])
sc1 = sorted(c1.items(), key=lambda x: x[1])
#print(n)
#print(sc0)
#print('------------------')
#print(sc1)
if sc0[-1][0] != sc1[-1][0]:
    #print('--1')
    print(n//2 - sc0[-1][1] + n//2 - sc1[-1][1])
    exit()
if len(sc0) == 1 and len(sc1) == 1:
    #print('--2')
    print(n//2)
    exit()
if sc0[-1][1] > sc1[-1][1]:
    #print('--3')
    print(n//2 - sc0[-1][1] + n//2 - sc1[-2][1])
    exit()
if sc0[-1][1] < sc1[-1][1]:
    #print('--4')
    print(n//2 - sc0[-2][1] + n//2 - sc1[-1][1])
    exit()
if sc0[-1][1] == sc1[-1][1]:
    if sc0[-2][1] < sc1[-2][1]:
        #print('--1',sc0[-1][1],sc1[-1][1], sc0[-2][1],sc1[-2][1])
        print(n//2 - sc0[-1][1] + n//2 - sc1[-2][1])
    else:
        #print('--1',sc0[-1][1],sc1[-1][1], sc0[-2][1],sc1[-2][1])
        print(n//2 - sc0[-2][1] + n//2 - sc1[-1][1])
    exit()

#(92753, 12393), (2054, 12394), (27775, 12395)
#(55530, 10),    (50652, 12393),   (27775, 12395)

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split(' ')))
    v_odd, v_even = list(), list()
    for i in range(n):
        if i % 2 == 0:
            v_even.append(v[i])
        else:
            v_odd.append(v[i])
    assert len(v_odd) == len(v_even)
    odd_top2 = Counter(v_odd).most_common(2)
    even_top2 = Counter(v_even).most_common(2)
    if odd_top2[0][0] != even_top2[0][0]:
        print(n - odd_top2[0][1] - even_top2[0][1])
    else:
        d1 = n - odd_top2[0][1] - (0 if len(even_top2) == 1 else even_top2[1][1])
        d2 = n - even_top2[0][1] - (0 if len(odd_top2) == 1 else odd_top2[1][1])
        print(min([d1, d2]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)

inf = 10 ** 15
mod = 10 ** 9 + 7
n = int(input())
v = list(map(int, input().split()))

# 偶数番目の要素において、iの数が何個あったか
even = [0 for i in range(100001)]
# 奇数番目の要素において、iの数が何個あったか
odd = [0 for i in range(100001)]

# 偶数番目、奇数番目の要素、それぞれ数える
for i in range(0, n-1, 2):
    even[v[i]] += 1
    odd[v[i+1]] += 1

# 偶数番目の要素のうち最も多かった数値
maxeveni = -1
# 偶数番目の要素のうち最も多かった数値の個数
maxeven = 0
# 偶数番目の要素のうち2番目に多かった数値の個数
preeven = 0

# 奇数番目の要素のうち最も多かった数値
maxoddi = -1
# 奇数番目の要素のうち最も多かった数値の個数
maxodd = 0
# 奇数番目の要素のうち2番目に多かった数値の個数
preodd = 0

# 偶数番目の要素を走査
for i in range(1, 100001):
    num = even[i]
    if maxeven <= num:
        maxeveni = i
        preeven = maxeven
        maxeven = num
    elif preeven <= num:
        preeven = num

# 奇数番目の要素を走査
for i in range(1, 100001):
    num = odd[i]
    if maxodd <= num:
        maxoddi = i
        preodd = maxodd
        maxodd = num
    elif preodd <= num:
        preodd = num

ans = 0

# 要素のうち最も多かった数値が偶数番目と奇数番目で一致していなかった場合
if maxeveni != maxoddi:
    ans = n - maxeven - maxodd
# 要素のうち最も多かった数値が偶数番目と奇数番目で一致していた場合
else:
    ans = min(n - preeven - maxodd, n - maxeven - preodd)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
num_list = list(map(int,input().split()))

even_cnt = [0]*(10**5 + 10)
odd_cnt = [0]*(10**5 +10)
for i in range(n):
    if i % 2 == 0:
        even_cnt[num_list[i]] += 1
    else:
        odd_cnt[num_list[i]] += 1
ame = np.argmax(even_cnt)
amo = np.argmax(odd_cnt)
if ame != amo:
    print(len(num_list) - max(even_cnt) -  max(odd_cnt))
    
    
else:
    tmp_e_max =  max(even_cnt)
    tmp_o_max = max(odd_cnt)
    even_cnt[ame] = 0
    odd_cnt[amo] = 0
    if tmp_e_max-max(even_cnt) >=  tmp_o_max - max(odd_cnt):
        print(len(num_list) - max(odd_cnt) -  tmp_e_max)
    else:
        print(len(num_list) - max(even_cnt) -  tmp_o_max)

Submission status: Accepted

Solution code:
n=int(input())
v=list(map(int,input().split()))
ans1=[0]*(10**5+1)#偶数
ans2=[0]*(10**5+1)#奇数
for i in v[0::2]:
  ans1[i]+=1
for i in v[1::2]:
  ans2[i]+=1
m1=max(ans1)
m2=max(ans2)
flag=False
for i in range(10**5+1):
  if ans1[i]==m1 and ans2[i]==m2:
    flag=True
    ans1.sort()
    ans2.sort()
    m12=ans1[-2]
    m22=ans2[-2]
    break
if len(set(v))==1:
  print(n//2)
elif flag==True:
  print(n-max(m12+m2,m1+m22))
else:
  print(n-m1-m2)

Submission status: Accepted

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

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

odd = defaultdict(int)
even = defaultdict(int)

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

evenMax = 0
oddMax = 0
ev = 0
evenList = []
oddList = []
for k, v in even.items():
    evenList.append((v, k))
for k, v in odd.items():
    oddList.append((v, k))

evenList.sort(reverse=True)
oddList.sort(reverse=True)

ans = 0

if evenList[0][1] == oddList[0][1]:
    ans = min(N - evenList[0][0] - oddList[1][0],
              N - evenList[1][0] - oddList[0][0])
else:
    ans = N - evenList[0][0] - oddList[0][0]

print(ans)

Submission status: Accepted

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

def mkdc(l):
    di=dict()
    for i in range(len(l)):
        if l[i] in di:
            di[l[i]]+=1
        else:
            di[l[i]]=1
    return di

e,o=[],[]      
for i in range(int(n/2)):
    e.append(v[2*i])
    o.append(v[2*i+1])
#print(e)
de=mkdc(e)
do=mkdc(o)
#print(de)
de=sorted(de.items(),key=lambda d: d[1],reverse=True)
do=sorted(do.items(),key=lambda d: d[1],reverse=True)
de.append((0,0))
do.append((0,0))
#de=sorted(de)
#print(de)
if do[0][0]==de[0][0]:
    print(n- do[0][1]-max(de[1][1],do[1][1]))
else:
    print(n-de[0][1]-do[0][1])

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import itertools
import math
import fractions
import functools
l = [0]*(10**5+1)
r = [0]*(10**5+1)
 
n = int(input())
v = list(map(int, input().split()))
 
for i in range(n):
    if i % 2 == 0:
        l[v[i]] += 1
    else:
        r[v[i]] += 1
 
max_l = l.index(max(l))
max_r = r.index(max(r))
count = 0
 
if max_l == max_r:
    for i in range(len(r)):
        if r[i] == r[max_r]:
            r[i] = 0
        if l[i] == l[max_l]:
            l[i] = 0
if max(l) > max(r):
    max_l = l.index(max(l))
else:
    max_r = r.index(max(r))
 
for i in range(n):
    if i % 2 == 0 and v[i] != max_l:
        count += 1
    if i % 2 != 0 and v[i] != max_r:
        count += 1
print(count)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

n, *v = map(int, read().split())
g = Counter(v[::2]).most_common()
k = Counter(v[1::2]).most_common()
if g[0][0] == k[0][0]:
    if len(g) > 1:
        if len(k) > 1:
            print(n - max(g[0][1] + k[1][1], g[1][1] + k[0][1]))
        else:
            print(n - g[1][1] - k[0][1])
    elif len(k) > 1:
        print(n - g[0][1] - k[1][1])
    else:
        print(n // 2)
else:
    print(n - g[0][1] - k[0][1])

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
V = [int(i) for i in input().split()]
Ki = []
Gu = []
switch = True
for i in range(N):
    if switch:
        Ki.append(V[i])
    else:
        Gu.append(V[i])
    switch = not switch

K = sorted(Counter(Ki).items(),key=lambda x:x[1],reverse=True)
G = sorted(Counter(Gu).items(),key=lambda x:x[1],reverse=True)
sk = len(K)
gk = len(G)
if sk==1 and gk==1:
    if G[0][0]==K[0][0]:
        print(N//2)
    else:
        print(0)
elif sk==1:
    if G[0][0]==K[0][0]:
        print(N-K[0][1]-G[1][1])
    else:
        print(N-K[0][1]-G[0][1])
elif gk == 1:
    if G[0][0]==K[0][0]:
        print(N-K[1][1]-G[0][1])
    else:
        print(N-K[0][1]-G[0][1])
else:
    if G[0][0] == K[0][0]:
        s1 = K[0][1]+G[1][1]
        s2 = K[1][1]+G[0][1]
        print(N-max(s1,s2))
    else:
        print(N-K[0][1]-G[0][1])

Submission status: Accepted

Solution code:
from collections import defaultdict

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

o=defaultdict(int)						#初期化を忘れずに
e=defaultdict(int)

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

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

es=sorted(e.items(),key=lambda x:x[1],reverse=True)							#辞書のソート
os=sorted(o.items(),key=lambda x:x[1],reverse=True)

if es[0][0]==os[0][0]:
	if len(es)==1 and len(os)==1:
		print(n-max(es[0][1],os[0][1]))
	elif len(es)==1:
		print(n-es[0][1]-os[1][1])
	elif len(os)==1:
		print(n-es[1][1]-os[0][1])
	else:
		print(n-max(es[0][1]+os[1][1],es[1][1]+os[0][1]))
else:
	print(n-es[0][1]-os[0][1])