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())
a = input().split( )

ret = [0]

odds = []
evens = []
for i in range(N):
    if i % 2 == 0:
        odds.append(int(a[i]))
    else:
        evens.append(int(a[i]))

codds = collections.Counter(odds)
cevens = collections.Counter(evens)

if codds.most_common()[0][0] ==cevens.most_common()[0][0]:
    if codds.most_common()[0][1] > cevens.most_common()[0][1]:
        codds = list(codds.values())
        cevens = list(cevens.values())
        if len(codds) > 1:
            codds=sorted(codds)
            codds.pop(-1)
        else:
            codds = [0]
        if len(cevens) > 1:
            cevens = sorted(cevens)
            cevens.pop(-2)
    else:
        codds = list(codds.values())
        cevens = list(cevens.values())
        if len(codds) > 1:
            codds=sorted(codds)
            codds.pop(-2)
        if len(cevens) > 1:
            cevens = sorted(cevens)
            cevens.pop(-1)
        else:
            cevens = [0]
else:
    codds = list(codds.values())
    cevens = list(cevens.values())
    if len(codds) > 1:
        codds=sorted(codds)
        codds.pop(-1)
    if len(cevens) > 1:
        cevens = sorted(cevens)
        cevens.pop(-1)

print(sum(codds) + sum(cevens))

import collections
N = int(input())
a = input().split( )

ret = [0]

odds = []
evens = []
for i in range(N):
    if i % 2 == 0:
        evens.append(int(a[i]))
    else:
        odds.append(int(a[i]))

codds = collections.Counter(odds)
cevens = collections.Counter(evens)

if codds.most_common()[0][0] ==cevens.most_common()[0][0]:
    if codds.most_common()[0][1] > cevens.most_common()[0][1]:
        codds = list(codds.values())
        cevens = list(cevens.values())
        if len(codds) > 1:
            codds=sorted(codds)
            codds=codds[1:]
        else:
            codds = [0]
        if len(cevens) > 1:
            cevens = sorted(cevens)
            evens = evens.pop(1)
    else:
        codds = list(codds.values())
        cevens = list(cevens.values())
        if len(codds) > 1:
            codds=sorted(codds)
            codds.pop(1)
        if len(cevens) > 1:
            cevens = sorted(cevens)
            cevens = cevens[1:]
        else:
            cevens = [0]
else:
    codds = list(codds.values())
    cevens = list(cevens.values())
    if len(codds) > 1:
        codds=sorted(codds)
        codds=codds[1:]
    if len(cevens) > 1:
        cevens = sorted(cevens)
        cevens = cevens[1:]

print(sum(codds) + sum(cevens))

import collections
N = int(input())
a = input().split( )

ret = [0]

odds = []
evens = []
for i in range(N):
    if i % 2 == 0:
        odds.append(int(a[i]))
    else:
        evens.append(int(a[i]))

codds = collections.Counter(odds)
cevens = collections.Counter(evens)
print(codds)
print(cevens)

if codds.most_common()[0][0] ==cevens.most_common()[0][0]:
    if codds.most_common()[0][1] > cevens.most_common()[0][1]:
        codds = list(codds.values())
        cevens = list(cevens.values())
        if len(codds) > 1:
            codds=sorted(codds)
            codds.pop(-1)
        else:
            codds = [0]
        print(1)
        if len(cevens) > 1:
            print(3)
            cevens = sorted(cevens)
            cevens.pop(-2)
    else:
        codds = list(codds.values())
        cevens = list(cevens.values())
        if len(codds) > 1:
            codds=sorted(codds)
            codds.pop(-2)
        if len(cevens) > 1:
            cevens = sorted(cevens)
            cevens.pop(-1)
        else:
            cevens = [0]
else:
    codds = list(codds.values())
    cevens = list(cevens.values())
    if len(codds) > 1:
        codds=sorted(codds)
        codds.pop(-1)
    if len(cevens) > 1:
        cevens = sorted(cevens)
        cevens.pop(-1)

print(sum(codds) + sum(cevens))

import collections
N = int(input())
a = input().split( )

ret = [0]

odds = []
evens = []
for i in range(N):
    if i % 2 == 0:
        odds.append(int(a[i]))
    else:
        evens.append(int(a[i]))

codds = collections.Counter(odds)
cevens = collections.Counter(evens)

if codds.most_common()[0][0] ==cevens.most_common()[0][0]:
    if codds.most_common()[0][1] > cevens.most_common()[0][1]:
        codds = sorted(list(codds.values()))
        cevens = sorted(list(cevens.values()))
        if len(codds) > 1:
            codds.pop(-1)
        else:
            codds = [0]
        if len(cevens) > 1:
            cevens.pop(-2)
    elif codds.most_common()[0][1] < cevens.most_common()[0][1]:
        codds = sorted(list(codds.values()))
        cevens = sorted(list(cevens.values()))
        if len(codds) > 1:
            codds.pop(-2)
        if len(cevens) > 1:
            cevens.pop(-1)
        else:
            cevens = [0]
    else:
        if len(codds) == 1 and len(cevens) == 1:
            codds = [0]
            cevens = sorted(list(cevens.values()))
        elif codds.most_common()[1][1] > cevens.most_common()[1][1]:
            codds = sorted(list(codds.values()))
            cevens = sorted(list(cevens.values()))
            codds.pop(-2)
            cevens.pop(-1)
        else:
            codds = sorted(list(codds.values()))
            cevens = sorted(list(cevens.values()))
            codds.pop(-1)
            cevens.pop(-2)

else:
    codds = sorted(list(codds.values()))
    cevens = sorted(list(cevens.values()))
    if len(codds) > 1:
        codds.pop(-1)
    else:
        codds= [0]
    if len(cevens) > 1:
        cevens.pop(-1)
    else:
        cevens = [0]

print(sum(codds) + sum(cevens))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted