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):
# 2019/05/15


from operator import itemgetter

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

l_even = list()
l_odd = list()

# Separate Odd or Even
for i in range(n):
    if i % 2 == 0:
        l_even.append(v[i])
    else:
        l_odd.append(v[i])

l_even.sort()
l_odd.sort()
wk_cnt_e = 1
wk_cnt_o = 1

cnt_even = list()
cnt_odd = list()

# Count
for x in range(int(n/2)-1):
    if l_even[x] != l_even[x+1]:
        cnt_even.append([l_even[x], wk_cnt_e])
        wk_cnt_e = 1
    else:
        wk_cnt_e += 1

    if l_odd[x] != l_odd[x+1]:
        cnt_odd.append([l_odd[x], wk_cnt_o])
        wk_cnt_o = 1
    else:
        wk_cnt_o += 1

cnt_even.append([l_even[x+1], wk_cnt_e])
cnt_odd.append([l_odd[x+1], wk_cnt_o])

cnt_even.sort(key=itemgetter(1))
cnt_odd.sort(key=itemgetter(1))

if len(cnt_even) == 1 and len(cnt_odd) == 1 and cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2
elif len(cnt_even) == 1 and cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2 - cnt_odd[0][1]
elif len(cnt_odd) == 1 and cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2 - cnt_even[0][1]
elif cnt_even[0][0] == cnt_odd[0][0]:
    ans = n / 2 - min(cnt_even[0][1], cnt_odd[0][1])
else:
    ans = (n / 2 - cnt_even[0][1]) + (n / 2 - cnt_odd[0][1])
 
print(cnt_even, cnt_odd)
# Output
print(int(ans))


# 2019/05/15


from operator import itemgetter

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

l_even = list()
l_odd = list()

# Separate Odd or Even
for i in range(n):
    if i % 2 == 0:
        l_even.append(v[i])
    else:
        l_odd.append(v[i])

l_even.sort()
l_odd.sort()
wk_cnt_e = 1
wk_cnt_o = 1

cnt_even = list()
cnt_odd = list()

# Count
for x in range(int(n/2)-1):
    if l_even[x] != l_even[x+1]:
        cnt_even.append([l_even[x], wk_cnt_e])
        wk_cnt_e = 1
    else:
        wk_cnt_e += 1

    if l_odd[x] != l_odd[x+1]:
        cnt_odd.append([l_odd[x], wk_cnt_o])
        wk_cnt_o = 1
    else:
        wk_cnt_o += 1

cnt_even.append([l_even[x+1], wk_cnt_e])
cnt_odd.append([l_odd[x+1], wk_cnt_o])

cnt_even.sort(key=itemgetter(1),reverse=True)
cnt_odd.sort(key=itemgetter(1),reverse=True)

# Max is same
if cnt_even[0][0] == cnt_odd[0][0]:
    if len(cnt_even) == 1 and len(cnt_odd) == 1:
        ans = n / 2
    elif len(cnt_even) == 1:
        ans = n / 2 - cnt_odd[1][1]
    elif len(cnt_odd) == 1:
        ans = n / 2 - cnt_even[1][1]
    else:
        ans = min((n / 2 - cnt_even[0][1]) + (n / 2 - cnt_odd[1][1]),
                (n / 2 - cnt_even[1][1]) + (n / 2 - cnt_odd[0][1]))
# Max is Not same
else:
    if len(cnt_even) == 1 and len(cnt_odd) == 1:
        ans = 0
    elif len(cnt_even) == 1:
        ans = n / 2 - cnt_odd[0][1]
    elif len(cnt_odd) == 1:
        ans = n / 2 - cnt_even[0][1]
    else:
        ans = (n / 2 - cnt_even[0][1]) + (n / 2 - cnt_odd[0][1])

# Output
print(int(ans))


Verdicts: Wrong Answer

Accepted