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())
list = [int(i) for i in input().split()]

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)


if cnt_odd[0][1] == cnt_even[0][1]:
    
    if len(cnt_odd) or len(cnt_even) == 1:
        ans =  n //2
    
    else:
        
        if cnt_odd[1][0] > cnt_even[1][0]:
            ans = n - cnt_odd[1][0] - cnt_even[0][0]
        
        elif cnt_odd[1][0] < cnt_even[1][0]:
            ans = n - cnt_odd[0][0] - cnt_even[1][0]

else:
    ans = n - cnt_odd[0][0] - cnt_even[0][1]

print(ans)

n = int(input())
list = [int(i) for i in input().split()]

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)


if cnt_odd[0][1] == cnt_even[0][1]:
    
    if len(cnt_odd) or len(cnt_even) == 1:
        ans =  int(n / 2)
    
    else:
        
        if cnt_odd[1][0] > cnt_even[1][0]:
            ans = n - cnt_odd[1][0] - cnt_even[0][0]
        
        elif cnt_odd[1][0] < cnt_even[1][0]:
            ans = n - cnt_odd[0][0] - cnt_even[1][0]

else:
    ans = n - cnt_odd[0][0] - cnt_even[0][1]

print(ans)

n = int(input())
list = [int(i) for i in input().split()]

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)
print(cnt_odd)
print(cnt_even)

if len(cnt_odd) == len(cnt_even) == 1
    if cnt_even[0][1] != cnt_odd[0][1]:
        ans = 0
    elif cnt_even[0][1] == cnt_odd[0][1]:
        ans = int(n / 2)
elif cnt_even[0][1] != cnt_odd[0][1]:
    ans = n - cnt_odd[0][0] - cnt_even[0][0]

print(ans)

n = int(input())
list = [int(i) for i in input().split()]

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)


if cnt_odd[0][1] == cnt_even[0][1]:
    
    if len(cnt_odd) == len(cnt_even) == 1:
        ans = 1
    
    else:
        
        if cnt_odd[1][0] > cnt_even[1][0]:
            ans = n - cnt_odd[1][0] - cnt_even[0][0]
        
        elif cnt_odd[1][0] < cnt_even[1][0]:
            ans = n - cnt_odd[0][0] - cnt_even[1][0]

else:
    ans = n - cnt_odd[0][0] - cnt_even[0][1]

print(ans)

n = int(input())
list = [int(i) for i in input().split()]

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)


if cnt_odd[0][1] == cnt_even[0][1]:
    
    if len(cnt_odd) or len(cnt_even) == 1:
        ans =  n / 2
    
    else:
        
        if cnt_odd[1][0] > cnt_even[1][0]:
            ans = n - cnt_odd[1][0] - cnt_even[0][0]
        
        elif cnt_odd[1][0] < cnt_even[1][0]:
            ans = n - cnt_odd[0][0] - cnt_even[1][0]

else:
    ans = n - cnt_odd[0][0] - cnt_even[0][1]

print(ans)

from collections import Counter

n = int(input())
v = [int(i) for i in input().split()]

ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

print(ki)
print(gu)

ans = 0

if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)
    else:
        if ki[1][1] > gu[1][1]:
            ans = n - ki[1][1] - gu[0][1]
        else:
            ans = n - ki[0][1] - gu[1][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print(ans)



from collections import Counter
n = int(input())
list = list(map(int,input().split()))
list_o = list[::2]
list_e = list[1::2]

cnt_o = Counter(list_e).most_common(2)
cnt_e = Counter(list_o).most_common(2)

if cnt_o[0][0] == cnt_e[0][0]:
    if len(cnt_o) == 1 and len(cnt_e) == 1:
        print(int(n/2))
    else:
        print(n-cnt_o[0][1]-max(cnt_o[1][1],cnt_e[1][1]))
else:
    print(n-cnt_o[0][1]-cnt_e[0][1])

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Accepted