Problem:


Score : 300 points

Problem Statement

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.

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

Print the minimum number of elements that needs to be replaced.

Sample Input 1

4
3 1 3 2

Sample Output 1

1

The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

The sequence 105,119,105,119,105,119 is /\/\/\/.

Sample Input 3

4
1 1 1 1

Sample Output 3

2

The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
n = input()
v = input()
v = [int(i) for i in v.split(' ')]
ch1={}
ch1_k = []
ch2={}
ch2_k = []

cnt=0
init = v[0]
from operator import itemgetter
for i in range(int(int(n)/2)):
    if v[i] == init:
        cnt += 1
    if v[i*2] not in ch1:
        ch1[v[i*2]] = 1
        ch1_k.append(v[i*2])
    else:
        ch1[v[i*2]] += 1


    if v[i*2+1] not in ch2:
        ch2[v[i*2+1]] = 1
        ch2_k.append(v[i*2+1])
    else:
        ch2[v[i*2+1]] += 1


if len(ch1) == len(ch2) and ch1_k[0] != ch2_k[0] and len(ch1) == 1:
    print(0)
elif len(ch1) == len(ch2) and ch1_k[0] == ch2_k[0] and len(ch1) == 1:
    print(int(int(n)/2))
elif max(ch1.items(), key=itemgetter(1))[0] == max(ch2.items(), key=itemgetter(1))[0]:
    a = int(int(n)/2) - max(ch1.values())
    del ch2[max(ch1.items(), key=itemgetter(1))[0]]
    b = int(int(n)/2) - max(ch2.values())
    print(a+b)
else:
    a = int(int(n)/2) - max(ch1.values())
    b = int(int(n)/2) - max(ch2.values())
    print(a+b)

Submission status: Wrong Answer

Solution code:
n = input()
v = input()
v = [int(i) for i in v.split(' ')]
ch1={}
ch1_k = []
ch2={}
ch2_k = []

cnt=0
init = v[0]
for i in range(int(int(n)/2)):
    if v[i] == init:
        cnt += 1
    if v[i*2] not in ch1:
        ch1[v[i*2]] = 1
        ch1_k.append(v[i*2])
    else:
        ch1[v[i*2]] += 1


    if v[i*2+1] not in ch2:
        ch2[v[i*2+1]] = 1
        ch2_k.append(v[i*2+1])
    else:
        ch2[v[i*2+1]] += 1

if len(ch1) == len(ch2) and ch1_k[0] != ch2_k[0] and len(ch1) == 1:
    print(0)
elif len(ch1) == len(ch2) and ch1_k[0] == ch2_k[0]:
    print(int(int(n)/2))
else:
    a = int(int(n)/2) - max(ch1.values())
    b = int(int(n)/2) - max(ch2.values())
    print(a+b)

Submission status: Wrong Answer

Solution code:
n = input()
v = input()
v = [int(i) for i in v.split(' ')]
ch1={}
ch1_k = []
ch2={}
ch2_k = []

cnt=0
init = v[0]
for i in range(int(int(n)/2)):
    if v[i] == init:
        cnt += 1
    if v[i*2] not in ch1:
        ch1[v[i*2]] = 1
        ch1_k.append(v[i*2])
    else:
        ch1[v[i*2]] += 1


    if v[i*2+1] not in ch2:
        ch2[v[i*2+1]] = 1
        ch2_k.append(v[i*2+1])
    else:
        ch2[v[i*2+1]] += 1

if len(ch1) == len(ch2) and ch1_k[0] != ch2_k[0]:
    print(0)
elif len(ch1) == len(ch2) and ch1_k[0] == ch2_k[0]:
    print(int(int(n)/2))
else:
    a = int(int(n)/2) - max(ch1.values())
    b = int(int(n)/2) - max(ch2.values())
    print(a+b)

Submission status: Wrong Answer

Solution code:
n = input()
v = input()
v = [int(i) for i in v.split(' ')]
ch1={}
ch1_k = []
ch2={}
ch2_k = []

print(v)
cnt=0
init = v[0]
for i in range(int(int(n)/2)):
    if v[i] == init:
        cnt += 1
    if v[i*2] not in ch1:
        ch1[v[i*2]] = 1
        ch1_k.append(v[i*2])
    else:
        ch1[v[i*2]] += 1


    if v[i*2+1] not in ch2:
        ch2[v[i*2+1]] = 1
        ch2_k.append(v[i*2+1])
    else:
        ch2[v[i*2+1]] += 1

print(ch1,ch2, len(ch1), len(ch2))

if len(ch1) == len(ch2) and ch1_k[0] != ch2_k[0]:
    print(0)
elif len(ch1) == len(ch2) and ch1_k[0] == ch2_k[0]:
    print(int(int(n)/2))
else:
    a = int(int(n)/2) - max(ch1.values())
    b = int(int(n)/2) - max(ch2.values())
    print(a+b)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

	kinds = len(set(v))
	if kinds == 1:
		print(int(len(v)/2))
		return

	numbers = [{}, {}]
	for i in range(n):
		index = 0
		if i%2 == 1:
			index = 1

		if v[i] not in numbers[index]:
			numbers[index][v[i]] = 1
		else:
			numbers[index][v[i]] += 1

	if len(numbers[0])==1 and len(numbers[1])==1:
		print("0")
		return

	sort_nums = []
	for i in range(2):
		sort_nums.append(sorted(numbers[i].items(), key=itemgetter(1), reverse=True))
	
	maxes = [sort_nums[0][0], sort_nums[1][0]]
	if sort_nums[0][0][0]!=sort_nums[1][0][0]:
		print(n - sort_nums[0][0][1] - sort_nums[1][0][1])
		return

	#from here is the case where sort_nums[0][0][0] == sort_nums[1][0][0]

	b1 = -100
	b2 = -100

	if len(sort_nums[0])==1:
		print(n - sort_nums[0][0][1] - sort_nums[1][1][1])
		return
	if len(sort_nums[1])==1:
		print(n - sort_nums[1][0][1] - sort_nums[0][1][1])
		return


	if len(sort_nums[0])>1 and len(sort_nums[1])>1:
		if sort_nums[0][0][1] > sort_nums[1][0][1]:
			print(n - sort_nums[0][0][1] - sort_nums[1][1][1])
			return
		else:
			print(n - sort_nums[1][0][1] - sort_nums[0][1][1])
			return


main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

	kinds = len(set(v))
	if kinds == 1:
		print(int(len(v)/2))
		return

	numbers = [{}, {}]
	for i in range(n):
		index = 0
		if i%2 == 1:
			index = 1

		if v[i] not in numbers[index]:
			numbers[index][v[i]] = 1
		else:
			numbers[index][v[i]] += 1

	if len(numbers[0])==1 and len(numbers[1])==1:
		print("0")
		return

	sort_nums = []
	for i in range(2):
		sort_nums.append(sorted(numbers[i].items(), key=itemgetter(1), reverse=True))
	
	maxes = [sort_nums[0][0], sort_nums[1][0]]
	if maxes[0][0] == maxes[1][0]:

		if len(sort_nums[0])>1 and len(sort_nums[1])>1:
			diff = maxes[0][1] - maxes[1][1]
			index = True   #True = 1
			if diff > 0 and sort_nums[0][1][1]>sort_nums[1][1][1]:
				index = False  #True = 0

			total = 0
			total += sum([x[1] for x in sort_nums[index][1:]])
			total += sort_nums[not(index)][0][1]
			total += sum([x[1] for x in sort_nums[not(index)][2:]])
			print(total)
			return

		elif len(sort_nums[0])==1:
			total = 0
			total += sum([x[1] for x in sort_nums[0][1:]])
			total += sort_nums[1][0][1]
			if len(sort_nums[1])>2:
				total += sum([x[1] for x in sort_nums[1][2:]])
			print(total)
			return

		else:
			total = 0
			total += sum([x[1] for x in sort_nums[1][1:]])
			total += sort_nums[0][0][1]
			if len(sort_nums[0]) > 2:
				total += sum([x[1] for x in sort_nums[0][2:]])
			print(total)
			return

	else: 
		total = 0
		for i in range(2):
			total += sum([x[1] for x in sort_nums[i][1:]])
		print(total)
		return
	

main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

	kinds = len(set(v))
	if kinds == 1:
		print(int(len(v)/2))
		return

	numbers = [{}, {}]
	for i in range(n):
		index = 0
		if i%2 == 1:
			index = 1

		if v[i] not in numbers[index]:
			numbers[index][v[i]] = 1
		else:
			numbers[index][v[i]] += 1

	if len(numbers[0])==1 and len(numbers[1])==1:
		print("0")
		return

	sort_nums = []
	for i in range(2):
		sort_nums.append(sorted(numbers[i].items(), key=itemgetter(1), reverse=True))
	
	maxes = [sort_nums[0][0], sort_nums[1][0]]
	if maxes[0][0] == maxes[1][0]:

		if len(sort_nums[0])>1 and len(sort_nums[1])>1:
			diff = maxes[0][1] - maxes[1][1]
			index = True   #True = 1
			if diff > 0 and sort_nums[0][1][1]>sort_nums[1][1][1]:
				index = False  #True = 0

			total = 0
			total += sum([x[1] for x in sort_nums[index][1:]])
			total += sort_nums[not(index)][0][1]
			total += sum([x[1] for x in sort_nums[not(index)][2:]])
			print(total)
			return

		elif len(sort_nums[0])==1:
			total = 0
			total += sum([x[1] for x in sort_nums[0][1:]])
			total += sort_nums[1][0][1]
			total += sum([x[1] for x in sort_nums[1][2:]])
			print(total)
			return

		else:
			total = 0
			total += sum([x[1] for x in sort_nums[1][1:]])
			total += sort_nums[0][0][1]
			total += sum([x[1] for x in sort_nums[0][2:]])
			print(total)
			return

	else: 
		total = 0
		for i in range(2):
			total += sum([x[1] for x in sort_nums[i][1:]])
		print(total)
		return
	

main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

	kinds = len(set(v))
	if kinds == 1:
		print(int(len(v)/2))
		return

	numbers = [{}, {}]
	for i in range(n):
		index = 0
		if i%2 == 1:
			index = 1

		if v[i] not in numbers[index]:
			numbers[index][v[i]] = 1
		else:
			numbers[index][v[i]] += 1

	if len(numbers[0])==1 and len(numbers[1])==1:
		print("0")

	sort_nums = []
	for i in range(2):
		sort_nums.append(sorted(numbers[i].items(), key=itemgetter(1), reverse=True))
	
	maxes = [sort_nums[0][0], sort_nums[1][0]]
	if maxes[0][0] == maxes[1][0]:

		if len(sort_nums[0])>1 and len(sort_nums[1])>1:
			diff = maxes[0][1] - maxes[1][1]
			index = True   #True = 1
			if diff > 0 and sort_nums[0][1][1]>sort_nums[1][1][1]:
				index = False  #True = 0

			total = 0
			total += sum([x[1] for x in sort_nums[index][1:]])
			total += sort_nums[not(index)][0][1]
			total += sum([x[1] for x in sort_nums[not(index)][2:]])
			print(total)

		elif len(sort_nums[0])==1:
			total = 0
			total += sum([x[1] for x in sort_nums[0][1:]])
			total += sort_nums[1][0][1]
			total += sum([x[1] for x in sort_nums[1][2:]])
			print(total)

		else:
			total = 0
			total += sum([x[1] for x in sort_nums[1][1:]])
			total += sort_nums[0][0][1]
			total += sum([x[1] for x in sort_nums[0][2:]])
			print(total)

	else: 
		total = 0
		for i in range(2):
			total += sum([x[1] for x in sort_nums[i][1:]])
		print(total)
	

main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

	kinds = len(set(v))
	if kinds == 1:
		print(int(len(v)/2))
		return

	numbers = [{}, {}]
	for i in range(n):
		index = 0
		if i%2 == 1:
			index = 1

		if v[i] not in numbers[index]:
			numbers[index][v[i]] = 1
		else:
			numbers[index][v[i]] += 1

	if len(numbers[0])==1 and len(numbers[1])==1:
		print("0")

	sort_nums = []
	for i in range(2):
		sort_nums.append(sorted(numbers[i].items(), key=itemgetter(1), reverse=True))
	
	maxes = [sort_nums[0][0], sort_nums[1][0]]
	if maxes[0][0] == maxes[1][0]:

		if len(sort_nums[0])>1 and len(sort_nums[1])>1:
			diff = maxes[0][1] - maxes[1][1]
			index = True   #True = 1
			if diff > 0 and sort_nums[0][1][1]>sort_nums[1][1][1]:
				index = False  #True = 0

			total = 0
			total += sum([x[1] for x in sort_nums[index][1:]])
			total += sort_nums[not(index)][0][1]
			total += sum([x[1] for x in sort_nums[not(index)][2:]])
			print(total)

		if len(sort_nums[0])==1:
			total = 0
			total += sum([x[1] for x in sort_nums[0][1:]])
			total += sort_nums[1][0][1]
			total += sum([x[1] for x in sort_nums[1][2:]])
			print(total)

		else:
			total = 0
			total += sum([x[1] for x in sort_nums[1][1:]])
			total += sort_nums[0][0][1]
			total += sum([x[1] for x in sort_nums[0][2:]])
			print(total)

	else: 
		total = 0
		for i in range(2):
			total += sum([x[1] for x in sort_nums[i][1:]])
		print(total)
	

main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

	kinds = len(set(v))
	if kinds == 1:
		print(int(len(v)/2))
		return

	numbers = [{}, {}]
	for i in range(n):
		index = 0
		if i%2 == 1:
			index = 1

		if v[i] not in numbers[index]:
			numbers[index][v[i]] = 1
		else:
			numbers[index][v[i]] += 1

	if len(numbers[0])==1 and len(numbers[1])==1:
		print("0")

	sort_nums = []
	for i in range(2):
		sort_nums.append(sorted(numbers[i].items(), key=itemgetter(1), reverse=True))
	
	maxes = [sort_nums[0][0], sort_nums[1][0]]
	if maxes[0][0] == maxes[1][0]:
		diff = maxes[0][1] - maxes[1][1]
		index = True   #True = 1
		if diff > 0 and sort_nums[0][1][1]>=sort_nums[1][1][1]:
			index = False  #True = 0

		total = 0
		total += sum([x[1] for x in sort_nums[index][1:]])
		total += sort_nums[not(index)][0][1]
		total += sum([x[1] for x in sort_nums[not(index)][2:]])
		print(total)

	else: 
		total = 0
		for i in range(2):
			total += sum([x[1] for x in sort_nums[i][1:]])
		print(total)
	

main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

	kinds = len(set(v))
	if kinds == 1:
		print(int(len(v)/2))
		return

	numbers = [{}, {}]
	for i in range(n):
		index = 0
		if i%2 == 1:
			index = 1

		if v[i] not in numbers[index]:
			numbers[index][v[i]] = 1
		else:
			numbers[index][v[i]] += 1

	if len(numbers[0])==1 and len(numbers[1])==1:
		print("0")

	sort_nums = []
	for i in range(2):
		sort_nums.append(sorted(numbers[i].items(), key=itemgetter(1), reverse=True))
	
	maxes = [sort_nums[0][0], sort_nums[1][0]]
	if maxes[0][0] == maxes[1][0]:
		diff = maxes[0][1] - maxes[1][1]
		index = True   #True = 1
		if diff > 0 and sort_nums[0][1][1]>sort_nums[1][1][1]:
			index = False  #True = 0

		total = 0
		total += sum([x[1] for x in sort_nums[index][1:]])
		total += sort_nums[not(index)][0][1]
		total += sum([x[1] for x in sort_nums[not(index)][2:]])
		print(total)

	else: 
		total = 0
		for i in range(2):
			total += sum([x[1] for x in sort_nums[i][1:]])
		print(total)
	

