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())
odd = []
even = []
for i, j in enumerate(map(int, input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(), reverse=True, key=lambda x: x[1])
even = sorted(collections.Counter(even).items(), reverse=True, key=lambda x: x[1])

if len(odd) == 1 and len(even) == 1 and odd[0][0] == even[0][0]:
    print(n // 2)
elif odd[0][0] == even[0][0]:
    if odd[0][1] == even[0][1]:
        for i in range(n//2):
            if odd[i][1] == even[i][1]:
                continue
            elif odd[i][1] > even[i][1]:
                print((n // 2 - odd[0][1]) + (n // 2 - even[1][1]))
            elif odd[i][1] < even[i][1]:
                print((n // 2 - odd[1][1]) + (n // 2 - even[0][1]))
        else:
            print((n // 2 - odd[0][1]) + (n // 2 - even[1][1]))
    elif odd[0][1] > even[0][1]:
        print((n // 2 - odd[0][1]) + (n // 2 - even[1][1]))
    elif odd[0][1] < even[0][1]
        print((n // 2 - odd[1][1]) + (n // 2 - even[0][1]))
else:
    print((n // 2 - odd[0][1]) + (n // 2 - even[0][1]))


import collections


n = int(input())
odd = []
even = []
for i,j in enumerate(map(int,input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(),key=lambda x:(x[1]),reverse=True)
even = sorted(collections.Counter(even).items(),key=lambda x:(x[1]),reverse=True)

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

import collections


n = int(input())
odd = []
even = []
for i,j in enumerate(map(int,input().split())):
    if i % 2 == 0:
        even += [j]
    else:
        odd += [j]
odd = sorted(collections.Counter(odd).items(),key=lambda x:(x[1]),reverse=True)
even = sorted(collections.Counter(even).items(),key=lambda x:(x[1]),reverse=True)

if len(odd) == 1 and len(even) == 1:
    if odd[0][0] == even[0][0]:
        print(n//2)
        exit()
    else:
        print(0)
        exit()

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

Verdicts: Runtime Error

Runtime Error

Accepted