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


sequence_list=[]
sequence_even_value_cnt_sortlist=[]
sequence_odd_value_cnt_sortlist=[]
sequence_even_value_cnt={}
sequence_odd_value_cnt={}
even_2_maxnum=0
odd_2_maxnum=0

sequence_num=int(input())
sequence_list=input().split()

for i in range(sequence_num):
    if i%2==0:
        sequence_even_value_cnt[sequence_list[i]]=sequence_even_value_cnt.get(sequence_list[i],0)+1
    else:
        sequence_odd_value_cnt[sequence_list[i]]=sequence_odd_value_cnt.get(sequence_list[i],0)+1
        
print(sequence_odd_value_cnt)
print(sequence_even_value_cnt)
    
sequence_even_value_cnt_sortlist=sorted(sequence_even_value_cnt.items(),key=lambda x:x[1],reverse=True)
sequence_odd_value_cnt_sortlist=sorted(sequence_odd_value_cnt.items(),key=lambda x:x[1],reverse=True)

even_1_maxnum=sequence_even_value_cnt_sortlist[0][1]
odd_1_maxnum=sequence_odd_value_cnt_sortlist[0][1]

for j in sequence_even_value_cnt_sortlist:
    
    if even_1_maxnum!=j[1]:
        even_2_maxnum=j[1]
        break

for k in sequence_odd_value_cnt_sortlist:
    
    if odd_1_maxnum!=k[1]:
        odd_2_maxnum=k[1]
        break

if sequence_even_value_cnt_sortlist[0][0]!=sequence_odd_value_cnt_sortlist[0][0]:
    ans=sequence_num-(even_1_maxnum+odd_1_maxnum)
else:
    if even_2_maxnum>=odd_2_maxnum:
        ans=sequence_num-(even_2_maxnum+odd_1_maxnum)
    else:
        ans=sequence_num-(even_1_maxnum+odd_2_maxnum)

print(ans)
    


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

nums1 = nums[0::2] 
nums2 = nums[1::2]
print(nums1)
print(nums2)

bug1 = [0] * 100001 
bug2 = [0] * 100001


for num in nums1:
    bug1[num] += 1

for num in nums2:
    bug2[num] += 1

max_v_1 = max(bug1)
max_i_1 = bug1.index(max_v_1) 
max_v_2 = max(bug2)
max_i_2 = bug2.index(max_v_2)

if max_i_1 == max_i_2:
    bug1[max_i_1] = 0 
    bug2[max_i_2] = 0
    sec_max_v_1 = max(bug1)
    sec_max_v_2 = max(bug2)
	
    print(n - max(max_v_1, max_v_2) - max(sec_max_v_1, sec_max_v_2))
else:
    print(n - max_v_1 - max_v_2) 



import collections

sequence_num=int(input())
count=0
even_sequence_list=[]
odd_sequence_list=[]
sequence_list=list(map(int,input().split()))
for i in range(sequence_num):
	if i%2 == 0:
		even_sequence_list.append(sequence_list[i])
	else:
		odd_sequence_list.append(sequence_list[i])
even_mode=collections.Counter(even_sequence_list).most_common()[0][0]
odd_mode=collections.Counter(odd_sequence_list).most_common()[0][0]
if even_mode != odd_mode:
	for i in even_sequence_list:
		if i != even_mode:
			count+=1
	for j in odd_sequence_list:
		if j != odd_mode:
			count+=1
	print(count)
else:
	even_counter=collections.Counter(even_sequence_list)
	odd_counter=collections.Counter(odd_sequence_list)
	if len(even_counter.keys()) == 1 and len(odd_counter.keys()) == 1:
		even_mode=0
		for i in even_sequence_list:
			if i != even_mode:
				count+=1
		for j in odd_sequence_list:
			if j != odd_mode:
				count+=1
		print(count)
	elif len(even_counter.keys()) != 1 and len(odd_counter.keys()) == 1:
		even_mode=collections.Counter(even_sequence_list).most_common()[1][0]
		for i in even_sequence_list:
			if i != even_mode:
				count+=1
		for j in odd_sequence_list:
			if j != odd_mode:
				count+=1
		print(count)
	elif len(even_counter.keys()) == 1 and len(odd_counter.keys()) != 1:
		odd_mode=collections.Counter(odd_sequence_list).most_common()[1][0]
		for i in even_sequence_list:
			if i != even_mode:
				count+=1
		for j in odd_sequence_list:
			if j != odd_mode:
				count+=1
		print(count)
	else:
		even_2_mode=collections.Counter(even_sequence_list).most_common()[1][0]
		odd_2_mode=collections.Counter(odd_sequence_list).most_common()[1][0]
		even_change_count=0
		odd_change_count=0
		for i in even_sequence_list:
			if i != even_2_mode:
				even_change_count+=1
		for j in odd_sequence_list:
			if j != odd_mode:
				even_change_count+=1
		for i in even_sequence_list:
			if i != even_mode:
				odd_change_count+=1
		for j in odd_sequence_list:
			if j != odd_2_mode:
				odd_change_count+=1
		if even_change_count < odd_change_count:
			print(even_change_count)
		else:
			print(odd_change_count)

Verdicts: Wrong Answer

Wrong Answer

Accepted