main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

	kinds = len(set(v))
	if kinds == 1:
		print(int(len(v)/2))
		return

	numbers = [{}, {}]
	for i in range(n):
		index = 0
		if i%2 == 1:
			index = 1

		if v[i] not in numbers[index]:
			numbers[index][v[i]] = 1
		else:
			numbers[index][v[i]] += 1

	if len(numbers[0])==1 and len(numbers[1])==1:
		print("0")

	sort_nums = []
	for i in range(2):
		sort_nums.append(sorted(numbers[i].items(), key=itemgetter(1), reverse=True))
	
	maxes = [sort_nums[0][0], sort_nums[1][0]]
	if maxes[0][0] == maxes[1][0]:
		diff = maxes[0][1] - maxes[1][1]
		index = True   #True = 1
		if diff >= 0 and sort_nums[0][1][1]>sort_nums[1][1][1]:
			index = False  #True = 0

		total = 0
		total += sum([x[1] for x in sort_nums[index][1:]])
		total += sort_nums[not(index)][0][1]
		total += sum([x[1] for x in sort_nums[not(index)][2:]])
		print(total)

	else: 
		total = 0
		for i in range(2):
			total += sum([x[1] for x in sort_nums[i][1:]])
		print(total)
	

main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

	kinds = len(set(v))
	if kinds == 1:
		print(int(len(v)/2))
		return

	numbers = [{}, {}]
	for i in range(n):
		index = 0
		if i%2 == 1:
			index = 1

		if v[i] not in numbers[index]:
			numbers[index][v[i]] = 1
		else:
			numbers[index][v[i]] += 1

	if len(numbers[0])==1 and len(numbers[1])==1:
		print("0")

	sort_nums = []
	for i in range(2):
		sort_nums.append(sorted(numbers[i].items(), key=itemgetter(1), reverse=True))
	
	maxes = [sort_nums[0][0], sort_nums[1][0]]
	if maxes[0][0] == maxes[1][0]:
		#second = []
		#for i in range(2):
		#	if len(sort_nums[i]) > 1:
		#		second.append(sort_nums[i][1][0])
		
		diff = maxes[0][1] - maxes[1][1]
		index = True
		if diff > 0:
			index = False

		total = 0
		total += sum([x[1] for x in sort_nums[index][1:]])
		total += sort_nums[not(index)][0][1]
		total += sum([x[1] for x in sort_nums[not(index)][2:]])
		print(total)

	else: 
		total = 0
		for i in range(2):
			total += sum([x[1] for x in sort_nums[i][1:]])
		print(total)
	

main()

Submission status: Wrong Answer

Solution code:
n = int(input())
v = len(set(list(map(int,input().split()))))
if v >= 2:
    print(v - 2)
