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

Solution code:
#encoding utf-8
def main(n,v):
    n = int(input())
    v = list(int(i) for i in input().split())
    even_v = []
    odd_v = []

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

    odd_dic = {}
    even_dic = {}
    for i in range(len(odd_v)):
        if odd_v[i] in odd_dic.keys():
            odd_dic[odd_v[i]] += 1
        else:
            odd_dic[odd_v[i]] = 1

    for i in range(len(even_v)):
        if even_v[i] in even_dic.keys():
            even_dic[even_v[i]] += 1
        else:
            even_dic[even_v[i]] = 1

    tem_dic = {}
    for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    even_dic = tem_dic
    tem_dic = {}
    for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    odd_dic = tem_dic

    # odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
    # even_dic = sorted(even_dic.items(),key=lambda x:x[1])

    odd_keys = list(odd_dic.keys())
    even_keys = list(even_dic.keys())

    # for i in range(len(odd_keys)-1):
    #     if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
    #         if odd_keys[i] > odd_keys[i+1]:
    #             tem = odd_keys[i]
    #             odd_keys[i] = odd_keys[i+1]
    #             odd_keys[i+1] = tem
    #
    # for i in range(len(even_keys)-1):
    #     if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
    #         if even_keys[i] > even_keys[i+1]:
    #             tem = even_keys[i]
    #             even_keys[i] = even_keys[i+1]
    #             even_keys[i+1] = tem


    # print(even_dic,odd_dic)
    # print(even_keys,odd_keys)

    if odd_keys[0] != even_keys[0]:
        answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
    else:
        if len(odd_keys) == 1 and len(even_keys) == 1:
            answer = len(odd_v)
        elif len(odd_keys) == 1:
            answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        elif len(even_keys) == 1:
            answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        else:
            # if odd_dic[odd_keys[1]] > even_dic[even_keys[1]]:
            #     answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
            # else:
            #     answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
            ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
            ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
            answer = min(ans1, ans2)
    print(int(answer))
    # return(int(answer))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:

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

ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

ans = 0

if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)
    else:
        if ki[1][1] > gu[1][1]:
            ans = n - ki[1][1] - gu[0][1]
        else:
            ans = n - ki[0][1] - gu[1][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print(ans)

Submission status: Runtime Error

Solution code:

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

ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

ans = 0

if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)
    else:
        if ki[1][1] > gu[1][1]:
            ans = n - ki[1][1] - gu[0][1]
        else:
            ans = n - ki[0][1] - gu[1][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print("答え",ans)

Submission status: Runtime Error

Solution code:
#encoding utf-8

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

even_v = []
odd_v = []

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

odd_dic = {}
even_dic = {}
for i in range(len(odd_v)):
    if odd_v[i] in odd_dic.keys():
        odd_dic[odd_v[i]] += 1
    else:
        odd_dic[odd_v[i]] = 1

for i in range(len(even_v)):
    if even_v[i] in even_dic.keys():
        even_dic[even_v[i]] += 1
    else:
        even_dic[even_v[i]] = 1


for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):pass
for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):pass

# odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
# even_dic = sorted(even_dic.items(),key=lambda x:x[1])

odd_keys = list(odd_dic.keys())
even_keys = list(even_dic.keys())

if odd_keys[0] != even_keys[0]:
    answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
else:
    if len(odd_keys) == 1 and len(even_keys) == 1:
        answer = len(odd_v)
    else:
        answer = mins(int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]]), int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]]))

print(int(answer))


































# #encoding utf-8
#
# n = int(input())
# v = list(int(i) for i in input().split())
#
#
# v_odd = []
# v_even = []
# for i in range(n):
#     if i%2 == 0:
#         v_odd.append(v[i])
#     else:
#         v_even.append(v[i])
#
# #odd part
# count={}
# for i in range(len(v_odd)):
#     if v_odd[i] in count.keys():
#         count[v_odd[i]] += 1
#     else:
#         count[v_odd[i]] = 1
#
# for k, v in sorted(count.items(), key=lambda x: -x[1]):
#     pass
# keys = list(count.keys())
#
# #even part
# even_count={}
# for i in range(len(v_even)):
#     if v_even[i] in even_count.keys():
#         even_count[v_even[i]] += 1
#     else:
#         even_count[v_even[i]] = 1
#
# # print(even_count)
# for k, v in sorted(even_count.items(), key=lambda x: -x[1]):
#     pass
# even_keys = list(even_count.keys())
#
# if even_keys[0] == keys[0]:
#     if len(keys) == 1 and len(even_keys) == 1:
#         answer = int(n/2)
#     elif len(keys) == 1:
#         answer = int(n/2)-int(even_count[even_keys[1]])
#     elif len(even_keys) == 1:
#         answer = int(n/2)-int(count[keys[1]])
#     else:
#         if int(even_count[even_keys[0]]) > int(count[keys[0]]):
#             answer = n-int(count[keys[1]])-int(even_count[even_keys[0]])
#         elif int(even_count[even_keys[0]]) < int(count[keys[0]]):
#             answer = n-int(count[keys[0]])-int(even_count[even_keys[1]])
#         elif int(even_count[even_keys[0]]) == int(count[keys[0]]):
#             if int(even_count[even_keys[1]]) > int(count[keys[1]]):
#                 answer = n-int(even_count[even_keys[1]])-int(count[keys[0]])
#             elif int(even_count[even_keys[1]]) < int(count[keys[1]]):
#                 answer = n-int(even_count[even_keys[0]])-int(count[keys[1]])
#             else:
#                 answer = n-int(even_count[even_keys[1]])-int(count[keys[0]])
# else:
#     answer = n-int(count[keys[0]])-int(even_count[even_keys[0]])
# print(int(answer))

Submission status: Runtime Error

Solution code:
import collections

n = input()
line = input().split()
odd = line[::2]
even = line[1::2]
o = collections.Counter(odd)
e = collections.Counter(even)
maxoddcnt = o.most_common()[0][1]
maxevencnt = e.most_common()[0][1]

#すべての値が同じときは半分を置換する
if odd == even:
    print(len(odd))
    input()
    exit(0)

#奇数列，偶数列それぞれの最頻の文字が同じ場合は，いずれかを2番目に多い文字に置換しなければならない
if o.most_common()[0][0] == e.most_common()[0][0]:
    if len(o.most_common()) > 1 and len(e.most_common()) <= 1:
        maxoddcnt = o.most_common()[1][1]
    if len(o.most_common()) <= 1 and len(e.most_common()) > 1:
        maxevencnt = e.most_common()[1][1]
    if o.most_common()[1][1] + e.most_common()[0][1] >= o.most_common()[0][1] + e.most_common()[1][1]:
        maxoddcnt = o.most_common()[1][1]
    else: #if o.most_common()[1][1] + e.most_common()[0][1] <= o.most_common()[0][1] + e.most_common()[1][1] :
        maxevencnt = e.most_common()[1][1]

print(len(odd)-maxoddcnt+len(even)-maxevencnt)

Submission status: Runtime Error

Solution code:
import collections

n = input()
line = input().split()
odd = line[::2]
even = line[1::2]
o = collections.Counter(odd)
e = collections.Counter(even)
maxoddcnt = o.most_common()[0][1]
maxevencnt = e.most_common()[0][1]

#すべての値が同じときは半分を置換する
if odd == even:
    print(len(odd))
    exit(0)

#奇数列，偶数列それぞれの最頻の文字が同じ場合は，いずれかを2番目に多い文字に置換しなければならない
if o.most_common()[0][0] == e.most_common()[0][0]:
    if len(o.most_common()) > 1 and len(e.most_common()) <= 1:
        maxoddcnt = o.most_common()[1][1]
    if len(o.most_common()) <= 1 and len(e.most_common()) > 1:
        maxevencnt = e.most_common()[1][1]
    if o.most_common()[1][1] + e.most_common()[0][1] >= o.most_common()[0][1] + e.most_common()[1][1]:
        maxoddcnt = o.most_common()[1][1]
    else: #if o.most_common()[1][1] + e.most_common()[0][1] <= o.most_common()[0][1] + e.most_common()[1][1] :
        maxevencnt = e.most_common()[1][1]
        input()

print(len(odd)-maxoddcnt+len(even)-maxevencnt)

Submission status: Runtime Error

Solution code:
import collections

n = input()
line = input().split()
odd = line[::2]
even = line[1::2]
o = collections.Counter(odd)
e = collections.Counter(even)
maxoddcnt = o.most_common()[0][1]
maxevencnt = e.most_common()[0][1]

#すべての値が同じときは半分を置換する
if odd == even:
    print(len(odd))
    exit(0)

