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

even = []
odd = []
for i in range(len(V)):
    if V[i] % 2 ==0:
        even.append(V[i])
    else:
        odd.append(V[i])

even =Counter(even)
even = list(even.items())
even = sorted(even,key=itemgetter(1),reverse = True)

odd =Counter(odd)
odd = list(odd.items())
odd = sorted(odd,key=itemgetter(1),reverse = True)

cnt = 0
if len(odd) == 0 :
    if len(even) == 1:
        cnt = N // 2
    else:
        cnt = 0
elif len(even) == 0 :
    if len(odd) == 1:
        cnt = N // 2
    else:
        cnt = 0

elif even[0][1] != odd[0][1]:
    cnt = N - (even[0][1] + odd[0][1])
elif odd[0][1] == even[0][1]:
    if even[1][1] > odd[1][1]:
        cnt = N- (odd[0][1] + even[1][1])
    elif odd[1][1] > even[1][1]:
        cnt = N- (even[0][1] + odd[1][1])

print(cnt)

from collections import Counter

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

ac=Counter(v[::2]).most_common(2)
bc=Counter(v[1::2]).most_common(2)

print(ac,bc)
if ac[0][0] != bc[0][0]:
    ans = n -(ac[0][1] + bc[0][1])
elif ac[0][1] == bc[0][1]:
    ans = n//2
else:
    ans = n-max(ac[1][1] + bc[0][1],bc[1][1] + ac[0][1])
    
    
print(ans)

from collections import Counter
from operator import itemgetter

N = int(input())
V = Counter(map(int, input().split()))

C = list(V.items())
C = sorted(C,key=itemgetter(1),reverse = True)
#print(C)

even = []
odd = []
for i in range(min(len(C),100)):
    if C[i][0] % 2 ==0:
        even.append(C[i])
    else:
        odd.append(C[i])
cnt = 0
if even[0][1] != odd[0][1]:
    for i in range(1,len(odd)):
        cnt += even[i][1]
    for i in range(1,len(even)):
        cnt += odd[i][1]
print(cnt)

from collections import Counter
from operator import itemgetter

N = int(input())
V = Counter(map(int, input().split()))


C = list(V.items())
C = sorted(C,key=itemgetter(1),reverse = True)
#print(C)


even = []
odd = []
for i in range(min(len(C),100)):
    if C[i][0] % 2 ==0:
        even.append(C[i])
    else:
        odd.append(C[i])
#print(even,odd)

cnt = 0
if len(odd) == 0 :
    if len(even) == 1:
        cnt = N // 2
    else:
        cnt = 0
elif len(even) == 0 :
    if len(odd) == 1:
        cnt = N // 2
    else:
        cnt = 0
elif even[0][1] > odd[0][1]:
    cnt = even[0][1] - even[1][1]
elif odd[0][1] > even[0][1]:
    cnt = odd[0][1] - odd[1][1]
elif odd[0][1] == even[0][1]:
    if even[1][1] > odd[1][1]:
        cnt = even[0][1] - even[1][1]
    elif odd[1][1] > even[1][1]:
        cnt = odd[0][1] - odd[1][1]

from collections import Counter

n = int(input())
v = list(map(int,input().split()))
ac = Counter(v[::2]).most_common(2)
bc = Counter(v[1::2]).most_common(2)



if ac[0][0] != bc[0][0]:            
    ans =  n - ac[0][1] - bc[0][1]  
else:                               
    if len(bc) == 1 or len(ac) == 1:
        ans = n // 2
    else: 
        ans = n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])
print(ans)

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Accepted