else:
    print(n // 2)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = len(set(list(map(int,input().split()))))
if v >= 2:
    print(v - 2)
else:
    print(n / 2)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = len(set(list(map(int,input().split()))))
print(v - 2)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(int(n/2)):
    a.append(v[2*i])
    b.append(v[2*i-1])
la=[]
lb=[]
maxv=max(v)
for k in range(1,maxv+1):
    if k in a:
        la.append([k,a.count(k)])
    else:
        pass

for k in range(1,maxv+1):
    if k in b:
        lb.append([k,b.count(k)])
    else:
        pass
la.sort(key=lambda x:x[1])
lb.sort(key=lambda x:x[1])

if la==lb:
    print(n-la[0][0]-lb[0][0])
elif la[0][0]==lb[0][0]:
    print(min(n-la[0][1]-lb[1][1], n-la[1][1]-lb[0][1]))
else:
    print(n-la[0][1]-lb[0][1])

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(int(n/2)):
    a.append(v[2*i])
    b.append(v[2*i-1])
la=[]
lb=[]
for k in range(1,max(a)+1):
    if k in a:
        la.append([k,a.count(k)])
    else:
        pass

for k in range(1,max(b)+1):
    if k in b:
        lb.append([k,b.count(k)])
    else:
        pass
la.sort(key=lambda x:x[1])
lb.sort(key=lambda x:x[1])

if la==lb:
    print(n-la[0][0]-lb[0][0])
elif la[0][0]==lb[0][0]:
    print(n-la[0][1]-lb[1][1])
else:
    print(n-la[0][1]-lb[0][1])

Submission status: Wrong Answer

Solution code:
def main():
    inf = 1 << 60
    n = int(input())
    v = list(map(int, input().split()))

    a = [{}, {}]
    for i,vi in enumerate(v):
        ai = i % 2
        if vi in a[ai].keys():
            a[ai][vi] += 1
        else:
            a[ai][vi] = 1

    b = []
    for i in range(0, 2):
        lst = sorted(list(a[i].items()), key=lambda e:e[1], reverse=True)
        b.append(lst)
        #print(lst)

    if b[0][0][0] != b[1][0][0]:
        return n - b[0][0][1] - b[1][0][1]
    b1 = -inf
    b2 = -inf
    if len(b[1]) >= 2:
        b1 = n - b[0][0][1] - b[1][1][1]
    if len(b[0]) >= 2:
        b2 = n - b[0][1][1] - b[1][0][1]
    if b1 > b2:
        if b1 >= 0:
            return b1
    else:
        if b2 >= 0:
            return b2
    if b[0][0][1] > b[1][0][1]:
        return n - b[0][0][1]
    else:
        return n - b[1][0][1]

ans = main()
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = list(map(int, input().split()))

    a = [{}, {}]
    for i,vi in enumerate(v):
        ai = i % 2
        if vi in a[ai].keys():
            a[ai][vi] += 1
        else:
            a[ai][vi] = 1

    b = []
    for i in range(0, 2):
        lst = sorted(list(a[i].items()), key=lambda e:e[1], reverse=True)
        b.append(lst)
        #print(lst)

    if b[0][0][0] != b[1][0][0]:
        return n - b[0][0][1] - b[1][0][1]
    if len(b[1]) >= 2:
        if b[0][0][1] == b[1][1][1]:
            return n - b[0][0][1] - b[1][1][1]
    if len(b[0]) >= 2:
        if b[0][1][1] == b[1][0][1]:
            return n - b[0][1][1] - b[1][0][1]
    if b[0][0][1] > b[1][0][1]:
        return n - b[0][0][1]
    else:
        return n - b[1][0][1]

ans = main()
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = list(map(int, input().split()))

    a = [{}, {}]
    for i,vi in enumerate(v):
        ai = i % 2
        if vi in a[ai].keys():
            a[ai][vi] += 1
        else:
            a[ai][vi] = 1

    b = []
    for i in range(0, 2):
        lst = sorted(list(a[i].items()), key=lambda e:e[1], reverse=True)
        b.append(lst)

    if b[0][0][0] != b[1][0][0]:
        return n - b[0][0][1] - b[1][0][1]
    if b[0][0][1] > b[1][0][1]:
        return n - b[0][0][1]
    else:
        return n - b[1][0][1]

ans = main()
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = list(map(int, input().split()))

    a = [{}, {}]
    for i in range(0, 2):
        for j in range(i, n, 2):
            if v[j] in a[i].keys():
                a[i][v[j]] += 1
            else:
                a[i][v[j]] = 1

    b = [[], []]
    for i in range(0, 2):
        for ak in a[i].keys():
            b[i].append((ak, a[i][ak]))
        b[i].sort(key=lambda e:e[1], reverse=True)
        #print(b[i])

    if b[0][0][0] != b[1][0][0]:
        return n - b[0][0][1] - b[1][0][1]
    if b[0][0][1] > b[1][0][1]:
        return n - b[0][0][1]
    else:
        return n - b[1][0][1]

ans = main()
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v_ls = [int(i) for i in input().split()]
_1st = v_ls[1::2]
_2nd = v_ls[::2]
_1st_dict = dict()
_2nd_dict = dict()
for i in _1st:
    if _1st_dict.get(i) is None:
        _1st_dict[i] = 1
    else:
        _1st_dict[i] += 1
for i in _2nd:
    if _2nd_dict.get(i) is None:
        _2nd_dict[i] = 1
    else:
        _2nd_dict[i] += 1
if len(_1st_dict) <= 1 and len(_2nd_dict) <= 1:
    if _1st[0] == _2nd[0]:
        print(len(_2nd))
    else:
        print(0)
else:
    _1st_dict = sorted(_1st_dict.items(), key= lambda x:x[1])
    _2nd_dict = sorted(_2nd_dict.items(), key= lambda x:x[1])
    while _1st_dict[0][0] == _2nd_dict[0][0]:
        if _1st_dict[0][1] > _2nd_dict[0][1]:
            _2nd_dict.pop(0)
        elif _1st_dict[0][1] < _2nd_dict[0][1]:
            _1st_dict.pop(0)
        elif _1st_dict[1][1] > _2nd_dict[1][1]:
             _1st_dict.pop(0)
        else:
            _2nd_dict.pop(0)
    _1st_dict = dict(_1st_dict)
    _2nd_dict = dict(_2nd_dict)
    dupli = max(_1st_dict.values()) + max(_2nd_dict.values())
    print(len(v_ls) - dupli)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(str, input().split()))
gu_row = []
ki_row = []

for i in range(n):
    if i % 2 == 0:
        gu_row.append(v[i])
    elif i % 2 == 1:
        ki_row.append(v[i])

gu_count = collections.Counter(gu_row).most_common()
ki_count = collections.Counter(ki_row).most_common()
print(gu_count)
print(ki_count)

if len(gu_count) > 1 and len(ki_count) > 1:
    if gu_count[0][0] != ki_count[0][0]:
        ans = n - gu_count[0][1] - ki_count[0][1]
    elif gu_count[0][0] == ki_count[0][0] and len(gu_count) == 1:
        ans = n - gu_count[0][1] - ki_count[1][1]
    elif gu_count[0][0] == ki_count[0][0] and len(ki_count) == 1:
        ans = n - gu_count[1][1] - ki_count[0][1]
    else:
        ans = n - max(gu_count[0][1] + ki_count[1][1], gu_count[1][1] + ki_count[0][1])
else:
    if gu_count[0][0] != ki_count[0][0]:
        ans = n - gu_count[0][1] - ki_count[0][1]
    else:
        ans = gu_count[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**7) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
 
# h,w = li()
# ss = [ns() for _ in range(h)]

n = input()

vs = li()
v_odd = []
v_even = []

i=0
for v in vs:
    if i % 2 == 0:
        v_even.append(v)
    else:
        v_odd.append(v)
    i = i + 1

max_count_odd = 0

m_odd = 0
m_even = 0
for ss in set(v_odd):
    count = v_odd.count(ss)
    if count > max_count_odd:
        max_count_odd = count
        m_odd = ss

max_count_even = 0
for ss in set(v_even):
    count = v_even.count(ss)
    if count > max_count_even:
        max_count_even = count
        m_even = ss
# import pdb;pdb.set_trace() 
ans = len(v_even)-max_count_even  +  len(v_odd)-max_count_odd

m2_oddmax = 0
m2_evenmax = 0
import copy
# import pdb;pdb.set_trace()
if(m_even==m_odd):
    temp = copy.deepcopy(v_odd)
    temp.remove(m_odd)
    m2_odd = 0
    for ss in set(temp):
        count = temp.count(ss)
        if count > m2_oddmax:
            m2_oddmax = count
            m2_odd = ss
    if max_count_even > max_count_odd:
        ans = len(v_even)-max_count_even + len(v_odd)-m2_oddmax
    temp = copy.deepcopy(v_even)
    temp.remove(m_even)
    m2_even = 0
    for ss in set(temp):
        count = temp.count(ss)
        if count > m2_evenmax:
            m2_evenmax = count
            m2_even = ss
    if max_count_even < max_count_odd:
        ans = len(v_even)-m2_evenmax + len(v_odd)-max_count_odd
    if max_count_even == max_count_odd:
        if m2_evenmax > m2_oddmax:
            ans = len(v_even)-m2_evenmax + len(v_odd)-max_count_odd
        else:
            ans = len(v_even)-max_count_even + len(v_odd)-m2_evenmax
    if m2_even == 0 and m2_odd == 0:
        ans = int(X/2)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
H = list(map(int, input().split()))
counter=0
a=[]
b=[]
for i in range(int(n/2)):
    if H[i*2] not in a:
        a.append(H[i*2])
    if H[i*2+1] not in b:
        b.append(H[i*2+1])
    
