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 = input()
nums = list(map(int, input().split()))
odd = nums[0::2]
even = nums[1::2]
odd_c = collections.Counter(odd)
even_c = collections.Counter(even)


if odd_c.most_common(1)[0][0] == even_c.most_common(1)[0][0]:
    if len(odd_c) >= 3 and len(even_c) >= 3:
        odd_first_count = len(odd) - odd_c.most_common(1)[0][1]
        even_first_count = len(even) - even_c.most_common(1)[0][1]
        odd_second_count = len(odd) - odd_c.most_common(2)[1][1]
        even_second_count = len(even) - even_c.most_common(2)[1][1]
        if odd_first_count + even_second_count > odd_second_count + even_first_count:
            print(odd_first_count + even_second_count)
            exit()
        else:
            print(odd_second_count + even_first_count)
            exit()
    odd_next_most = 0
    even_next_most = 0
    if len(odd_c) >= 2:
        odd_next_most = odd_c.most_common(2)[1][1]
    if len(even_c) >= 2:
        even_next_most = even_c.most_common(2)[1][1]
    if odd_next_most > even_next_most:
        print(len(odd) - odd_next_most + len(even) - even_c.most_common(1)[0][1])
    else:
        print(len(odd) - odd_c.most_common(1)[0][1] + len(even) - even_next_most)
else:
    print("else")
    odd_change = len(odd) - odd_c.most_common(1)[0][1]
    even_change = len(even) - even_c.most_common(1)[0][1]
    print(odd_change + even_change)


import collections

n = input()
nums = list(map(int, input().split()))
odd = nums[0::2]
even = nums[1::2]
odd_c = collections.Counter(odd)
even_c = collections.Counter(even)
print(odd_c)
print(even_c)
if odd_c.most_common(1)[0][0] == even_c.most_common(1)[0][0]:
    odd_next_most = 0
    even_next_most = 0
    if len(odd_c) >= 2:
        odd_next_most = odd_c.most_common(2)[1][1]
    if len(even_c) >= 2:
        even_next_most = even_c.most_common(2)[1][1]
    if odd_next_most > even_next_most:
        print(len(odd) - odd_next_most)
    else:
        print(len(even) - even_next_most)
else:
    odd_change = len(odd) - odd_c.most_common(1)[0][1]
    even_change = len(even) - even_c.most_common(1)[0][1]
    if odd_change + even_change == 0:
        if odd_c.most_common(1)[0][0] == even_c.most_common(1)[0][0]:
            print(len(even))
            exit()
    print(odd_change + even_change)


import collections

n = input()
nums = list(map(int, input().split()))
odd = nums[0::2]
even = nums[1::2]
odd_c = collections.Counter(odd)
even_c = collections.Counter(even)


if odd_c.most_common(1)[0][0] == even_c.most_common(1)[0][0]:
    if len(odd_c) >= 3 and len(even_c) >= 3:
        odd_first_count = len(odd) - odd_c.most_common(1)[0][1]
        even_first_count = len(even) - even_c.most_common(1)[0][1]
        odd_second_count = len(odd) - odd_c.most_common(2)[1][1]
        even_second_count = len(even) - even_c.most_common(2)[1][1]
        if odd_first_count + even_second_count < odd_second_count + even_first_count:
            print(odd_first_count + even_second_count)
            exit()
        else:
            print(odd_second_count + even_first_count)
            exit()
    odd_next_most = 0
    even_next_most = 0
    if len(odd_c) >= 2:
        odd_next_most = odd_c.most_common(2)[1][1]
    if len(even_c) >= 2:
        even_next_most = even_c.most_common(2)[1][1]
    if odd_next_most > even_next_most:
        print(len(odd) - odd_next_most + len(even) - even_c.most_common(1)[0][1])
    else:
        print(len(odd) - odd_c.most_common(1)[0][1] + len(even) - even_next_most)
else:
    print("else")
    odd_change = len(odd) - odd_c.most_common(1)[0][1]
    even_change = len(even) - even_c.most_common(1)[0][1]
    print(odd_change + even_change)


import collections

n = input()
nums = list(map(int, input().split()))
odd = nums[0::2]
even = nums[1::2]
odd_c = collections.Counter(odd)
even_c = collections.Counter(even)


if odd_c.most_common(1)[0][0] == even_c.most_common(1)[0][0]:
    if len(odd_c) >= 3 and len(even_c) >= 3:
        odd_first_count = len(odd) - odd_c.most_common(1)[0][1]
        even_first_count = len(even) - even_c.most_common(1)[0][1]
        odd_second_count = len(odd) - odd_c.most_common(2)[1][1]
        even_second_count = len(even) - even_c.most_common(2)[1][1]
        if odd_first_count + even_second_count < odd_second_count + even_first_count:
            print(odd_first_count + even_second_count)
            exit()
        else:
            print(odd_second_count + even_first_count)
            exit()
    odd_next_most = 0
    even_next_most = 0
    if len(odd_c) >= 2:
        odd_next_most = odd_c.most_common(2)[1][1]
    if len(even_c) >= 2:
        even_next_most = even_c.most_common(2)[1][1]
    if odd_next_most > even_next_most:
        print(len(odd) - odd_next_most + len(even) - even_c.most_common(1)[0][1])
    else:
        print(len(odd) - odd_c.most_common(1)[0][1] + len(even) - even_next_most)
else:
    odd_change = len(odd) - odd_c.most_common(1)[0][1]
    even_change = len(even) - even_c.most_common(1)[0][1]
    print(odd_change + even_change)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted