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):
n = int(input())
v = list(map(int, input().split()))

odd = {}
even = {}

for i in range(len(v)):
    if i % 2 == 1:
        if v[i] in odd:
            odd[v[i]] += 1
        else:
            odd[v[i]] = 1
    else:
        if v[i] in even:
            even[v[i]] += 1
        else:
            even[v[i]] = 1


odd_sorted  = sorted(odd.items(), key = lambda x : -x[1])
even_sorted  = sorted(even.items(), key = lambda x : -x[1])





if odd_sorted[0][0] == even_sorted[0][0]:
    
    if len(odd.keys()) > 1 and len(even.keys()) > 1:
        
        if odd_sorted[0][1] > even_sorted[0][1]:
            ans_odd = odd_sorted[0][0]
            ans_even = even_sorted[1][0]
        elif odd_sorted[0][1] < even_sorted[0][1]:
            ans_odd = odd_sorted[1][0]
            ans_even = even_sorted[0][0]
        else:
            
            if odd_sorted[1][1] >= even_sorted[1][1]:
                ans_odd = odd_sorted[1][0]
                ans_even = even_sorted[0][0]
            elif odd_sorted[1][1] < even_sorted[1][1]:
                ans_odd = odd_sorted[0][0]
                ans_even = even_sorted[1][0]

    
    elif len(odd.keys()) == 1 and len(even.keys()) == 1:
        ans_odd = -1
        ans_even = even_sorted[0][0]
    
    elif len(odd.keys()):
        ans_odd = odd_sorted[0][0]
        ans_even = even_sorted[1][0]
    
    else: 
        ans_odd = odd_sorted[1][0]
        ans_even = even_sorted[0][0]

else:
    ans_odd = odd_sorted[0][0]
    ans_even = even_sorted[0][0]

ans = 0
for i in range(len(v)):
    if i % 2:
        if v[i] != ans_odd:
            ans += 1
    else:
        if v[i] != ans_even:
            ans += 1


print(odd_sorted)
print(even_sorted)

print(ans_odd, ans_even)
print(ans)

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

odd = {}
even = {}

for i in range(len(v)):
    if i % 2 == 1:
        if v[i] in odd:
            odd[v[i]] += 1
        else:
            odd[v[i]] = 1
    else:
        if v[i] in even:
            even[v[i]] += 1
        else:
            even[v[i]] = 1


odd_sorted  = sorted(odd.items(), reversed = True, key = lambda x : x[1])
even_sorted  = sorted(even.items(), reversed = True, key = lambda x : x[1])





if odd_sorted[0][0] == even_sorted[0][0]:
    
    if len(odd.keys()) > 1 and len(even.keys()) > 1:
        
        if odd_sorted[0][1] >= even_sorted[0][1]:
            ans_odd = odd_sorted[0][0]
            ans_even = even_sorted[1][0]
        else:
            ans_odd = odd_sorted[1][0]
            ans_even = even_sorted[0][0]
    
    elif len(odd.keys()) == 1 and len(even.keys()) == 1:
        ans_odd = -1
        ans_even = even_sorted[0][0]
    
    elif len(odd.keys()):
        ans_odd = odd_sorted[0][0]
        ans_even = even_sorted[1][0]
    
    else: 
        ans_odd = odd_sorted[1][0]
        ans_even = even_sorted[0][0]

else:
    ans_odd = odd_sorted[0][0]
    ans_even = even_sorted[0][0]

ans = 0
for i in range(len(v)):
    if i % 2:
        if v[i] != ans_odd:
            ans += 1
    else:
        if v[i] != ans_even:
            ans += 1


print(ans)

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

odd = {}
even = {}

for i in range(len(v)):
    if i % 2 == 1:
        if v[i] in odd:
            odd[v[i]] += 1
        else:
            odd[v[i]] = 1
    else:
        if v[i] in even:
            even[v[i]] += 1
        else:
            even[v[i]] = 1


odd_sorted  = sorted(odd.items(), key = lambda x : -x[1])
even_sorted  = sorted(even.items(), key = lambda x : -x[1])





if odd_sorted[0][0] == even_sorted[0][0]:
    
    if len(odd.keys()) > 1 and len(even.keys()) > 1:
        
        if odd_sorted[0][1] > even_sorted[0][1]:
            ans_odd = odd_sorted[0][0]
            ans_even = even_sorted[1][0]
        elif odd_sorted[0][1] < even_sorted[0][1]:
            ans_odd = odd_sorted[1][0]
            ans_even = even_sorted[0][0]
        else:
            
            if odd_sorted[1][1] >= even_sorted[1][1]:
                ans_odd = odd_sorted[1][0]
                ans_even = even_sorted[0][0]
            elif odd_sorted[1][1] < even_sorted[1][1]:
                ans_odd = odd_sorted[0][0]
                ans_even = even_sorted[1][0]

    
    elif len(odd.keys()) == 1 and len(even.keys()) == 1:
        ans_odd = -1
        ans_even = even_sorted[0][0]
    
    elif len(odd.keys()):
        ans_odd = odd_sorted[0][0]
        ans_even = even_sorted[1][0]
    
    else: 
        ans_odd = odd_sorted[1][0]
        ans_even = even_sorted[0][0]

else:
    ans_odd = odd_sorted[0][0]
    ans_even = even_sorted[0][0]

ans = 0
for i in range(len(v)):
    if i % 2:
        if v[i] != ans_odd:
            ans += 1
    else:
        if v[i] != ans_even:
            ans += 1


print(ans)

Verdicts: Wrong Answer

Runtime Error

Accepted