print(len(a)+len(b)-2)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = len(v) // 2
    O = [v[i] for i in range(1, n, 2)]
    E = [v[i] for i in range(0, n, 2)]

    co = list(collections.Counter(O).most_common())
    ce = list(collections.Counter(E).most_common())
    o1 = co[0][0]
    e1 = ce[0][0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)

    num = 0
    if e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if len(co) == 1 and len(ce) == 1:
            num = half_length
        elif len(co) == 1:
            pass
            """
            e2 = ce[1][0]
            num_e_2 = len(list(filter(lambda e: e != e2, E)))
            num = num_o_1 + num_e_2
            """
        elif len(ce) == 1:
            pass
            """
            o2 = co[1][0]
            num_o_2 = len(list(filter(lambda o: o != o2, O)))
            num = num_o_2 + num_e_1
            """
        else:
            pass
            """
            e2 = ce[1][0]
            o2 = co[1][0]
            num = min(num_o_1 + num_e_2, num_o_2 + num_e_1)
            """
    print(num)
    return

def len2(l):
    n = 0
    for i in l:
        n += 1
    return n

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = len(v) // 2
    O = [v[i] for i in range(1, n, 2)]
    E = [v[i] for i in range(0, n, 2)]

    co = list(collections.Counter(O).most_common())
    ce = list(collections.Counter(E).most_common())
    o1 = co[0][0]
    e1 = ce[0][0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)

    if e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if True or len2(co) == 1 and len2(ce) == 1:
            num = half_length
        elif len(co) == 1:
            e2 = ce[1][0]
            num_e_2 = len(list(filter(lambda e: e != e2, E)))
            num = num_o_1 + num_e_2
        elif len(ce) == 1:
            o2 = co[1][0]
            num_o_2 = len(list(filter(lambda o: o != o2, O)))
            num = num_o_2 + num_e_1
        else:
            e2 = ce[1][0]
            o2 = co[1][0]
            num = min(num_o_1 + num_e_2, num_o_2 + num_e_1)
    print(num)
    return

def len2(l):
    n = 0
    for i in l:
        n += 1
    return n

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = len(v) // 2
    O = [v[i] for i in range(1, n, 2)]
    E = [v[i] for i in range(0, n, 2)]

    co = list(collections.Counter(O).most_common())
    ce = list(collections.Counter(E).most_common())
    o1 = co[0][0]
    e1 = ce[0][0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)

    if e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if len(co) and len(ce) :
            num = half_length
        elif len(co) == 1:
            e2 = ce[1][0]
            num_e_2 = len(list(filter(lambda e: e != e2, E)))
            num = num_o_1 + num_e_2
        elif len(ce) == 1:
            o2 = co[1][0]
            num_o_2 = len(list(filter(lambda o: o != o2, O)))
            num = num_o_2 + num_e_1
        else:
            e2 = ce[1][0]
            o2 = co[1][0]
            num = min(num_o_1 + num_e_2, num_o_2 + num_e_1)
    print(num)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import statistics
import collections

def solve(n: int, v: "List[int]"):
    half_length = len(v) // 2
    O = [v[i] for i in range(1, n, 2)]
    E = [v[i] for i in range(0, n, 2)]

    co = list(collections.Counter(O).most_common())
    ce = list(collections.Counter(E).most_common())
    len(co)
    len(ce)
    o1 = co[0][0]
    e1 = ce[0][0]

    O_ = list(filter(lambda o: o != o1, O))
    E_ = list(filter(lambda e: e != e1, E))
    num_o_1 = len(O_) 
    num_e_1 = len(E_)

    print(0)
    return

    if e1 != o1:
        num = num_o_1 + num_e_1
    else:
        if len(co) == 1 and len(ce) == 1:
            num = half_length
        elif len(co) == 1:
            e2 = ce[1][0]
            num_e_2 = len(list(filter(lambda e: e != e2, E)))
            num = num_o_1 + num_e_2
        elif len(ce) == 1:
            o2 = co[1][0]
            num_o_2 = len(list(filter(lambda o: o != o2, O)))
            num = num_o_2 + num_e_1
        else:
            e2 = ce[1][0]
            o2 = co[1][0]
            num = min(num_o_1 + num_e_2, num_o_2 + num_e_1)
    print(num)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    v = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, v)

if __name__ == '__main__':
    main()