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

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

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

if e[0][0] != o[0][0]:
    print(n - e[0][1] - o[0][1])
else:
    if len(e) == 1 and len(o) == 1:
        print(n // 2)
    elif len(e) == 1 and len(o) >= 2:
        print(n - o[0][1])
    elif len(e) >= 2 and len(o) == 1:
        print(n - e[0][1])
    else:
        print(n - max(e[1][1] + o[0][1], e[0][1] + o[1][1]))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
odd = []
even = []

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

o_count = Counter(odd)
e_count = Counter(even)
o_count[-1] = 0
e_count[-2] = 0

if o_count.most_common(1)[0] != e_count.most_common(1)[0]:
  print(n - o_count.most_common(1)[0][1] - e_count.most_common(1)[0][1])
else:
  o1e2 = n - o_count.most_common(2)[0][1] - e_count.most_common(2)[1][1]
  o2e1 = n - o_count.most_common(2)[1][1] - e_count.most_common(2)[0][1]
  ans = min(o1e2,o2e1)
  print(ans)

Submission status: Accepted

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


def solve(n: int, V: "List[int]"):

    ev = V[0::2]
    ov = V[1::2]

    ec = collections.Counter(ev)
    oc = collections.Counter(ov)

    em = ec.most_common()
    om = oc.most_common()

    if em[0][0] != om[0][0]:
        print( n-em[0][1]-om[0][1])
    else:
        if len(em) == 1 and len(om) == 1:
            print(n-em[0][1])
        elif  len(em) == 1:
            print( n-em[0][1]-om[1][1])
        elif  len(om) == 1:
            print( n-em[1][1]-om[0][1])
        else:
            print(min(n-em[0][1]-om[1][1], n-em[1][1]-om[0][1]))

            



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections

n = int(input())
v = [int(i) for i in input().split()]

odd = []
even = []
for i, num in enumerate(v):
    if (i+1) % 2 != 0:
        odd.append(num)
    else:
        even.append(num)

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

cnt_odd = 0
cnt_even = 0

ans = 0
if odds[0][0]  == evens[0][0]:
    if len(evens) == 1 and len(odds) == 1:
        ans = evens[0][1]
        print(ans)
        exit()

    ans1 = 10 ** 5
    ans2 = 10 ** 5

    if len(evens) > 1:
        for i, e in enumerate(evens):
            if i != 1:
                cnt_even += e[1]
        for i, o in enumerate(odds):
            if i > 0:
                cnt_odd += o[1]
        ans1 = cnt_even + cnt_odd
        cnt_even, cnt_odd = 0,0
    if len(odds) > 1:
        for i, e in enumerate(evens):
            if i > 0:
                cnt_even += e[1]
        for i, o in enumerate(odds):
            if i != 1:
                cnt_odd += o[1]
        ans2 = cnt_even + cnt_odd
    ans = min(ans1, ans2)
    print(ans)
    exit()

for i, o in enumerate(odds):
    if i > 0:
        cnt_odd += o[1]
for i, e in enumerate(evens):
    if i > 0:
        cnt_even += e[1]
ans = cnt_odd + cnt_even

print(ans)

Submission status: Accepted

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

odd = {}
even = {}

for i in range(len(v)):
    if i % 2 == 1:
        if v[i] in odd:
            odd[v[i]] += 1
        else:
            odd[v[i]] = 1
    else:
        if v[i] in even:
            even[v[i]] += 1
        else:
            even[v[i]] = 1

#ソートして一番目、二番目を見る
odd_sorted  = sorted(odd.items(), key = lambda x : -x[1])
even_sorted  = sorted(even.items(), key = lambda x : -x[1])




#候補が同じ場合
if odd_sorted[0][0] == even_sorted[0][0]:
    #奇数も偶数も2番目が存在する？
    if len(odd.keys()) > 1 and len(even.keys()) > 1:
        #数が大きい方を採用
        if odd_sorted[0][1] > even_sorted[0][1]:
            ans_odd = odd_sorted[0][0]
            ans_even = even_sorted[1][0]
        elif odd_sorted[0][1] < even_sorted[0][1]:
            ans_odd = odd_sorted[1][0]
            ans_even = even_sorted[0][0]
        else:
            #両者が一致した場合
            if odd_sorted[1][1] >= even_sorted[1][1]:
                ans_odd = odd_sorted[1][0]
                ans_even = even_sorted[0][0]
            elif odd_sorted[1][1] < even_sorted[1][1]:
                ans_odd = odd_sorted[0][0]
                ans_even = even_sorted[1][0]

    #お互いに二番目が存在しない(ただし数は必ず一致するのでどちらか)
    elif len(odd.keys()) == 1 and len(even.keys()) == 1:
        ans_odd = -1
        ans_even = even_sorted[0][0]
    #奇数に2番目が存在しない
    elif len(odd.keys()):
        ans_odd = odd_sorted[0][0]
        ans_even = even_sorted[1][0]
    #偶数に2番目が存在しない
    else: #len(even.keys()):
        ans_odd = odd_sorted[1][0]
        ans_even = even_sorted[0][0]

else:
    ans_odd = odd_sorted[0][0]
    ans_even = even_sorted[0][0]

ans = 0
for i in range(len(v)):
    if i % 2:
        if v[i] != ans_odd:
            ans += 1
    else:
        if v[i] != ans_even:
            ans += 1


print(ans)

Submission status: Accepted

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

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

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

odd_map[-1] = 0
even_map[-2] = 0
odd_list = list(odd_map.items())
odd_list.sort(key=lambda x: x[1], reverse=True)
even_list = list(even_map.items())
even_list.sort(key=lambda x: x[1], reverse=True)

odds = [odd_list[i][0] for i in range(2)]
evens = [even_list[i][0] for i in range(2)]

ans_list = []
for odd in odds:
    for even in evens:
        if odd == even:
            continue
        ans = 0
        for k, v in odd_map.items():
            if k != odd:
                ans += v
        for k, v in even_map.items():
            if k != even:
                ans += v
        ans_list.append(ans)

print(min(ans_list))

Submission status: Accepted

Solution code:
import collections

c = collections.Counter

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

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

c1 = c(even_v).most_common(2)
c2 = c(odd_v).most_common(2)
# print(c1)
# print(c2)

def calc(x, y):
    # print('x:', x, 'y:', y)
    # print('x[1]:', x[1], 'y[1]:', y[1])
    return len(even_v) - x[1] + len(odd_v) - y[1]

def main():
    if c1[0] != c2[0]:
        # print('c1[0] != c2[0]:')
        return calc(c1[0], c2[0])

    if len(c1) == 1 and len(c2) == 1:
        # print('len(c1) == 1 and len(c2) == 1:')
        return len(odd_v)

    if calc(c1[0], c2[1]) < calc(c1[1], c2[0]):
        # print('calc(c1[0], c2[1]) < calc(c1[1], c2[0]):')
        return calc(c1[0], c2[1])

    else:
        # print('else')
        return calc(c1[1], c2[0])

print(main())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - /\/\/\/
https://atcoder.jp/contests/abc111/tasks/arc103_a

"""
import sys


from collections import Counter

def solve(n, nums):
    e_cnt = Counter(nums[::2])
    o_cnt = Counter(nums[1::2])
    e = e_cnt.most_common()
    o = o_cnt.most_common()

    ans1 = len(nums)
    ans2 = len(nums)
    if e[0][0] == o[0][0]:
        ee = e[0][1]
        oo = o[1][1] if len(o) > 1 else 0
        ans1 -= (ee + oo)
        ee = e[1][1] if len(e) > 1 else 0
        oo = o[0][1]
        ans2 -= (ee + oo)
        return min(ans1, ans2)
    else:
        return len(nums) - (e[0][1] + o[0][1])

def main(args):
    n = int(input())
    nums = [int(i) for i in input().split()]
    ans = solve(n, nums)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
import collections
c = collections.Counter

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

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

c1 = c(v_odd).most_common(2)
c2 = c(v_eve).most_common(2)

if len(c1) == 1 and len(c2) == 1:
    if c1[0][0] != c2[0][0]:
        ans = 0
    else:
        ans = int(N/2)
else:
    if c1[0] != c2[0]:
        ans = N - c1[0][1] - c2[0][1]
    else:
        if c1[1][1] >= c2[1][1]:
            ans = N - c1[1][1] - c2[0][1]
        else:
            ans = N - c1[0][1] - c2[1][1]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
count_dict = {i:{} for i in range(2)}
#print(count_dict[0])
for i in range(2):
  for j in A[i::2]:
    if j not in count_dict[i]:
      count_dict[i][j] = 1
    else:
      count_dict[i][j] += 1

candidates = [sorted(count_dict[i].items(), key=lambda kv: kv[1], reverse=True)[:2] for i in range(2)]
candidates = [i[1]+j[1] for i in candidates[0] for j in candidates[1] if i[0] != j[0]]
no_move = max(candidates) if candidates != [] else len(A) // 2
print(N-no_move)

Submission status: Accepted

Solution code:
# 2019/05/15
# AtCoder Beginner Contest 111 - C

from operator import itemgetter

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

l_even = list()
l_odd = list()

# Separate Odd or Even
for i in range(n):
    if i % 2 == 0:
        l_even.append(v[i])
    else:
        l_odd.append(v[i])

l_even.sort()
l_odd.sort()
wk_cnt_e = 1
wk_cnt_o = 1

cnt_even = list()
cnt_odd = list()

# Count
for x in range(int(n/2)-1):
    if l_even[x] != l_even[x+1]:
        cnt_even.append([l_even[x], wk_cnt_e])
        wk_cnt_e = 1
    else:
        wk_cnt_e += 1

    if l_odd[x] != l_odd[x+1]:
        cnt_odd.append([l_odd[x], wk_cnt_o])
        wk_cnt_o = 1
    else:
        wk_cnt_o += 1

cnt_even.append([l_even[x+1], wk_cnt_e])
cnt_odd.append([l_odd[x+1], wk_cnt_o])

cnt_even.sort(key=itemgetter(1),reverse=True)
cnt_odd.sort(key=itemgetter(1),reverse=True)

# Max is same
if cnt_even[0][0] == cnt_odd[0][0]:
    if len(cnt_even) == 1 and len(cnt_odd) == 1:
        ans = n / 2
    elif len(cnt_even) == 1:
        ans = n / 2 - cnt_odd[1][1]
    elif len(cnt_odd) == 1:
        ans = n / 2 - cnt_even[1][1]
    else:
        ans = min((n / 2 - cnt_even[0][1]) + (n / 2 - cnt_odd[1][1]),
                (n / 2 - cnt_even[1][1]) + (n / 2 - cnt_odd[0][1]))
# Max is Not same
else:
    if len(cnt_even) == 1 and len(cnt_odd) == 1:
        ans = 0
    elif len(cnt_even) == 1:
        ans = n / 2 - cnt_odd[0][1]
    elif len(cnt_odd) == 1:
        ans = n / 2 - cnt_even[0][1]
    else:
        ans = (n / 2 - cnt_even[0][1]) + (n / 2 - cnt_odd[0][1])

# Output
print(int(ans))

Submission status: Accepted

Solution code:
import collections

c = collections.Counter

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

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

c1 = c(even_v).most_common(2)
c2 = c(odd_v).most_common(2)


def calc(x, y):
    return len(even_v) - x[1] + len(odd_v) - y[1]


def main():
    if c1[0] != c2[0]:
        return calc(c1[0], c2[0])

    if len(c1) == 1 and len(c2) == 1:
        return len(odd_v)

    if calc(c1[0], c2[1]) < calc(c1[1], c2[0]):
        return calc(c1[0], c2[1])
    else:
        return calc(c1[1], c2[0])


print(main())

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
V = input().split()
a = V[::2]
b = V[1::2]
h = int(N / 2)
ac = Counter(a)
bc = Counter(b)
ma = ac.most_common()
mb = bc.most_common()
if ma[0][0] == mb[0][0]:
  if len(ma) == len(mb) == 1:
    ans = h
  elif len(ma) == 1:
    ans = h - mb[1][1]
  elif len(mb) == 1:
    ans = h - ma[1][1]
  else:
    ans = min(2 * h - ma[0][1] - mb[1][1], 2 * h - mb[0][1] - ma[1][1])
else:
  ans = 2 * h - ma[0][1] - mb[0][1]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
V = input().split(' ')
V_even = V[1::2]
V_odd = V[0::2]
#偶数列の要素を数え上げ
V_even_Count = Counter(V_even)
#奇数列の数え上げ
V_odd_Count = Counter(V_odd)

#偶数列の格納
X = []
for x in V_even_Count.most_common(2):
  X.append(x)
if len(X) == 1:
  X.append(('i',0))
#奇数列の格納
Y = []
for y in V_odd_Count.most_common(2):
  Y.append(y)
if len(Y) == 1:
  Y.append(('j',0))

A,B,C,D = X[0],X[1],Y[0],Y[1]
if A[0] != C[0]:
  print(N-A[1]-C[1])
else:
  if B[1] <= D[1]:
    print(N-A[1]-D[1])
  else:
    print(N-B[1]-C[1])

Submission status: Accepted

Solution code:
from collections import Counter

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

odd_most_common = Counter(v[:: 2]).most_common()[0]
even_most_common = Counter(v[1:: 2]).most_common()[0]

odd_most_cnt = odd_most_common[1]
even_most_cnt = even_most_common[1]

if odd_most_common[0] != even_most_common[0]:
	print(n - odd_most_cnt - even_most_cnt)
else:
	A = odd_most_cnt
	B = even_most_cnt
	if len(set(v[:: 2])) > 1:
		A = Counter(v[:: 2]).most_common()[1][1] + even_most_cnt
	if len(set(v[1:: 2])) > 1:
		B = odd_most_cnt + Counter(v[1:: 2]).most_common()[1][1]
	print(min(n - A, n - B))

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
cnt1=[0]*(10**5+1)
cnt2=[0]*(10**5+1)
for i in range(n):
  if i%2==0:
    cnt1[arr[i]]+=1
  else:
    cnt2[arr[i]]+=1
m1=max(cnt1)
m2=max(cnt2)
p1=cnt1.index(m1)
p2=cnt2.index(m2)
cnt1=sorted(cnt1,reverse=True)
cnt2=sorted(cnt2,reverse=True)
if n==2:
  if arr[0]!=arr[1]:
    print(0)
  else:
    print(1)
else:
  if p1==p2:
    ans=min(n-m1-cnt2[1],n-cnt1[1]-m2)
  else:
    ans=n-m1-m2
  print(ans)

Submission status: Accepted

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

V1 = V[::2]
V2 = V[1::2]
 
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]

ans = 0
if k1 == k2:
    ans = n - v1
    m = 0
    if len(V1c) >= 2:
        m = max(m, V1c[1][1])
    if len(V2c) >= 2:
        m = max(m, V2c[1][1])
    ans = ans - m
else:
    ans = n - v1 - v2
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
even = np.zeros(100001, dtype=int)
odd = np.zeros(100001, dtype=int)

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

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

e1 = even.argmax()
e1n = even.max()
o1 = odd.argmax()
o1n = odd.max()

# print(e1, e1n, o1, o1n)
if e1 == o1:
    e2n = np.sort(even)[-2]
    o2n = np.sort(odd)[-2]
    # print(e2n, o2n)
    print(min(n - e1n - o2n, n - e2n - o1n))
else:
    print(n - e1n - o1n)

Submission status: Accepted

Solution code:
import numpy as np
even = np.zeros(100001, dtype='i')
odd = np.zeros(100001, dtype='i')

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

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

e1 = even.argmax()
e1n = even.max()
o1 = odd.argmax()
o1n = odd.max()

# print(e1, e1n, o1, o1n)
if e1 == o1:
    e2n = np.sort(even)[-2]
    o2n = np.sort(odd)[-2]
    # print(e2n, o2n)
    print(min(n - e1n - o2n, n - e2n - o1n))
else:
    print(n - e1n - o1n)

Submission status: Accepted

Solution code:
import numpy as np
even = np.zeros(100001, dtype=np.int32)
odd = np.zeros(100001, dtype=np.int32)

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

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

e1 = even.argmax()
e1n = even.max()
o1 = odd.argmax()
o1n = odd.max()

# print(e1, e1n, o1, o1n)
if e1 == o1:
    e2n = np.sort(even)[-2]
    o2n = np.sort(odd)[-2]
    # print(e2n, o2n)
    print(min(n - e1n - o2n, n - e2n - o1n))
else:
    print(n - e1n - o1n)

Submission status: Accepted

Solution code:
import numpy as np
even = np.zeros(100001, dtype=np.int64)
odd = np.zeros(100001, dtype=np.int64)

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

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

e1 = even.argmax()
e1n = even.max()
o1 = odd.argmax()
o1n = odd.max()

# print(e1, e1n, o1, o1n)
if e1 == o1:
    e2n = np.sort(even)[-2]
    o2n = np.sort(odd)[-2]
    # print(e2n, o2n)
    print(min(n - e1n - o2n, n - e2n - o1n))
else:
    print(n - e1n - o1n)

Submission status: Accepted

Solution code:
# def makelist(n, m):
#     return [[0 for i in range(m)] for j in range(n)]

n = int(input())
v = [0] + list(map(int, input().split()))

odd = {}
even = {}
for i in range(1, n+1):
    if i % 2 == 0:
        if v[i] not in even:
            even[v[i]] = 1
        else:
            even[v[i]] += 1
    else:
        if v[i] not in odd:
            odd[v[i]] = 1
        else:
            odd[v[i]] += 1

even = list(reversed(sorted(map(lambda x: (x[1], x[0]), list(even.items())))))
odd = list(reversed(sorted(map(lambda x: (x[1], x[0]), list(odd.items())))))

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

print(ans)

Submission status: Accepted

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
odd, even = [], []

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

    
codd = collections.Counter(odd)
ceven = collections.Counter(even)
mostodd = codd.most_common()[0]
mosteven = ceven.most_common()[0]

if mostodd[0] != mosteven[0]:
  ans = n - mostodd[1] - mosteven[1]
else:
  if len(ceven.most_common()) > 1:
    even2nd = ceven.most_common()[1][1]
  else:
    even2nd = 0
  ans1 = n - mostodd[1] - even2nd
  if len(codd.most_common()) > 1:
    odd2nd = codd.most_common()[1][1]
  else:
    odd2nd = 0
  ans2 = n - odd2nd - mosteven[1] 
  ans = min(ans1, ans2)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


def m():
    N = int(input())
    V = [int(i) for i in input().split()]
    vodds = V[0::2]
    vevens = V[1::2]

    odds_commons = Counter(vodds).most_common()
    even_commons = Counter(vevens).most_common()

    odds_top = odds_commons[0]
    evens_top = even_commons[0]
    if odds_top[0] != evens_top[0]:
        return N - odds_top[1] - evens_top[1]
    else:
        if len(odds_commons) > 1 and len(even_commons) > 1:
            return min(
                N - odds_commons[1][1] - even_commons[0][1],
                N - even_commons[1][1] - odds_commons[0][1]
            )
        elif len(odds_commons) > 1:
            return N - odds_commons[1][1] - even_commons[0][1]
        elif len(even_commons) > 1:
            return N - even_commons[1][1] - odds_commons[0][1]
        else:
            return N // 2


print(m())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri May 10 23:15:55 2019

@author: Yamazaki Kenichi
"""

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

T = [[0 for i in range(10**5+1)], [0 for i in range(10**5+1)]]
counta = 0
for c in A:
    T[counta%2][c] += 1
    counta += 1

tmp = [[0]*4, [0]*4]
for i in range(10**5+1):
#for i in range(6):
    for k in range(2):
        if T[k][i] > tmp[k][0]:
            tmp[k][2], tmp[k][3] = tmp[k][0], tmp[k][1]
            tmp[k][0], tmp[k][1] = T[k][i], i
        elif T[k][i] > tmp[k][2]:
            tmp[k][2], tmp[k][3] = T[k][i], i
#        print(tmp)
if tmp[0][1] != tmp[1][1]:
    print(n-tmp[0][0]-tmp[1][0])
else:
    print(min(n-tmp[0][0]-tmp[1][2], n-tmp[0][2]-tmp[1][0]))

Submission status: Accepted

Solution code:
import collections
n=int(input())
v=[int(i) for i in input().split()]
A=[]
B=[]
for i in range(n//2):
    A.append(v[2*i])
    B.append(v[2*i+1])
    
a=collections.Counter(A)
b=collections.Counter(B)
aa=a.most_common()
bb=b.most_common()


if len(a)==len(b)==1 and aa[0][0]!=bb[0][0]:
    print(0)
elif len(a)==len(b)==1 and aa[0][0]==bb[0][0]:
    print(n//2)
else:
    if aa[0][0]!=bb[0][0]:
        count=n-aa[0][1]-bb[0][1]
        print(count)
    else:
        print(min(
            n-aa[0][1]-bb[1][1],
            n-aa[1][1]-bb[0][1]
        ))

Submission status: Accepted

Solution code:
import heapq

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

evens = [(0, 0)]*(10**5+1)
odds = [(0, 0)]*(10**5+1)
for i in range(N):
    if (i+1) % 2 == 0:
        evens[V[i]] = (V[i], evens[V[i]][1] + 1)
    else:
        odds[V[i]] = (V[i], odds[V[i]][1] + 1)

evens_top_two = heapq.nlargest(2, evens, key=lambda x: x[1])
odds_top_two = heapq.nlargest(2, odds, key=lambda x: x[1])

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

Submission status: Accepted

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

evens = [(0, 0)]*(10**5+1)
odds = [(0, 0)]*(10**5+1)
for i in range(N):
    if (i+1) % 2 == 0:
        evens[V[i]] = (V[i], evens[V[i]][1] + 1)
    else:
        odds[V[i]] = (V[i], odds[V[i]][1] + 1)

evens.sort(key=lambda x: x[1], reverse=True)
odds.sort(key=lambda x: x[1], reverse=True)

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

vsd1 = defaultdict(int)
for i in range(0, n, 2):
    vsd1[vs[i]] += 1

vsd2 = defaultdict(int)
for i in range(1, n, 2):
    vsd2[vs[i]] += 1

vsc1 = []
for k, v in vsd1.items():
    vsc1.append((k, v))

vsc2 = []
for k, v in vsd2.items():
    vsc2.append((k, v))

vsc1.append((-1, 0))
vsc2.append((-1, 0))
vsc1 = sorted(vsc1, key=lambda x: x[1], reverse=True)
vsc2 = sorted(vsc2, key=lambda x: x[1], reverse=True)

if vsc1[0][0] != vsc2[0][0]:
    print(n - (vsc1[0][1] + vsc2[0][1]))
else:
    print(n - max(vsc1[0][1] + vsc2[1][1], vsc1[1][1] + vsc2[0][1]))

Submission status: Accepted

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

dic1, dic2 = dict(), dict()
#dic1[0] = 0
#dic2[0] = 0
for i, x in enumerate(lst):
    dic = dic1 if  i%2 == 0 else dic2
    if x not in dic.keys():
        dic[x] = 1
    else:
        dic[x] += 1
#print (type(dic1))
dic1 =sorted(dic1.items(), key = lambda x:x[1])[::-1]
dic2 =sorted(dic2.items(), key = lambda x:x[1])[::-1]

#print (type(dic2))
#print (dic1)
#print (dic2)

if dic1[0][0] != dic2[0][0]:
    print (N-dic1[0][1]-dic2[0][1])
elif len(dic1) == 1 and len(dic2) == 1:
    print (N//2)
elif len(dic1) == 1:
    print (N-dic1[0][1]-dic2[1][1])
elif len(dic2) == 1:
    print (N-dic1[1][1]-dic2[0][1])
else:
    print (min(N-dic1[0][1]-dic2[1][1], N-dic1[1][1]-dic2[0][1]))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
dic1,dic2=dict(),dict()
for i,x in enumerate(a):
    dic = dic1 if i%2==0 else dic2
    if x not in dic.keys():
        dic[x]=1
    else:
        dic[x]+=1
dic1=sorted(dic1.items(),key=lambda x:x[1])[::-1]
dic2=sorted(dic2.items(),key=lambda x:x[1])[::-1]

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v_odd = v[::2]
v_even = v[1::2]
c_odd = Counter(v_odd)
c_even = Counter(v_even)
ans = len(v)
for c_o, c_e in zip(c_odd.most_common(), c_even.most_common()):
    if c_o == c_e:
        continue
    else:
        ans -= max(c_o[1], c_e[1])
        ans -= min(c_odd.most_common()[0][1], c_even.most_common()[0][1])
        break
else:
    ans -= c_odd.most_common()[0][1]
    if len(c_even.most_common()[1:]) > 0:
        ans -= c_even.most_common()[1][1]

print(ans)

Submission status: Accepted

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

cnts = [collections.Counter(v[::2]), collections.Counter(v[1::2])]

hs = [[], []]
for i in range(2):
    for k, c in cnts[i].items():
        heapq.heappush(hs[i], (-c, k))
h0 = heapq.heappop(hs[0])
h1 = heapq.heappop(hs[1])
if h0[1] == h1[1]:
    if not hs[0] and not hs[1]:
        print(n//2)
    elif not hs[0]:
        print(n+h1[0])
    elif not hs[1]:
        print(n+h0[0])
    else:
        n0 = heapq.heappop(hs[0])
        n1 = heapq.heappop(hs[1])
        print(n + min(h0[0]+n1[0], n0[0]+h1[0]))
else:
    print(n+(h0[0]+h1[0]))

Submission status: Accepted

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
a = v[0::2]
b = v[1::2]
a = collections.Counter(a)
a = a.most_common()
b = collections.Counter(b)
b = b.most_common()
c = n//2
if a[0][0] != b[0][0]:
    ans = c-a[0][1] + c-b[0][1]
    print(ans)
else: 
    if len(a) == 1:
        tmpa = 0
    else:
        tmpa = a[1][1]
    if len(b) == 1:
        tmpb = 0
    else:
        tmpb = b[1][1]
    ans1 = c-tmpa + c-b[0][1]
    ans2 = c-a[0][1] + c-tmpb
    print(min(ans1,ans2))

Submission status: Accepted

Solution code:
import numpy as np
from collections import Counter

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

c_odd = Counter(vlist[0::2])
c_even = Counter(vlist[1::2])

odd = c_odd.most_common()
even = c_even.most_common()

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

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
even, odd = v[::2], v[1::2]

set_e, set_o = set(even), set(odd)
E, O = Counter(even), Counter(odd)
ce, co = E.most_common(), O.most_common()
e1, o1 = ce[0][0], co[0][0]

if e1 != o1:
    a, b = ce[0][1], co[0][1]
    print(n-a-b)
    exit()
if len(set_o) == 1 and len(set_e) == 1:
    print(len(even))
    exit()
if len(set_o) == 1:
    a = ce[1][1]
    print(len(even)-a)
    exit()
if len(set_e) == 1:
    a = co[1][1]
    print(len(odd)-a)
    exit()

e2, o2 = ce[1][0], co[1][0]
ce1, co1 = ce[0][1], co[0][1]
ce2, co2 = ce[1][1], co[1][1]

print(min(n-ce1-co2, n-ce2-co1))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
v_odd = v[0::2]
v_even = v[1::2]
ans = 0
c_odd = Counter(v_odd)
c_even = Counter(v_even)
v_o, c_o = zip(*c_odd.most_common())
v_e, c_e = zip(*c_even.most_common())
if len(c_o) == 1:
    odd1 = 0
else:
    odd1 = c_o[1]
if len(c_e) == 1:
    even1 = 0
else:
    even1 = c_e[1]
if not v_o[0] == v_e[0]:
    print(sum(c_o) - c_o[0] + sum(c_e) - c_e[0])
else:
    ans = min(sum(c_o) - c_o[0] + sum(c_e) - even1, sum(c_o) - odd1 + sum(c_e) - c_e[0])
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
V = list(map(int, input().split()))
E = {}
O = {}
now = 1
for i, v in enumerate(V):
    if now:
        if v in E.keys():
            E[v] += 1
        else:
            E[v] = 1
    else:
        if v in O.keys():
            O[v] += 1
        else:
            O[v] = 1
    now = 1 - now
E = sorted(E.items(), key=lambda x: -x[1])
O = sorted(O.items(), key=lambda x: -x[1])
if E[0][0] != O[0][0]:
    print(n - E[0][1] - O[0][1])
else:
    if len(E) == 1 and len(O) == 1:
        print(E[0][1])
    elif len(E) == 1:
        print(n-E[0][1]-O[1][1])
    elif len(O) == 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]))

Submission status: Accepted

Solution code:
n = int(input())
V = list(map(int, input().split()))
E = {}
O = {}
n = 1
for i, v in enumerate(V):
    if n:
        if v in E.keys():
            E[v] += 1
        else:
            E[v] = 1
    else:
        if v in O.keys():
            O[v] += 1
        else:
            O[v] = 1
    n = 1 - n
E = sorted(E.items(), key=lambda x: -x[1])
O = sorted(O.items(), key=lambda x: -x[1])
if E[0][0] != O[0][0]:
    ans = sum([x[1] for x in E])-E[0][1]
    ans += sum([x[1] for x in O])-O[0][1]
    print(ans)
else:
    if len(E) == 1 and len(O) == 1:
        print(E[0][1])
    elif len(E) == 1:
        ans = sum([x[1] for x in E])-E[0][1]
        ans += sum([x[1] for x in O])-O[1][1]
        print(ans)
    elif len(O) == 1:
        ans = sum([x[1] for x in E])-E[1][1]
        ans += sum([x[1] for x in O])-O[0][1]
        print(ans)
    else:
        ans1 = sum([x[1] for x in E])-E[0][1]
        ans1 += sum([x[1] for x in O])-O[1][1]
        ans2 = sum([x[1] for x in E])-E[1][1]
        ans2 += sum([x[1] for x in O])-O[0][1]
        print(min(ans1, ans2))