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()))

v1 = []
v2 = []



if max(v) == min(v):
    print(int(n/2))
elif v[0] == v[1]:
    j=0
    for i in range(int(n/2)):
        v1.append(v[j])
        j+=2
    j=0
    for i in range(int(n/2)):
        v2.append(v[j+1])
        j+=2

    import collections

    v1n = collections.Counter(v1)
    values, counts1 = zip(*v1n.most_common())

    v2n = collections.Counter(v2)
    values, counts2 = zip(*v2n.most_common())

    print( (len(v1)-max(counts1)) + (len(v2)-max(counts2)) + 1)
else:
    j=0
    for i in range(int(n/2)):
        v1.append(v[j])
        j+=2
    
    j=0

    for i in range(int(n/2)):
        v2.append(v[j+1])
        j+=2

    import collections

    v1n = collections.Counter(v1)
    values, counts1 = zip(*v1n.most_common())

    v2n = collections.Counter(v2)
    values, counts2 = zip(*v2n.most_common())

    print( (len(v1)-max(counts1)) + (len(v2)-max(counts2)) + 1)

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

v1 = []
v2 = []

if max(v) == min(v):
    print(int(n/2))
else:
    j=0
    for i in range(int(n/2)):
        v1.append(v[j])
        j+=2
    
    j=0

    for i in range(int(n/2)):
        v2.append(v[j+1])
        j+=2

    import collections

    v1n = collections.Counter(v1)
    values1, counts1 = zip(*v1n.most_common())

    v2n = collections.Counter(v2)
    values2, counts2 = zip(*v2n.most_common())
    
    if max(counts1) != 1 and max(counts2) != 1:
        print( (len(v1)-max(counts1)) + (len(v2)-max(counts2)))
    else:
        print( int(n/2) + min((len(v1)-max(counts1)),(len(v2)-max(counts2))) )

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

v1 = []
v2 = []



if max(v) == min(v):
    print(int(n/2))
else:
    j=0
    for i in range(int(n/2)):
        v1.append(v[j])
        j+=2
    
    j=0

    for i in range(int(n/2)):
        v2.append(v[j+1])
        j+=2

    import collections

    v1n = collections.Counter(v1)
    values1, counts1 = zip(*v1n.most_common())

    v2n = collections.Counter(v2)
    values2, counts2 = zip(*v2n.most_common())
    
    if values1 != values2 and max(counts1) != 1 and max(counts2) != 1:
        print( (len(v1)-max(counts1)) + (len(v2)-max(counts2)))
    else:
        print( int(n/2) + min((len(v1)-max(counts1)),(len(v2)-max(counts2))) )

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

count = 0

if max(v) == min(v):
    print(int(n/2))
else:
    for i in range(int(n/2)):
        if v[0] != v[j+2]:
            count += 1
        if v[1] != v[j+3]:
            count =+ 1
        j = j+2
    print(count)    

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

v1 = []
v2 = []

j=0
for i in range(int(n/2)):
    v1.append(v[j])
    j+=2
    
j=0
for i in range(int(n/2)):
    v2.append(v[j+1])
    j+=2

import collections

v1n = collections.Counter(v1)
v2n = collections.Counter(v2)

if v1n.most_common()[0][0] != v2n.most_common()[0][0]:
    print(n - v1n.most_common()[0][1] - v2n.most_common()[0][1])
else:
    if len(v1n) == 1 and len(v2n) == 1:
        print(int(n/2))
    else:
        xxx=(len(v1)-v1n.most_common()[0][1])+(len(v2)-v2n.most_common()[1][1])
        yyy=(len(v1)-v1n.most_common()[1][1])+(len(v2)-v2n.most_common()[0][1])
        print(min(xxx,yyy))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted