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):
from collections import Counter

n = int(input())

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

odds = []
evens = []

for i in range(n):
    if i % 2 == 0:
        evens.append(v[i])
    else:
        odds.append(v[i])

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()

ans = 0

fl = 0
for i in range(len(evens_c)):
    for j in range(len(odds_c)):
        fl = 0
        try:
            if evens_c[i][0] != odds_c[j][0]:
                ans = min(ans, n - evens_c[i][1] - odds_c[j][1])
                fl = 1
        except:
            continue

if fl == 1:
    print(ans)
    exit()
print(n // 2)


from collections import Counter

n = int(input())

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

odds = []
evens = []

for i in range(n):
    if i % 2 == 0:
        evens.append(v[i])
    else:
        odds.append(v[i])

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()

ans = 0
for i in range(len(evens_c)):
    for j in range(len(odds_c)):
        fl = 0
        try:
            if evens_c[i][0] != odds_c[j][0]:
                ans = max(ans, n - evens_c[i][1] - odds_c[j][1])
                fl = 1
        except:
            continue

print(n // 2)


from collections import Counter

n = int(input())

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

odds = []
evens = []

for i in range(n):
    if i % 2 == 0:
        evens.append(v[i])
    else:
        odds.append(v[i])

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()

fl = 0
for i in range(len(evens_c)):
    for j in range(len(odds_c)):
        try:
            if evens_c[i][0] != odds_c[j][0]:
                print(n - evens_c[i][1] - odds_c[j][1])
                fl = 1
                exit()
        except:
            continue
if fl==0:
    print(n//2)



from collections import Counter

n = int(input())

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

odds = []
evens = []

for i in range(n):
    if i % 2 == 0:
        evens.append(v[i])
    else:
        odds.append(v[i])

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()

fl = 0
for i in range(len(evens_c)):
    for j in range(len(odds_c)):
        try:
            if evens_c[i][0] != odds_c[j][0]:
                print(n - odds_c[0][1] - evens_c[0][1])
                fl = 1
                exit()
        except:
            continue
if fl==0:
    print(n//2)



from collections import Counter

n = int(input())

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

odds = []
evens = []

for i in range(n):
    if i % 2 == 0:
        evens.append(v[i])
    else:
        odds.append(v[i])

evens_c = Counter(evens).most_common(2)
odds_c = Counter(odds).most_common(2)

if evens_c[0][0] != odds_c[0][0]:
    print(n - evens_c[0][1] - odds_c[0][1])
    exit()

if len(evens_c) == 1 or len(odds_c) == 1:
    print(n // 2)
    exit()

print(n - max(evens_c[0][1] + odds_c[1][1], evens_c[1][1] + odds_c[0][1]))


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted