Problem: 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.

Submission attempts (in order):
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))

import collections

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

even_odd_length = len(v) / 2
replace_total = 0

if len(set(v)) == 1:
    print(2)
else:
    c_even = collections.Counter(v[0::2])
    c_odd = collections.Counter(v[1::2])
    replace_total += even_odd_length - list(c_even.values())[0]
    replace_total += even_odd_length - list(c_odd.values())[0]
    print(replace_total)

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))
dict_c_even_bk = dict_c_even.copy()

replace_total_tmp = 0
replace_total_tmp2 = 0

max_count_c_odd = max(dict_c_odd.values())
max_count_c_even = max(dict_c_even.values())
max_count_c_even_bk = max_count_c_even

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 len(set(v)) == 1:
    print(int(even_odd_length))
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_tmp = (n - max_count_c_odd - max_count_c_even)
    
    dict_c_even = dict_c_even_bk
    max_count_c_even = max_count_c_even_bk
    
    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())
    replace_total_tmp2 = (n - max_count_c_odd - max_count_c_even)
    
    if replace_total_tmp >= replace_total_tmp2:
         replace_total = replace_total_tmp2
    else:
         replace_total = replace_total_tmp

    print(replace_total)

Verdicts: Runtime Error

Wrong Answer

Accepted