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, = map(int, input().split())
v_even, v_odd = [v[i] for i in range(n) if i % 2 == 0], [v[i] for i in range(n) if i % 2 != 0]

counter_even = collections.Counter(v_even)
counter_odd = collections.Counter(v_odd)

count_even = sorted(counter_even.items(), key=lambda x:x[1], reverse=True)
print(count_even)
count_odd = sorted(counter_odd.items(), key=lambda x:x[1], reverse=True)
print(count_odd)

if len(counter_even) == 1 and len(counter_odd) == 1:
    if count_even[0][0] != count_odd[0][0]:
        ans = 0
    else:
        ans1 = 0
        for i in range(n // 2):
            if v_even[i] != count_even[1][0]:
                v_even[i] = count_even[1][0]
                ans1 += 1
            
            if v_odd[i] != count_odd[0][0]:
                v_odd[i] = count_odd[0][0]
                ans1 += 1
    
        ans2 = 0
        for i in range(n // 2):
            if v_even[i] != count_even[0][0]:
                v_even[i] = count_even[0][0]
                ans2 += 1
            
            if v_odd[i] != count_odd[1][0]:
                v_odd[i] = count_odd[1][0]
                ans2 += 1
                
        ans = min(ans1, ans2)

else:
    ans = 0 
    for i in range(n // 2):
        if v_even[i] != count_even[0][0]:
            v_even[i] = count_even[0][0]
            ans += 1
        
        if v_odd[i] != count_odd[0][0]:
            v_odd[i] = count_odd[0][0]
            ans += 1

print(ans)

import collections
n = int(input())
*v, = map(int, input().split())
v_even, v_odd = [v[i] for i in range(n) if i % 2 == 0], [v[i] for i in range(n) if i % 2 != 0]

counter_even = collections.Counter(v_even)
counter_odd = collections.Counter(v_odd)

max_count_even = max(counter_even.items(), key=lambda x:x[1])
#print(max_count_even[0])
max_count_odd = max(counter_odd.items(), key=lambda x:x[1])
#print(max_count_odd[0])
ans = 0
for i in range(n // 2):
    if v_even[i] != max_count_even[0]:
        v_even[i] = max_count_even[0]
        ans += 1
        
    if v_odd[i] != max_count_odd[0]:
        v_odd[i] = max_count_odd[0]
        ans += 1
        
if len(counter_even) == 1 and len(max_count_odd):
    ans = n // 2

print(ans)

from collections import Counter
n = int(input())
*v, = map(int, input().split())
v_even, v_odd = v[::2], v[1::2]
even = Counter(v_even).most_common(2)
odd = Counter(v_odd).most_common(2)

ans = 0

if even[0][0] != odd[0][0]:
    ans = n - odd[0][1] - even[0][1]

else:
    if len(even) == 1 and len(odd) == 1:
        ans = n // 2
        
    elif len(even) == 1:
        ans = n - even[0][1] - odd[1][1]
        
    elif len(odd) == 1:
        ans = n - even[1][1] - odd[0][1]
        
    else:
        ans = min(n - even[0][1] - odd[1][1], 
                  n - even[1][1] - odd[0][1])
                  
print(ans)

Verdicts: Runtime Error

Wrong Answer

Accepted