#奇数列，偶数列それぞれの最頻の文字が同じ場合は，いずれかを2番目に多い文字に置換しなければならない
if o.most_common()[0][0] == e.most_common()[0][0]:
    if len(o.most_common()) > 1 and len(e.most_common()) <= 1:
        maxoddcnt = o.most_common()[1][1]
    if len(o.most_common()) <= 1 and len(e.most_common()) > 1:
        maxevencnt = e.most_common()[1][1]
    if o.most_common()[1][1] + e.most_common()[0][1] >= o.most_common()[0][1] + e.most_common()[1][1]:
        maxoddcnt = o.most_common()[1][1]
        input()
    else: #if o.most_common()[1][1] + e.most_common()[0][1] <= o.most_common()[0][1] + e.most_common()[1][1] :
        maxevencnt = e.most_common()[1][1]

print(len(odd)-maxoddcnt+len(even)-maxevencnt)

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
even=v[0::2]
odd=v[1::2]
import collections
c=collections.Counter(even)
d=collections.Counter(odd)
e=c.most_common()[0][0]
o=d.most_common()[0][0]
e2=c.most_common()[0][1]
o2=d.most_common()[0][1]
if e==o:
  	if even.count(e)==odd.count(o)==len(even):
        print(n/2)
    elif even.count(e)>odd.count(o):
        o=o2
    else:
        e=e2
count=len(v)-(even.count(e)+odd.count(o))
print(count)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import numpy as np

n = input()
m = input().strip().split()
l = [0] * 100000
k = [0] * 100000
b = m[0::2]
c = m[1::2]

for i in b:
    i = int(i)
    l[i] = l[i] + 1

for j in c:
    j = int(j)
    k[j] = k[j] + 1

