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

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

d0 = dict()
for x in v0:
    d0[x] = d0.get(x, 0) + 1

d1 = dict()
for x in v1:
    d1[x] = d1.get(x, 0) + 1

L0 = [(k, v) for k, v in d0.items()]
L0 = sorted(L0, key=lambda x: x[1], reverse=True)

L1 = [(k, v) for k, v in d1.items()]
L1 = sorted(L1, key=lambda x: x[1], reverse=True)

half_n = n // 2
ans = -1
if L0[0][0] != L1[0][0]:
    ans = (half_n - L0[0][1]) + (half_n - L1[0][1])
else:
    if len(L0) > 1 and len(L1) > 1:
        if L0[1][1] >= L1[1][1]:
            ans = (half_n - L0[1][1]) + (half_n - L1[0][1])
        else:
            ans = (half_n - L0[0][1]) + (half_n - L1[1][1])
    else:
        if len(L0) == 1 and len(L1) > 1:
            ans = (half_n - L1[1][1])
        elif len(L0) > 1 and len(L1) == 1:
            ans = (half_n - L1[0][1])
        else:
            ans = (half_n)
print(ans)

Submission status: Accepted

Solution code:
# encoding: utf-8
n = int(input())
v = list(map(int, input().split()))

odd = [0] * (10 ** 5)
even = [0] * (10 ** 5)
for i, vi in enumerate(v):
    if i % 2: even[vi - 1] += 1
    else: odd[vi - 1] += 1

max_o = max_e = 0
imax_o = imax_e = 0
sub_o = sub_e = 0
for i, (valo, vale) in enumerate(zip(odd, even)):
    # odd
    if valo > max_o:
        sub_o = max_o
        max_o = valo
        imax_o = i + 1
    elif valo > sub_o: sub_o = valo
    # even
    if vale > max_e:
        max_e = vale
        imax_e = i + 1
    elif vale > sub_e: sub_e = vale

if imax_o == imax_e: print(min(n - max_o - sub_e, n - sub_o - max_e))
else: print(n - max_o - max_e)

Submission status: Accepted

Solution code:
n=int(input())
even={}
odd={}
for i,x in enumerate(list(map(int,input().split()))):
    if i%2==0:
        if even.get(x,0)==0:
            even[x]=1
        else:
            even[x]+=1
    else:
        if odd.get(x,0)==0:
            odd[x]=1
        else:
            odd[x]+=1

even=sorted(even.items(),key=lambda x:x[1])
odd=sorted(odd.items(),key=lambda x:x[1])
ans=0
if even[-1][0]==odd[-1][0]:
    if len(even)==1 and len(odd)==1:
        ans=n//2
    elif even[-1][1]>odd[-1][1]:
        ans=n-even[-1][1]-odd[-2][1]
    elif even[-1][1]<odd[-1][1]:
        ans=n-even[-2][1]-odd[-1][1]
    else:
        if even[-2][1]>odd[-2][1]:
            ans=n-even[-2][1]-odd[-1][1]
        else:
            ans=n-even[-1][1]-odd[-2][1]
else:
    ans=n-even[-1][1]-odd[-1][1]
print(ans)

Submission status: Accepted

Solution code:
import collections


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

V0 = [V[i] for i in range(len(V)) if i % 2 == 0]
V1 = [V[i] for i in range(len(V)) if i % 2 == 1]

c0 = collections.Counter(V0)
c1 = collections.Counter(V1)