print(len(b)-int(max(l))+len(c)-int(max(k)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import numpy as np

n = input()
m = input().strip().split()
l = [0] * 10000
k = [0] * 10000
b = m[0::2]
c = m[1::2]

for i in b:
    i = int(i)
    l[i] = l[i] + 1

for j in c:
    j = int(j)
    k[j] = k[j] + 1

print(len(b)-int(max(l))+len(c)-int(max(k)))

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
if(n == 2):
    print(0)
else:
    n2 = n/2
    v = [int(i) for i in input().split()]
    v1 = Counter(v[::2])
    v2 = Counter(v[1::2])
    v1mc = v1.most_common()
    v2mc = v2.most_common()
    if(v1mc[0][0] == v2mc[0][0]):
        print(n - max(v1mc[0][1]+v2mc[1][1], v2mc[0][1]+v1mc[1][1]))
    else:
        print(n - (v1mc[0][1]+v2mc[0][1]))

Submission status: Runtime Error

Solution code:
n = int(input())
n2 = n/2
v = [int(i) for i in input().split()]
v1 = []
v2 = []
for i in range(n):
    if(i % 2 == 0):
        v1.append(v[i])
    else:
        v2.append(v[i])
count1 = [v1.count(v1[i]) for i in range(int(n2))]
count2 = [v2.count(v2[i]) for i in range(int(n2))]
if(v1[count1.index(max(count1))] == v2[count2.index(max(count2))]):
    max1 = max(count1)
    max2 = max(count2)
    count1 = list(set(count1))
    count1.remove(max(count1))
    count2 = list(set(count2))
    count2.remove(max(count2))
    if(max(count1) > max(count2)):
        print(n - max(count1) - max2)
    else:
        print(n - max(count2) - max1)
else:
    print(n - max1 - max2)

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
origin_list=list(map(int,input().split()))
list_1=[]
list_2=[]
for i in range(1,n/2):
    list_1.append(origin_list[i])
for i in range((n/2)-1):
    list_2.append(origin_list[i]
mode1=list_1.most_common(1)[0][1]
mode2=list_2.most_common(1)[0][1]
print(n-(mode1+mode2))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if v.count(v[0]) == n:
    print(n // 2)
    exit()
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
e_counter = Counter(e)
o_counter = Counter(o)
E1 = list(e_counter.keys())[0]
if len(list(e_counter.keys())) > 1:
    E2 = list(e_counter.keys())[1]
else:
    E2 = E1
O1 = list(o_counter.keys())[0]
if len(list(o_counter.keys())) > 1:
    O2 = list(o_counter.keys())[1]
else:
    O2 = O1
e_cnt = n // 2 - max(e.count(E1))
o_cnt = n // 2 - max(o.count(O1))
if e_cnt == 0 and o_cnt == 0:
    print(0)
else:
    print(e_cnt + o_cnt)

Submission status: Runtime Error

Solution code:
import collections
def rep(n,key):
    count = 0
    for i in n:
        if i != key:
            count += 1
    return count 

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

count_odd = collections.Counter(v_odd)
count_even = collections.Counter(v_even)
odd_val = list(count_odd.values())
even_val = list(count_even.values())
odd_key = list(count_odd.keys())
even_key = list(count_even.keys())

if odd_key[0] != even_key[0]:
    odd_sum = rep(v_odd, str(odd_key[0]))
    even_sum = rep(v_even, str(even_key[0]))
    print(odd_sum+even_sum)

else:
    if len(odd_key) != 0:
        judge_odd = True
    else:
        judge_odd = False
    
    if len(eveb_key) != 0:
        judge_even = True
    else:
        judge_even = False
    
    if judge_even and judge_odd:
        odd_sum1 = rep(v_odd, odd_key[0])
        even_sum1 = rep(v_even, even_key[1])
        ans1 = odd_sum1+even_sum1

        odd_sum2 = rep(v_odd, odd_key[1])
        even_sum2 = rep(v_even, even_key[0])
        ans2 = odd_sum2 + even_sum2 
        print(min(ans1,ans2))
    else:
        if judge_odd or judge_even:
            if odd:
                print(rep(v_odd, odd_key[1]))
            else:
                print(rep(v_odd,even_key[1]))

        else:
            print(odd_key[0])

Submission status: Runtime Error

Solution code:
import collections
def rep(n,key):
    count = 0
    for i in n:
        if i != key:
            count += 1
    return count 

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

count_odd = collections.Counter(v_odd)
count_even = collections.Counter(v_even)
odd_val = list(count_odd.values())
even_val = list(count_even.values())
odd_key = list(count_odd.keys())
even_key = list(count_even.keys())

if odd_key[0] != even_key[0]:
    odd_sum = rep(v_odd, str(odd_key[0]))
    even_sum = rep(v_even, str(even_key[0]))
    print(odd_sum+even_sum)

else:
    if len(odd_key) != 0:
        judge_odd = True
    else:
        judge_odd = False
    
    if len(eveb_key) != 0:
        judge_even = True
    else:
        judge_even = False:
    
    if judge_even and judge_odd:
        odd_sum1 = rep(v_odd, odd_key[0])
        even_sum1 = rep(v_even, even_key[1])
        ans1 = odd_sum1+even_sum1

        odd_sum2 = rep(v_odd, odd_key[1])
        even_sum2 = rep(v_even, even_key[0])
        ans2 = odd_sum2 + even_sum2 
        print(min(ans1,ans2))
    else:
        if judge_odd or judge_even:
            if odd:
                print(rep(v_odd, odd_key[1]))
            else:
                print(rep(v_odd,even_key[1]))

        else:
            print(odd_key[0])

Submission status: Runtime Error

Solution code:
# N個のスペース区切りの数値を取得
N = int(input())
A = [int(N) for N in input().split()]


# 奇数番目と偶数番目に出てくる数字の頻度順にそれぞれソートして、
odd = []
even = []

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

import collections
c_odd = collections.Counter(odd)
c_even = collections.Counter(even)
#print(c_odd.most_common()[0][0], c_even.most_common()[0][0])



# 最頻な数字が一致してない場合はそれぞれの最頻値以外の合計値、
if c_odd.most_common()[0][0] != c_even.most_common()[0][0] :
    print(len(set(odd))-1 + len(set(even))-1)
    exit()


# 一致してる場合は片方が最頻を諦めた場合の合計値を両パターン求めて小さい方
if c_odd.most_common()[0][0] == c_even.most_common()[0][0] :
    # 最頻を諦める ＝ 2番めに頻出な数値を採用
    temp_odd_retire = N//2 - c_odd.most_common()[1][1] #個数
    temp_even_retire = N//2 - c_even.most_common()[1][1] #個数
    #print('temps are ', temp_odd_retire, temp_even_retire)

    # oddを諦めたほうが良い場合
    if temp_odd_retire < temp_even_retire:
        print(temp_odd_retire + N//2 - c_even.most_common()[0][1])
    # even()
    else:
        print(temp_even_retire + N//2 - c_odd.most_common()[0][1])
    exit()

print('unexpected!')

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())

index = 0
even_numbers = []
odd_numbers = []

for i in input().split():
    if index % 2 == 0:
        even_numbers.append(int(i))
    else:
        odd_numbers.append(int(i))
    index += 1

even = Counter(even_numbers).most_common(2)
odd = Counter(odd_numbers).most_common(2)

if even[0][1] == odd[0][1]:
    print(min(N - even[0][1] - odd[1][1], N - even[1][1] - odd[0][1]))
else:
    print(N - even[0][1] - odd[0][1])

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
n = N // 2

index = 0
g_inputs = []
k_inputs = []

for i in input().split():
    if index % 2 == 0:
        g_inputs.append(int(i))
        index += 1
    else:
        k_inputs.append(int(i))
        index += 1

g = Counter(g_inputs)
k = Counter(k_inputs)

g_max = max([(v,k) for k,v in g.items()])[1] 
k_max = max([(v,k) for k,v in k.items()])[1]

if g_max == k_max:
    del g[g_max]
    del k[k_max]
    g_max_2 = max([(v,k) for k,v in g.items()])[1] 
    k_max_2 = max([(v,k) for k,v in k.items()])[1]
    print(min(N - g_max - k_max_2, N - g_max_2 - k_max))
else:
    print(N - g[g_max] - k[k_max])

Submission status: Runtime Error

Solution code:
from collections import Counter


def solve(V):
    n = len(V)
    odd = Counter(V[1::2])
    even = Counter(V[::2])

    even_max = even.most_common(2)
    odd_max = odd.most_common(2)

    if odd_max[0][0] != even_max[0][0]:
        return n - odd_max[0][0] - even_max[0][0]
    elif len(odd_max[0][0]) != 1 and len(even_max[0][0]) == 1:
        return n - odd_max[1][0] - even_max[0][1]
    elif len(odd_max[0][0]) == 1 and len(even_max[0][0]) != 1:
        return n - odd_max[0][1] - even_max[1][1]
    else:
        return n - max(even_max[0][1] + odd_max[1][1],
                       even_max[1][1] + odd_max[0][1])

if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int,input().split()))
a = [0 for i in range(n)]
b = a
a_i = 0
b_i = 0
for i in l:
  if i%2 == 0:
    a[i]+=1
    if(a[a_i]<=a[i]):
      a_i=i
  else:
    b[i]+=1
    if(b[b_i]<=b[i]):
      b_i=i
a.sort()
a.reverse()
b.sort()
b.reverse()
if a_i == b_i:
  print(n-a[0]-b[0])
else:
  print(n-max(a[0]+b[1],a[1]+b[0]))

Submission status: Runtime Error

Solution code:
N = int(input())
V = list(map(int,input().split()))
D1 = {}
D2 = {}
for i in range(N) :
    if i % 2 == 0:
        if V[i] in D1 :
            D1[V[i]] += 1
        else :
            D1[V[i]] = 1
    else :
        if V[i] in D2 :
            D2[V[i]] += 1
        else :
            D2[V[i]] = 1
m1 = max(D1.values())
m2 = max(D2.values())
if max(D1,key = D1.get) != max(D2,key = D2.get) :
    print(N-m1-m2)
else :
    D1[max(D1,key=D1.get)] = 0
    D2[max(D2,key=D1.get)] = 0
    mm1 = max(D1.values())
    mm2 = max(D2.values())
    if mm1 >= mm2 :
        print(N-m2-mm1)
    else :
        print(N-m1-mm2)

Submission status: Runtime Error

Solution code:
n = int(input())
A = [int(x) for x in input().split()]

from collections import Counter
import operator
def f():
    a, b = Counter(A[::2]), Counter(A[1::2])
    ac, bc = a[0][1], b[0][1]
    ret = n - (ac + bc)
    if a[0][0] == b[0][0]:
        bc_2 = b[1][1] if len(b) != 1 else 0
        ac_2 = a[1][1] if len(a) != 1 else 0
        ret = n - max(ac + bc_2, ac_2 + bc)
    return ret
print(f())

Submission status: Runtime Error

Solution code:
from collections import Counter


def solve(V):
    n = len(V)
    odd = Counter()
    even = Counter()
    total = Counter()
    for i, c in enumerate(V):
        total.update([c])
        if i % 2 == 0:
            even.update([c])
        else:
            odd.update([c])

    total_max = total.most_common()[0]
    if total_max[1] == len(V):
        return len(V) / 2

    even_maxs = even.most_common(2)
    odd_maxs = odd.most_common(2)
    if len(odd_maxs) > 1:
        odd_max, odd_2nd_max = odd_maxs[0], odd_maxs[1]
    else:
        odd_max, odd_2nd_max = odd_maxs[0], None

    if len(even_maxs) > 1:
        even_max, even_2nd_max = even_maxs[0], even_maxs[1]
    else:
        even_max, even_2nd_max = even_maxs[0], None

    ans = 0
    if odd_max[0] != even_max[0]:
        return n - odd_maxs[0][0] - even_maxs[0][0]
    elif odd_2nd_max != None and even_2nd_max == None:
        return n - odd_maxs[1][0] - even_maxs[0][1]
    elif odd_2nd_max == None and even_2nd_max != None:
        return n - odd_maxs[0][1] - even_maxs[1][1]
    else:  # odd_2nd_max != None and even_2nd_max != None:
        return n - max(even_maxs[0][1] + odd_maxs[1][1], 
                       even_maxs[1][1] + odd_maxs[0][1])

    for key, count in even.items():
        if key != even_max:
            ans += count
    for key, count in odd.items():
        if key != odd_max:
            ans += count
    return ans


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
from operator import itemgetter
def solve():
    input()
    V = list(map(int, input().split()))
    l = sorted(Counter(V[::2]).items()+[(0,0)], key=itemgetter(1), reverse=True)
    u = sorted(Counter(V[1::2]).items()+[(0,0)], key=itemgetter(1), reverse=True)
    res = sum(map(itemgetter(1), l+u)) - (max(l[0][1]+u[1][1], l[1][1]+u[0][1]) if l[0][0]==u[0][0] else (l[0][1]+u[0][1]))
    return str(res)

if __name__ == '__main__':
    print(solve())

Submission status: Runtime Error

Solution code:
import collections
 
n = int(input())
v = [int(i) for i in input().split()]
 
v1 = [v[i] for i in range(0,n,2)]
v2 = [v[i] for i in range(1,n,2)]
 
count1 = collections.Counter(v1).most_common(2)
count2 = collections.Counter(v2).most_common(2)

if count1[0][0] != count2[0][0]:
    res = len(v1) - max(count1.values()) + len(v2) - max(count2.values())
    print(res)
else:
    if len(count1) == 1:
        print(len(v1))
    else:
        res1 = len(v1) - count1[0][1] + len(v2) - count2[1][1]
        res2 = len(v1) - count1[1][1] + len(v2) - count2[0][1]
        print(min(res1,res2))

Submission status: Runtime Error

Solution code:
import collections
 
n = int(input())
v = [int(i) for i in input().split()]
 
v1 = [v[i] for i in range(0,n,2)]
v2 = [v[i] for i in range(1,n,2)]
 
count1 = collections.Counter(v1).most_common(2)
count2 = collections.Counter(v2).most_common(2)

if max(count1.values()) != max(count2.values()):
    res = len(v1) - max(count1.values()) + len(v2) - max(count2.values())
    print(res)
else:
    if len(count1) == 1:
        print(len(v1))
    else:
        res1 = len(v1) - count1[0][1] + len(v2) - count2[1][1]
        res2 = len(v1) - count1[1][1] + len(v2) - count2[0][1]
        print(min(res1,res2))

Submission status: Runtime Error

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+100)]
cc = [0 for i in range(pow(10,5)+100)]
for i in range(len(b)):
    if i % 2 == 0:
        cc[b[i]-1] += 1
    else:
        c[b[i]-1] += 1

one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(len(c)+10):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i

t = max(one+twoo,onee+two)

if k != kk:
    print(a-one-two)
else:
    print(a-t)

Submission status: Runtime Error

Solution code:
from collections import Counter
    
n = int(input())
v = list(map(int, input().split()))
odd = v[::2]
even = v[1::2]
    
c_even = Counter(even).most_common(2)
c_odd = Counter(odd).most_common(2)

# print(c_even, c_odd)
    
if(c_even[0][0] != c_odd[0][0]):
    print(n - c_even[0][1] - c_odd[0][1])
elif(len(c_even) >= 2):
    second = max[c_even[1][1], c_odd[1][1]]
    print(n - c_even[0][1] - second)
else:
    print(n//2)

Submission status: Runtime Error

Solution code:
from collections import Counter
    
n = int(input())
v = list(map(int, input().split()))
odd = v[::2]
even = v[1::2]
    
c_even = Counter(even).most_common(2)
c_odd = Counter(odd).most_common(2)

print(c_even, c_odd)
    
if(c_even[0][0] != c_odd[0][0]):
    print(n - c_even[0][1] - c_odd[0][1])
elif(len(c_even) >= 2 and len(c_odd) >= 2):
    second = max[c_even[1][1], c_odd[1][1]]
    print(n - c_even[0][1] - second)
else:
    print(n//2)

Submission status: Runtime Error

Solution code:
n = int(input())
v_odd = {}
v_even = {}
vlist = list(map(int, input().split()))
for i in range(n):
    if i % 2 == 1:
        if vlist[i] in v_odd:
            v_odd[vlist[i]] += 1
        else:
            v_odd[vlist[i]] = 1
    else:
        if i in v_even:
            v_even[vlist[i]] += 1
        else:
            v_even[vlist[i]] = 1
omax = max(v_odd, key=(lambda x: v_odd[x]))
emax = max(v_even, key=(lambda x: v_even[x]))
if omax != emax:
    orewrite = sum(v_odd[i] for i in v_odd) - v_odd[omax]
    erewrite = sum(v_even[i] for i in v_even) - v_even[emax]
    ans = orewrite + erewrite
    print(ans)
else:
    lo = len(v_odd)
    le = len(v_even)
    if lo == 1 and le == 1:
        print(v_odd[omax])
    elif lo != 1 and le == 1:
        osum = sum(v_odd[i] for i in v_odd)
        ofirmax = v_odd[omax]
        v_odd[omax] = 0
        osecmax = max(v_odd, key=(lambda x: v_odd[x]))
        ans = osum - osecmax + sum(v_even[i] for i in v_even) + ofirmax - v_even[emax]
        print(ans)
    elif lo ==1 and le != 1:
        esum = sum(v_even[i] for i in v_even)
        efirmax = v_even[emax]
        v_even[emax] = 0
        esecmax = max(v_even, key=(lambda x: v_even[x]))
        ans = esum - esecmax + sum(v_odd[i] for i in v_odd) + efirmax- v_odd[omax]
        ans = esum - esecmax + sum(v_odd[i] for i in v_odd) - v_odd[omax]
        print(ans)
    else:
        def o2():
            osum = sum(v_odd[i] for i in v_odd)
            ofirmax = v_odd[omax]
            v_odd[omax] = 0
            osecmax = max(v_odd, key=(lambda x: v_odd[x]))
            ans = osum - osecmax + sum(v_even[i] for i in v_even) + ofirmax - v_even[emax]
            return ans
        def e2():
            esum = sum(v_even[i] for i in v_even)
            efirmax = v_even[emax]
            v_even[emax] = 0
            esecmax = max(v_even, key=(lambda x: v_even[x]))
            ans = esum - esecmax + sum(v_odd[i] for i in v_odd) + efirmax- v_odd[omax]
            return ans
        print(min(o2(), e2()))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
gu = v[::2]
ki = v[1::2]
ans = 0
k,g = False,False

###全部同じなら全長の半分,
# 最頻値が同じなら2番目を比べる
if v.count(v[0]) == n
    ans += n // 2
else:
    kic = Counter(ki)
    guc = Counter(gu)
    k1 = kic.most_common(2)
    g1 = guc.most_common(2)
    if k1[0][0] == g1[0][0]:
        if k1[1][1] < g1[1][1]:
            g = True
        else:
            k = True

    kic = list(kic.values())
    guc = list(guc.values())
    kic.sort(reverse = True)
    guc.sort(reverse = True)
    if len(kic) != 1:
        if k:
            ans += kic[0]
            ans += sum(kic[2::])
        else:
            ans += sum(kic[1::]) 
    if len(guc) != 1:
        if g:
            ans += guc[0]
            ans += sum(guc[2::])
        else:
            ans += sum(guc[1::])

print(ans)

Submission status: Runtime Error

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+1)]
cc = [0 for i in range(pow(10,5)+1)]
for i in range(len(b)):
    if i % 2 == 0:
        c[b[i]-1] += 1
    else:
        cc[b[i]-1] += 1

one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(d+1):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i

t = max(one+twoo,onee+twso)

if k != kk:
    print(a-one-two)
else:
    print(a-t)