R0 = (n // 2) + (n % 2) - c0.most_common()[0][1]

if c0.most_common()[0] != c1.most_common()[0]:
    R0 += (n // 2) - c1.most_common()[0][1]
else:
    try:
        R0 += (n // 2) - c1.most_common()[1][1]
    except:
        R0 += (n // 2)

R1 = (n // 2) + (n % 2) - c1.most_common()[0][1]

if c0.most_common()[0] != c0.most_common()[0]:
    R1 += (n // 2) - c0.most_common()[0][1]
else:
    try:
        R1 += (n // 2) - c0.most_common()[1][1]
    except:
        R1 += (n // 2)

print(min(R0, R1))

Submission status: Accepted

Solution code:
N = int(input())
V = [int(_) for _ in input().split()]

odd = {}
even = {}
for i in range(N):
    if i%2==0:
        if V[i] in even:
            even[V[i]] += 1
        else:
            even[V[i]] = 1
    else:
        if V[i] in odd:
            odd[V[i]] += 1
        else:
            odd[V[i]] = 1
maxEven, maxOdd = max(even.values()), max(odd.values())
if max(even, key=even.get) != max(odd, key=odd.get):
    print(N-maxEven-maxOdd)
else:
    even[max(even, key=even.get)] = 0
    odd[max(odd, key=odd.get)] = 0
    maxEven2, maxOdd2 = max(even.values()), max(odd.values())
    if maxEven2 >= maxOdd2:
        if len(even) > 1:
            print(N-maxEven2-maxOdd)
        else:
            print(N-maxOdd)
    else:
        if len(odd) > 1:
            print(N-maxEven-maxOdd2)
        else:
            print(N-maxEven)

Submission status: Accepted

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

ans = 0
even = v[::2]
nums_e = {}
for e in even:
    if not e in nums_e.keys():
        nums_e[e] = 1
    else:
        nums_e[e] += 1

e_sorted = []
for key, value in nums_e.items():
    e_sorted.append([value, key])
e_sorted = sorted(e_sorted, reverse = True) + [[0, 0-1]]
        

odd = v[1::2]
nums_o = {}
for o in odd:
    if not o in nums_o.keys():
        nums_o[o] = 1
    else:
        nums_o[o] += 1
        
o_sorted = []
for key, value in nums_o.items():
    o_sorted.append([value, key])
o_sorted = sorted(o_sorted, reverse = True) + [[-1, 0]]

if e_sorted[0][1] != o_sorted[0][1]:
    print(n - e_sorted[0][0] - o_sorted[0][0])
else:
    ans1 = n - e_sorted[1][0] - o_sorted[0][0]
    ans2 = n - e_sorted[0][0] - o_sorted[1][0]
    print(min(ans1, ans2))

Submission status: Accepted

Solution code:
n = input()
a = map(int, raw_input().strip().split())
eve = {}
odd = {}
for i in xrange(0, n, 2):
    try: eve[a[i]] += 1
    except: eve[a[i]] = 1
for i in xrange(1, n, 2):
    try: odd[a[i]] += 1
    except: odd[a[i]] = 1
    
em1 = em2 = om1 = om2 = 0
xe1 = xe2 = xo1 = xo2 = 0
for k in eve:
    if eve[k] > em1:
        em2 = em1
        xe2 = xe1
        em1 = eve[k]
        xe1 = k
    elif eve[k] > em2:
        em2 = eve[k]
        xe2 = k
    
for k in odd:
    if odd[k] > om1:
        om2 = om1
        xo2 = xo1
        om1 = odd[k]
        xo1 = k
    elif odd[k] > om2:
        om2 = odd[k]
        xo2 = k

if xe1 != xo1:
    print n - em1 - om1
else:
    t = n // 2
    if em1 > om1: ans = n - em1 - om2
    elif em1 < om1: ans = n - om1 - em2
    else:
        ans = t - em1
        ans += min(t - em2, t - om2)
    print ans

Submission status: Accepted

Solution code:
import collections

def counter_top(c, exclude):
  for a in c.most_common():
    if a[0] != exclude:
      return a
  return (object(), 0)

def conv_seq(seq, exclude=None):
  c = collections.Counter(seq)
  mc = counter_top(c, exclude)
  return sum(c.values()) - mc[1], mc[0]

input()
vals = list(map(int, input().split()))
s1, a = conv_seq(vals[::2])
s2, b = conv_seq(vals[1::2])
if a != b:
  print(s1 + s2)
else:
  s1_new, _ = conv_seq(vals[::2], exclude=b)
  s2_new, _ = conv_seq(vals[1::2], exclude=a)
  print(min(s1_new + s2, s1 + s2_new))

Submission status: Runtime Error

Solution code:
import itertools

n = int(input())
list_A = list(map(int, input().split()))
L, R = [], []
A, B = [[-1, 0], [-1, 0]]

for i in range(n):
    if i % 2 == 0:
        L.append(list_A[i])
    else:
        R.append(list_A[i])

L = itertools.groupby(L)
for key, group in L:
    A.append([key, len(list(group))])

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

R = itertools.groupby(R)
for key, group in R:
    B.append([key, len(list(group))])

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

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: Runtime Error

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

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

ans = 0
uniq_num = 0
def check_ununiq(list_num, uniq_num):
    # 既に使われている数字かチェック
    # 使われていればそれを置き換える必要があるのでカウント
    if uniq_num in list_num:
        tmp_ans = list_num.count(uniq_num) #
    # ユニークにした時の数字が1より大きいか
    elif len(set(list_num)) > 1:
        # 置き換える回数が少ない方の数字を抽出
        min_ununiq = 10 ** 5
        for i in set(list_num): #
            if list_num.count(i) < min_ununiq:
                min_ununiq = list_num.count(i) #
                uniq_num = i
        tmp_ans = min_ununiq
    # 置き換えが必要ない場合。ユニークとした数字のみを出力
    else:
        uniq_num = list_num[0]
    return(tmp_ans, uniq_num)

tmp_ans, uniq_num = check_ununiq(v_odd, uniq_num)
ans += tmp_ans
tmp_ans, uniq_num = check_ununiq(v_even, uniq_num)
ans += tmp_ans

print(ans)

Submission status: Runtime Error

Solution code:
#100 C - /\/\/\/ AC
import collections
n = int(input())
A = list(map(int,input().split()))

A1 = A[::2]
A2 = A[1::2]
cnt1 = collections.Counter(A1)
cnt2 = collections.Counter(A2)

items1 = list(cnt1.most_comon())
items2 = list(cnt2.most_comon())

if items1[0][0] != items2[0][0]:
    ans = (len(A1) - items1[0][1]) + (len(A2) - items2[0][1])
else:
    if len(items1) == len(items2) == 1:
        ans = min(len(A1),len(A2))

    else:
        ans1 = (len(A1) - items1[0][1]) + (len(A2) - items2[1][1])
        ans2 = (len(A1) - items1[1][1]) + (len(A2) - items2[0][1])
        ans = min(ans1,ans2)
print(ans)

Submission status: Runtime Error

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

#import
#import math
#import numpy as np
n = int(input())
V = list(map(int, input().split()))

even = {}
odd = {}

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

odic = {0:1}
edic = {0:1}

for o in odd:
    t = odd[o]
    if t in odic:
        odic[t].append(o)
    else:
        odic[t] = [o]

for e in even:
    t = even[e]
    if t in edic:
        edic[t].append(e)
    else:
        edic[t] = [e]

okey = list(odic.keys())
ekey = list(edic.keys())


maxo = okey[-1]
maxe = ekey[-1]

ans = n - maxo - maxe

if odic[maxo] == edic[maxe]:
    if len(odic[maxo]) == 1:
        nexto = okey[-2]
        nexte = ekey[-2]
        
    ans += maxe - max(nexto, nexte)

print(ans)

Submission status: Runtime Error

Solution code:
#100 C - /\/\/\/
import collections
n = int(input())
A = list(map(int,input().split()))

A1 = A[::2]
A2 = A[1::2]
cnt1 = collections.Counter(A1)
cnt2 = collections.Counter(A2)

items1 = list(cnt1.items())
items2 = list(cnt2.items())

if items1[0][0] != items2[0][0]:
    ans = (len(A1) - items1[0][1]) + (len(A2) - items2[0][1])
else:
    ans1 = (len(A1) - items1[0][1]) + (len(A2) - items2[1][1])
    ans2 = (len(A1) - items1[1][1]) + (len(A2) - items2[0][1])
    ans = min(ans1,ans2)
print(ans)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = [int(x) for x in input().split()]
v_odd, v_evn = [], []
for i in range(n):
  if i%2==0:
    v_odd.append(v[i])
  else:
    v_evn.append(v[i])
v_odd_cnt = collections.Counter(v_odd)
v_evn_cnt = collections.Counter(v_evn)
#print(v_odd_cnt, v_even_cnt)
max_kv_odd = max(v_odd_cnt.items(), key=lambda x: x[1])
max_kv_evn = max(v_evn_cnt.items(), key=lambda x: x[1])
if max_kv_odd[0] == max_kv_evn[0]:
  v_odd_cnt_tmp = v_odd_cnt
  v_evn_cnt_tmp = v_evn_cnt
  v_odd_cnt_tmp.pop(max_kv_odd[0])
  v_evn_cnt_tmp.pop(max_kv_evn[0])
  max_kv_odd_tmp = max(v_odd_cnt_tmp.items(), key=lambda x: x[1])
  max_kv_evn_tmp = max(v_evn_cnt_tmp.items(), key=lambda x: x[1])
  a = max_kv_odd[1] + max_kv_evn_tmp[1]
  b = max_kv_evn[1] + max_kv_odd_tmp[1]
  print(n-max(a, b))
  exit()
print(n-max_kv_odd[1]-max_kv_evn[1])
'''
v_odd = [0] * 10**5
veven = [0] * 10**5
for i in range(0, n//2+1, 2):
  v_odd[v[i]] += 1
  veven[v[i+1]] += 1
for i, x in enumerate(v_odd):

v_odd = {}
veven = {}
for i in range(0, n//2+1, 2):
  v_odd[v[i]] = v_odd.get(v[i], 0) + 1
  veven[v[i+1]] = veven.get(v[i+1], 0) + 1
'''

Submission status: Runtime Error

Solution code:
n = int(input())
alist  = list(map(int,input().split()))
list1 = alist[1::2]
list2 = alist[0::2]
from collections import Counter
dic1 = Counter(list1).most_common()
dic2 = Counter(list2).most_common()

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

Submission status: Runtime Error

Solution code:
n = int(input())
alist  = list(map(int,input().split()))
list1 = alist[1::2]
list2 = alist[0::2]
from collections import Counter
dic1 = Counter(list1).most_common()
dic2 = Counter(list2).most_common()
dic1.append([0,0])
dic2.append([0,])
if dic1[0][0]!=dic2[0][0]:
  print(n - dic1[0][1] - dic2[0][1])
else:
  print(min(n - dic1[0][1] - dic2[1][1], n -dic1[1][1] - dic2[0][1]))

Submission status: Runtime Error

Solution code:
n = int(input())
alist  = list(map(int,input().split()))
list1 = alist[1::2]
list2 = alist[0::2]
from collections import Counter
dic1 = Counter(list1)
dic2 = Counter(list2)
sortdic1 = sorted(dic1.items(),key=lambda x:x[1], reverse=True)
sortdic2 = sorted(dic2.items(),key=lambda x:x[1], reverse=True)
vlist1 = list(sortdic1.items())
vlist2 = list(sortdic2.items())
if vlist1[0][0]!=vlist2[0][0]:
  print(n - vlist1[0][1] - vlist2[0][1])
else:
  if (vlist1[0][1] + vlist2[1][1])>(vlist1[1][1] + vlist2[0][1]):
    print(n - vlist1[0][1] - vlist2[1][1])
  else:
    print(n -vlist1[1][1] - vlist2[0][1])

Submission status: Runtime Error

Solution code:
n = int(input())
alist  = list(map(int,input().split()))
list1 = alist[1::2]
list2 = alist[0::2]
from collections import Counter
dic1 = Counter(list1)
dic2 = Counter(list2)
sortdic1 = sorted(dic1.items(),key=lambda x:x[1], reverse=True)
sortdic2 = sorted(dic2.items(),key=lambda x:x[1], reverse=True)
vlist1 = list(sortdic1.items())
vlist2 = list(sortdic2.items())
if vlist1[0][0]!=vlist[0][0]:
  print(n - vlist1[0][1] - vlist2[0][1])
else:
  if (vlist1[0][1] + vlist2[1][1])>(vlist1[1][1] + vlist2[0][1]):
    print(n - vlist1[0][1] - vlist2[1][1])
  else:
    print(n -vlist1[1][1] - vlist2[0][1])

Submission status: Runtime Error

Solution code:
n = int(input())
alist  = list(map(int,input().split()))
list1 = alist[1::2]
list2 = blist[0::2]
from collections import Counter
dic1 = Counter(list1)
dic2 = Counter(list2)
vlist1 = sorted(list(dic1.values()))
vlist2 = sorted(list(dic2.values()))
print(n - vlist1[-1] - vlist2[-1])

Submission status: Runtime Error

Solution code:
n = int(input())
alist  = list(map(int,input().split()))
from collections import Counter
adic = Counter(alist)
vlist = sorted(list(adic.values()))
print(n - vlist[-1] - vlist[-2])

Submission status: Runtime Error

Solution code:
import collections

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

even_odd_length = n / 2
replace_total = 0

list_odd = v[0::2]
list_even = v[1::2]

dict_c_odd = dict(collections.Counter(list_odd))
dict_c_even = dict(collections.Counter(list_even))

if len(set(v)) == 1:
    print(int(even_odd_length))
else:
    max_count_c_odd = max(dict_c_odd.values())
    max_count_c_even = max(dict_c_even.values())
    max_c_odd_keys = [k for k, v in dict_c_odd.items() if v == max_count_c_odd]
    max_c_even_keys = [k for k, v in dict_c_even.items() if v == max_count_c_even]
    
    if max_count_c_odd > max_count_c_even:
        if max_c_odd_keys[0] in dict_c_even:
            del dict_c_even[max_c_odd_keys[0]]
        max_count_c_even = max(dict_c_even.values())
    elif max_count_c_odd < max_count_c_even:
        if max_c_even_keys[0] in dict_c_odd:
            del dict_c_odd[max_c_even_keys[0]]
        max_count_c_odd = max(dict_c_odd.values())
    else:
        if len(max_c_odd_keys) > len(max_c_even_keys):
            if max_c_even_keys[0] in dict_c_odd:
                del dict_c_odd[max_c_even_keys[0]]
            max_count_c_odd = max(dict_c_odd.values())
        elif len(max_c_odd_keys) < len(max_c_even_keys):
            if max_c_odd_keys[0] in dict_c_even:
                del dict_c_even[max_c_odd_keys[0]]
            max_count_c_even = max(dict_c_even.values())
        else:
            if list((set(max_c_odd_keys) & set(max_c_even_keys)))[0] in dict_c_odd:
                del dict_c_odd[max_c_even_keys[0]]
            max_count_c_odd = max(dict_c_odd.values())
    replace_total += (n - max_count_c_odd - max_count_c_even)
    print(int(replace_total))

Submission status: Runtime Error

Solution code:
import collections

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

even_odd_length = n / 2
replace_total = 0

list_odd = v[0::2]
list_even = v[1::2]

dict_c_odd = dict(collections.Counter(list_odd))
dict_c_even = dict(collections.Counter(list_even))

if len(set(v)) == 1:
    print(int(even_odd_length))
else:
    max_count_c_odd = max(dict_c_odd.values())
    max_count_c_even = max(dict_c_even.values())
    max_c_odd_keys = [k for k, v in dict_c_odd.items() if v == max_count_c_odd]
    max_c_even_keys = [k for k, v in dict_c_even.items() if v == max_count_c_even]
    
    if max_count_c_odd > max_count_c_even:
        if max_c_odd_keys[0] in dict_c_even:
            del dict_c_even[max_c_odd_keys[0]]
        max_count_c_even = max(dict_c_even.values())
    elif max_count_c_odd < max_count_c_even:
        if max_c_even_keys[0] in dict_c_odd:
            del dict_c_odd[max_c_even_keys[0]]
        max_count_c_odd = max(dict_c_odd.values())
    else:
        if len(max_c_odd_keys) > len(max_c_even_keys):
            if max_c_even_keys[0] in dict_c_odd:
                del dict_c_odd[max_c_even_keys[0]]
            max_count_c_odd = max(dict_c_odd.values())
        elif: len(max_c_odd_keys) > len(max_c_even_keys):
            if max_c_odd_keys[0] in dict_c_even:
                del dict_c_even[max_c_odd_keys[0]]
            max_count_c_even = max(dict_c_even.values())
        else:
            if max_c_odd_keys[0] in dict_c_even:
                del dict_c_even[max_c_odd_keys[0]]
            max_count_c_even = max(dict_c_even.values())
    replace_total += (n - max_count_c_odd - max_count_c_even)
    print(int(replace_total))

Submission status: Runtime Error

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

    even = [0] * (10 ** 5)
    odd = [0] * (10 ** 5)

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

    max_even = even.index(max(even))
    max_odd = odd.index(max(odd))

    if max_even == max_odd:
        even[max_even] = 0
        odd[max_odd] = 0
        if max(even) < max(odd):
            max_odd = odd.index(max(odd))
        else:
            max_even = even.index(max(even))
    ans = 0
    for i in range(n):
        if i % 2 == 0 and max_even != v[i]:
            ans += 1
        if i % 2 != 0 and max_odd != v[i]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

    even = [0] * (10 ** 5)
    odd = [0] * (10 ** 5)

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

    max_even = even.index(max(even))
    max_odd = odd.index(max(odd))

    ans = 0
    if max_even != max_odd:
        ans = n - even[max_even] - odd[max_odd]
    else:
        temp_even = even[max_even]
        temp_odd = odd[max_odd]
        even[max_even] = 0
        odd[max_odd] = 0
        max_even2 = even.index(max(even))
        max_odd2 = odd.index(max(odd))
        if even[max_even2] > odd[max_odd2]:
            ans = n - even[max_even2] - temp_odd
        else:
            ans = n - temp_even - odd[max_odd2]

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
o = defaultdict(int)
e = defaultdict(int)
odd_num = 0
even_num = 0
for i, v_one in enumerate(v):
  if i % 2 == 1:
    o[v_one] += 1
    odd_num += 1
  else:
    e[v_one] += 1
    even_num += 1
sorted_o = sorted(o.items(), key=lambda x:-x[1])
sorted_e = sorted(e.items(), key=lambda x:-x[1])
if sorted_o[0][0] != sorted_e[0][0]:
  ans = odd_num - sorted_o[0][1] + even_num - sorted_e[0][1]
else:
  ans1 = odd_num - sorted_o[1][1] + even_num - sorted_e[0][1]
  ans2 = odd_num - sorted_o[0][1] + even_num - sorted_e[1][1]
  ans = min(ans1, ans2)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
D1 = defaultdict(int)
D2 = defaultdict(int)

for i in range(0,N,2):
  D1[A[i]]+=1
for i in range(1,N,2):
  D2[A[i]]+=1
  
D1_sorted = sorted(D1.items(), key=lambda x:x[1], reverse = True) + [-1,0]
D2_sorted = sorted(D2.items(), key=lambda x:x[1], reverse = True) + [-1,0]

i, j = 0, 0
while i < len(D1_sorted) -1 and j < len(D2_sorted) -1:
  if D1_sorted[i][0] != D2_sorted[j][0]:
    break
  elif D1_sorted[i][1] > D2_sorted[j][1]:
    j+=1
  elif D1_sorted[i][1] < D2_sorted[j][1]:
    i+=1
  else:
    if D1_sorted[i+1][1] > D2_sorted[j+1][1]:
      i+=1
    else:
      j+=1

print(N-D1_sorted[i][1]-D2_sorted[j][1])

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
a = list(map(int,input().split()))
a1 = collections.Counter(a[0::2]).most_common()
a2 = collections.Counter(a[1::2]).most_common()
#a1.append((0,0))
#a2.append((0,0))
#print(a1)
#print(a2)

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

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
a = list(map(int,input().split()))
a1 = collections.Counter(a[0::2]).most_common()
a2 = collections.Counter(a[1::2]).most_common()
#a1.append((0,0))
#a2.append((0,0))
print(a1)
print(a2)

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

Submission status: Runtime Error

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

c1=Counter(V[0::2]).most_common()+[(0,0)]
c2=Counter(V[1::2]).most_common()+[(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: Runtime Error

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

c1=Counter(V[0::2]).most_common()+[(0,0)]
c2=Counter(V[1::2]).most_common()+[(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: Runtime Error

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

count = np.zeros(10**5, dtype=int)
for i in range(n):
  idx = v[i-1]
  count[idx] += 1
count = sorted(count, reverse=True)

total = count[0] + count[1]
if total == n:
  if count[0] == count[1]:
    print(0)
  else:
    print(abs(count[0]-count[1])//2)
else:
  print(n-total)

Submission status: Runtime Error

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

v_even = [0]*100000
v_odd = [0]*100000

for i in range(n):
  if i%2==0:
    v_even[v[i]] += 1 
  else:
    v_odd[v[i]] += 1
    
res1 = max(v_even)
res2 = max(v_odd)
if v_even.index(res1) == v_odd.index(res2):
  if res1 >= res2:
    v_odd[v_odd.index(res2)] = 0
    res2 = max(v_odd)
  else:
    v_even[v_even.index(res1)] = 0
    res1 = max(v_even)
print(n//2-res1 + n//2-res2)

Submission status: Runtime Error

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


first = {}
second = {}

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

first = sorted(first.items(), key=lambda x: x[1])
second = sorted(second.items(), key=lambda x: x[1])

f = first.pop()
s = second.pop()

if f[0] == s[0]:
    if len(first) >= 1:
        if len(second) >= 1:
            f2 = first.pop()
            s2 = second.pop()

            if f2[1] > s2[2]:
                f = f2
            else:
                s = s2
        else:
            s = second.pop()
    elif len(second) >= 1:
        f = first.pop()
    else:
        s = (0, 0)

print(n-f[1]-s[1])

Submission status: Runtime Error

Solution code:
import math
N=int(input())
V=list(map(int,input().split()))
counter = [dict() for _ in range(2)]
for i in range(N):
  if V[i] in counter[i%2]:
    counter[i%2][V[i]] += 1
  else:
    counter[i%2][V[i]] = 1

counter[0] = sorted(counter[0].items(), reverse=True, key=lambda x:x[1])
counter[1] = sorted(counter[1].items(), reverse=True, key=lambda x:x[1])
if counter[0][0][0]!=counter[1][0][0]:
  print(N-counter[0][0][1] - counter[1][0][1])
elif N%2 or counter[0][0][1] < counter[1][0][1]:
  print(N-counter[0][0][1] - counter[1][1][1])
else:
  print(N-counter[0][1][1] - counter[1][0][1])

Submission status: Runtime Error

Solution code:
import copy
import numpy as np

n = int(input())
v = list(map(int,input().split()))
a = v[0::2] 
b = v[1::2]

cnta = np.zeros(10**5+1, dtype=int)
cntb = np.zeros(10**5+1, dtype=int)
for i in range(n//2):
    ca, cb = a[i], b[i]
    cnta[ca] += 1
    cntb[cb] += 1
print(a, cnta[:5])
print(b, cntb[:5])
la = np.zeros((2,2), dtype=int)
lb = np.zeros((2,2), dtype=int)
for i in range(2):
    ia = cnta.argmax()
    ib = cntb.argmax()
    la[i][0], la[i][1] = ia, cnta[ia]
    lb[i][0], lb[i][1] = ib, cntb[ib]
    cnta[ia] = -1
    cntb[ib] = -1
print(la)
print(lb)
if la[0][0] != lb[0][0]:
    ans = n//2 - la[0][1] + n//2 - lb[0][1]
elif la[0][1] > lb[0][1]:
    ans = min(n//2 - la[0][1] + n//2 - lb[1][1], n//2 - la[1][1] + n//2 - lb[0][1])
print(ans)

Submission status: Runtime Error

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

ans = 0
eve = V[0::2]
odd = V[1::2]
cntEve = collections.Counter(eve)
cntOdd = collections.Counter(odd)

if cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]:
    ans = N - max(cntEve.most_common()[0][1],cntOdd.most_common()[0][1]) - max(cntEve.most_common()[1][1],cntOdd.most_common()[1][1])
else:
    ans = N - int(cntEve.most_common()[0][1]) - int(cntOdd.most_common()[0][1])

print(ans)

Submission status: Runtime Error

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

ans = 0
eve = V[0::2]
odd = V[1::2]
cntEve = collections.Counter(eve)
cntOdd = collections.Counter(odd)

if cntEve.most_common()[0][0] == cntOdd.most_common()[0][0]:
    ans = N - max(cntEve.most_common()[0][1],cntOdd.most_common()[0][1]) - max(cntEve.most_common()[1][1],cntOdd.most_common()[1][1])
else:
    ans = N - cntEve.most_common()[0][1] - cntOdd.most_common()[0][1]

print(ans)

Submission status: Runtime Error

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

even_=[]
odd_=[]
for i in range(len(v)):
  if i%2==0:
    even_.append(v[i])

  else:
    odd_.append(v[i])

from collections import Counter
even=Counter(even_)
odd=Counter(odd_)


even1=[]
for i,j in even.items():
  even1.append([i,j])

odd1=[]
for i,j in odd.items():
  odd1.append([i,j])

even1.sort()
odd1.sort()


if even1[-1][0]!=odd1[-1][0]:
  print(n//2-even1[-1][1]+n//2-odd1[-1][1])

else:
  s=n//2-even1[-1][1]+n//2-odd1[-2][1]
  t=n//2-even1[-2][1]+n//2-odd1[-1][1]
  print(min(s,t))

Submission status: Runtime Error

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

even_=[]
odd_=[]
for i in range(len(v)):
  if i%2==0:
    even_.append(v[i])

  else:
    odd_.append(v[i])

from collections import Counter
even=Counter(even_)
print(even)
odd=Counter(odd_)
print(odd)

even1=[]
for i,j in even.items():
  even1.append([i,j])

odd1=[]
for i,j in odd.items():
  odd1.append([i,j])

even1.sort()
odd1.sort()

print(even1)
print(odd1)

if even1[-1][0]!=odd1[-1][0]:
  print(n//2-even1[-1][1]+n//2-odd1[-1][1])

else:
  s=n//2-even1[-1][1]+n//2-odd1[-2][1]
  t=n//2-even1[-2][1]+n//2-odd1[-1][1]
  print(min(s,t))

Submission status: Runtime Error

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

from collections import*
C1=Counter(V[::2])
C1=sorted(C1.items(),key=lambda x:x[1])
C2=Counter(V[1::2])
C2=sorted(C2.items(),key=lambda x:x[1])

K1=C1[-1][0]
V1=C1[-1][1]
K2=C2[-1][0]
V2=C2[-1][1]
if V1>V2:
    if K1==K2:
        V2=C2[-2][1]
elif V2>V1:
    if K1==k2:
        V1=C1[-2][1]
elif K1==K2:
    if len(set(C1))==1:
        V2=C2[-2*(len(set(C2))>1)][1]*(len(set(C2))>1)
    else:
        V1=C1[-2*(len(set(C1))>1)][1]*(len(set(C1))>1)

print(N-V1-V2)

Submission status: Runtime Error

Solution code:
import collections
import sys
n = int(input())
a = list(map(int,input().split()))
#if len(set(a)) == 1:
 # print(n//2)
 # sys.exit()
a1 = [a[x] for x in range(0,n,2)]
l_a1 = len(a1)
a2 = [a[y] for y in range(1,n,2)]
l_a2 = len(a2)
c1 = collections.Counter(a1)
c2 = collections.Counter(a2)
K_a1 = c1.most_common()[0][0]
#print(K_a1)
K_a2 = c2.most_common()[0][0]
#print(K_a2)
F_a1 = c1.most_common(1)[0][1]
F_a2 = c2.most_common(1)[0][1]
if K_a1 == K_a2:
  if  c1.most_common(2)[0][1] >= c2.most_common(2)[0][1]:
    F_a2 = c2.most_common()[1][1]
  else:
    F_a1 = c1.most_common()[1][1]
   # print(F_a1)
print((l_a1 - F_a1)+(l_a2 - F_a2))

Submission status: Runtime Error

Solution code:
# https://atcoder.jp/contests/abc111/tasks/arc103_a
from collections import Counter
n = int(input())
nums = [int(i) for i in input().split()]

for i in range(n - 1):
    if nums[i + 1] != nums[i]:
        break
else:
    print(n // 2)
    sys.exit()


odd = Counter(nums[1::2]).most_common()
even = Counter(nums[::2]).most_common()
odd.append((0, 0))
even.append((0, 0))
if odd[0][0] != even[0][0]:
    ans = n - (odd[0][1] + even[0][1])
else:
    s = n - (odd[0][1] + even[1][1])
    t = n - (odd[1][1] + even[0][1])
    ans = min(s, t)
print(ans)

Submission status: Runtime Error

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

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

C_even = Counter(even)
C_odd = Counter(odd)
if C_even == C_odd:
    print(n//2)
    exit()

el = list(C_even.items())
ol = list(C_odd.items())
# print(el)
# print(ol)


num = 0
ans = 0
for i in range(len(el)):
    for j in range(len(ol)):
        if el[i][0] != ol[i][0]:
            if el[i][1] + el[i][1] > num:
                # print(el[i][1], ol[i][1])
                num = el[i][1] + ol[i][1]
                ans = n//2 - el[i][1] + n//2 - ol[i][1]

print(ans)