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 = int(input())
v = list(map(int,input().split()))
v_odd,v_eve = v[0::2],v[1::2]
lvo,lve = len(v_odd),len(v_eve)

v_odd_s = {}
for c in v_odd:v_odd_s[c] = v_odd_s.get(c,0) + 1
v_odd_l = []
for c in v_odd_s.keys():v_odd_l.append([c,v_odd_s[c]])
sorted_v_odd_l = sorted(v_odd_l, key=lambda x: x[1])

v_eve_s = {}
for c in v_eve:v_eve_s[c] = v_eve_s.get(c,0) + 1
v_eve_l = []
for c in v_eve_s.keys():v_eve_l.append([c,v_eve_s[c]])
sorted_v_eve_l = sorted(v_eve_l, key=lambda x: x[1])

if len(sorted_v_odd_l) == 1:sorted_v_odd_l.append([100001,0])
if len(sorted_v_eve_l) == 1:sorted_v_eve_l.append([100002,0])

#4 pattern cost
if sorted_v_eve_l[0][0] == sorted_v_odd_l[0][0]:p1 = -1
else:p1 = lvo + lve - sorted_v_eve_l[0][1] - sorted_v_odd_l[0][1]
if sorted_v_eve_l[1][0] == sorted_v_odd_l[0][0]:p2 = -1
else:p2 = lvo + lve - sorted_v_eve_l[1][1] - sorted_v_odd_l[0][1]
if sorted_v_eve_l[0][0] == sorted_v_odd_l[1][0]:p3 = -1
else:p3 = lvo + lve - sorted_v_eve_l[0][1] - sorted_v_odd_l[1][1]
if sorted_v_eve_l[1][0] == sorted_v_odd_l[1][0]:p4 = -1
else:p4 = lvo + lve - sorted_v_eve_l[1][1] - sorted_v_odd_l[1][1]

for i in sorted([p1,p2,p3,p4]):
    if i>=0:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
# C
import collections
n = int(input())
lst = list(map(int, input().split()))
lst1 = lst[::2]
lst2 = lst[1::2]
dct1 = sorted(dict(collections.Counter(lst1)).items(), key=lambda x:-x[1])
dct2 = sorted(dict(collections.Counter(lst2)).items(), key=lambda x:-x[1])


ans = 0
print(len(dct1))
if (len(dct1) == 1 and len(dct2) == 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = dct1[0][1]
	else:
		ans = 0
elif (len(dct1) == 1 and len(dct2) > 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = len(dct2) - dct2[1][1]
	else:
		ans = len(dct2) - dct2[0][1]
elif (len(dct2) == 1 and len(dct1) > 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = len(dct1) - dct1[1][1]
	else:
		ans = len(dct1) - dct1[0][1]
elif (len(dct1) > 1 and len(dct2) > 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = len(lst) - max(dct1[0][1] + dct2[1][1], dct1[1][1] + dct2[0][1])
	else:
		ans = len(lst) - dct1[0][1] - dct2[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
# C
import collections
n = int(input())
lst = list(map(int, input().split()))
lst1 = lst[::2]
lst2 = lst[1::2]
dct1 = sorted(dict(collections.Counter(lst1)).items(), key=lambda x:-x[1])
dct2 = sorted(dict(collections.Counter(lst2)).items(), key=lambda x:-x[1])


ans = 0

if (len(dct1) == 1 and len(dct2) == 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = dct1[0][1]
	else:
		ans = 0
elif (len(dct1) == 1 and len(dct2) > 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = len(dct2) - dct2[1][1]
	else:
		ans = len(dct2) - dct2[0][1]
elif (len(dct2) == 1 and len(dct1) > 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = len(dct1) - dct1[1][1]
	else:
		ans = len(dct1) - dct1[0][1]
elif (len(dct1) > 1 and len(dct2) > 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = len(lst) - max(dct1[0][1] + dct2[1][1], dct1[1][1] + dct2[0][1])
	else:
		ans = len(lst) - dct1[0][1] - dct2[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
# C
import collections
n = int(input())
lst = list(map(int, input().split()))
lst1 = lst[::2]
lst2 = lst[1::2]
dct1 = sorted(dict(collections.Counter(lst1)).items(), key=lambda x:-x[1])
dct2 = sorted(dict(collections.Counter(lst2)).items(), key=lambda x:-x[1])


ans = 0

if (len(dct1) == 1 and len(dct2) == 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = dct1[0][1]
	else:
		ans = 0
elif (len(dct1) == 1 and len(dct2) > 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = len(dct2) - dct2[1][1]
	else:
		ans = len(dct2) - dct2[0][1]
elif (len(dct2) == 1 and len(dct1) > 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = len(dct1) - dct1[1][1]
	else:
		ans = len(dct1) - dct1[0][1]
else:
	if (dct1[0][0] == dct2[0][0]):
		ans = len(lst) - max(dct1[0][1] + dct2[1][1], dct1[1][1] + dct2[0][1])
	else:
		ans = len(lst) - dct1[0][1] - dct2[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
# C
import collections
n = int(input())
lst = list(map(int, input().split()))
lst1 = lst[::2]
lst2 = lst[1::2]
dct1 = sorted(dict(collections.Counter(lst1)).items(), key=lambda x:-x[1])
dct2 = sorted(dict(collections.Counter(lst2)).items(), key=lambda x:-x[1])

if (len(dct1) == 1 and len(dct2) == 1):
	print(0)
elif (len(dct1) == 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct2) - dct2[1][1])
	else:
		print(len(dct2) - dct2[0][1])
elif (len(dct2) == 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct1) - dct1[1][1])
	else:
		print(len(dct1) - dct1[0][1])
else:
	if (dct1[0][0] == dct2[0][0]):
		print(len(lst) - max(dct1[0][1] + dct2[1][1], dct1[1][1] + dct2[0][1]))
	else:
		print(len(lst) - dct1[0][1] - dct2[0][1])

Submission status: Wrong Answer

Solution code:
# C
import collections
n = int(input())
lst = list(map(int, input().split()))
lst1 = lst[::2]
lst2 = lst[1::2]
dct1 = sorted(dict(collections.Counter(lst1)).items(), key=lambda x:-x[1])
dct2 = sorted(dict(collections.Counter(lst2)).items(), key=lambda x:-x[1])

cnt = len(dict(collections.Counter(lst)))
if (cnt == 1):
	print(int(len(lst) / 2))
elif (len(dct1) == 1 and len(dct2) == 1):
	print(0)

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

Solution code:
print(0)

Submission status: Wrong Answer

Solution code:
# C
import collections
n = int(input())
lst = list(map(int, input().split()))
lst1 = lst[::2]
lst2 = lst[1::2]
dct1 = sorted(dict(collections.Counter(lst1)).items(), key=lambda x:-x[1])
dct2 = sorted(dict(collections.Counter(lst2)).items(), key=lambda x:-x[1])

cnt = len(dict(collections.Counter(lst)))
if (cnt == 1):
	print(int(len(lst) / 2))
elif (len(dct1) == 1 and len(dct2) == 1):
	print(0)
elif (len(dct1) == 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct2) - dct2[1][1])
	else:
		print(len(dct2) - dct2[0][1])
elif (len(dct2) == 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct1) - dct1[1][1])
	else:
		print(len(dct1) - dct1[0][1])
else:
	if (dct1[0][0] == dct2[0][0]):
		print(len(lst) - max(dct1[0][1] + dct2[1][1], dct1[1][1] + dct2[0][1]))
	else:
		print(len(lst) - dct1[0][1] - dct2[0][1])

Submission status: Wrong Answer

Solution code:
# C
import collections
n = int(input())
lst = list(map(int, input().split()))
lst1 = lst[::2]
lst2 = lst[1::2]
dct1 = sorted(dict(collections.Counter(lst1)).items(), key=lambda x:-x[1])
dct2 = sorted(dict(collections.Counter(lst2)).items(), key=lambda x:-x[1])

cnt = len(dict(collections.Counter(lst)))
if (cnt == 1):
	print(int(len(lst) / 2))
elif (len(dct1) == 1):
	print(0)
elif (len(dct1) == 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct2) - dct2[1][1])
	else:
		print(len(dct2) - dct2[0][1])
elif (len(dct2) == 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct1) - dct1[1][1])
	else:
		print(len(dct1) - dct1[0][1])
else:
	if (dct1[0][0] == dct2[0][0]):
		print(len(lst) - max(dct1[0][1] + dct2[1][1], dct1[1][1] + dct2[0][1]))
	else:
		print(len(lst) - dct1[0][1] - dct2[0][1])

Submission status: Wrong Answer

Solution code:
# C
import collections
n = int(input())
lst = list(map(int, input().split()))
lst1 = lst[::2]
lst2 = lst[1::2]
dct1 = sorted(dict(collections.Counter(lst1)).items(), key=lambda x:-x[1])
dct2 = sorted(dict(collections.Counter(lst2)).items(), key=lambda x:-x[1])

cnt = len(dict(collections.Counter(lst)))
if (cnt == 1):
	print(int(len(lst) / 2))
elif (len(dct1) == 1 and len(dct2) == 1):
	print(0)
elif (len(dct1) == 1 and len(dct2) > 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct2) - dct2[1][1])
	else:
		print(len(dct2) - dct2[0][1])
elif (len(dct2) == 1 and len(dct1) > 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct1) - dct1[1][1])
	else:
		print(len(dct1) - dct1[0][1])
else:
	if (dct1[0][0] == dct2[0][0]):
		print(len(lst) - max(dct1[0][1] + dct2[1][1], dct1[1][1] + dct2[0][1]))
	else:
		print(len(lst) - dct1[0][1] - dct2[0][1])

Submission status: Wrong Answer

Solution code:
# C
import collections
n = int(input())
lst = list(map(int, input().split()))
lst1 = lst[::2]
lst2 = lst[1::2]
dct1 = sorted(dict(collections.Counter(lst1)).items(), key=lambda x:-x[1])
dct2 = sorted(dict(collections.Counter(lst2)).items(), key=lambda x:-x[1])

cnt = len(dict(collections.Counter(lst)))
if (cnt == 1):
	print(int(len(lst) / 2))
elif (len(dct1) == 1 and len(dct2) == 1):
	print(0)
elif (len(dct1) == 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct2) - dct2[1][1])
	else:
		print(len(dct2) - dct2[0][1])
elif (len(dct2) == 1 and len(dct1) > 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct1) - dct1[1][1])
	else:
		print(len(dct1) - dct1[0][1])
else:
	if (dct1[0][0] == dct2[0][0]):
		print(len(lst) - max(dct1[0][1] + dct2[1][1], dct1[1][1] + dct2[0][1]))
	else:
		print(len(lst) - dct1[0][1] - dct2[0][1])

Submission status: Wrong Answer

Solution code:
# C
import collections
n = int(input())
lst = list(map(int, input().split()))
lst1 = lst[::2]
lst2 = lst[1::2]
dct1 = sorted(dict(collections.Counter(lst1)).items(), key=lambda x:x[1])
dct2 = sorted(dict(collections.Counter(lst2)).items(), key=lambda x:x[1])


if (len(dct1) == 1 and len(dct2) == 1):
	print(0)
elif (len(dct1) == 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct2) - dct2[1][1])
	else:
		print(len(dct2) - dct2[0][1])
elif (len(dct2) == 1 and len(dct1) > 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct1) - dct1[1][1])
	else:
		print(len(dct1) - dct1[0][1])
else:
	if (dct1[0][0] == dct2[0][0]):
		print(len(lst) - max(dct1[0][1] + dct2[1][1], dct1[1][1] + dct2[0][1]))
	else:
		print(len(lst) - dct1[0][1] - dct2[0][1])

Submission status: Wrong Answer

Solution code:
# C
import collections
n = int(input())
lst = list(map(int, input().split()))
lst1 = lst[::2]
lst2 = lst[1::2]
dct1 = sorted(dict(collections.Counter(lst1)).items(), key=lambda x:x[1])
dct2 = sorted(dict(collections.Counter(lst2)).items(), key=lambda x:x[1])

cnt = len(dict(collections.Counter(lst)))
if (cnt == 1):
	print(int(len(lst) / 2))
elif (len(dct1) == 1 and len(dct2) == 1):
	print(0)
elif (len(dct1) == 1 and len(dct2) > 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct2) - dct2[1][1])
	else:
		print(len(dct2) - dct2[0][1])
elif (len(dct2) == 1 and len(dct1) > 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct1) - dct1[1][1])
	else:
		print(len(dct1) - dct1[0][1])
else:
	if (dct1[0][0] == dct2[0][0]):
		print(len(lst) - max(dct1[0][1] + dct2[1][1], dct1[1][1] + dct2[0][1]))
	else:
		print(len(lst) - dct1[0][1] - dct2[0][1])

Submission status: Wrong Answer

Solution code:
# C
import collections
n = int(input())
lst = list(map(int, input().split()))
lst1 = lst[::2]
lst2 = lst[1::2]
dct1 = sorted(dict(collections.Counter(lst1)).items(), key=lambda x:x[1])
dct2 = sorted(dict(collections.Counter(lst2)).items(), key=lambda x:x[1])

cnt = len(dict(collections.Counter(lst)))
if (cnt == 1):
	print(int(len(lst) / 2))
elif (len(dct1) == 1 and len(dct2) == 1):
	print(0)
elif (len(dct1) == 1 and len(dct2) > 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct2) - dct2[1][1])
	else:
		print(len(dct2) - dct2[0][1])
elif (len(dct2) == 1 and len(dct2) > 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct1) - dct1[1][1])
	else:
		print(len(dct1) - dct1[0][1])
else:
	if (dct1[0][0] == dct2[0][0]):
		print(len(lst) - max(dct1[0][1] + dct2[1][1], dct1[1][1] + dct2[0][1]))
	else:
		print(len(lst) - dct1[0][1] - dct2[0][1])

Submission status: Wrong Answer

Solution code:
# C
import collections
n = int(input())
lst = list(map(int, input().split()))
lst1 = lst[::2]
lst2 = lst[1::2]
dct1 = sorted(dict(collections.Counter(lst1)).items(), key=lambda x:x[1])
dct2 = sorted(dict(collections.Counter(lst2)).items(), key=lambda x:x[1])

cnt = len(dict(collections.Counter(lst)))
if (cnt == 1):
	print(int(len(lst) / 2))
elif (len(dct1) == 1 and len(dct2) == 1):
	print(0)
elif (len(dct1) == 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct2) - dct2[1][1])
	else:
		print(len(dct2) - dct2[0][1])
elif (len(dct2) == 1):
	if (dct1[0][0] == dct2[0][0]):
		print(len(dct1) - dct1[1][1])
	else:
		print(len(dct1) - dct1[0][1])
else:
	if (dct1[0][0] == dct2[0][0]):
		print(len(lst) - max(dct1[0][1] + dct2[1][1], dct1[1][1] + dct2[0][1]))
	else:
		print(len(lst) - dct1[0][1] - dct2[0][1])

Submission status: Wrong Answer

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

set_even = set(v[0::2]) 
set_odd = set(v[1::2]) 
dic_even={i:0 for i in set_even}
dic_odd={i:0 for i in set_odd}

for i in range(n):
  if i%2==0:
    dic_even[v[i]]+=1
  else:
    dic_odd[v[i]]+=1
    
even = sorted(dic_even.items(),key = lambda x: x[1],reverse=True)
odd = sorted(dic_odd.items(),key = lambda x: x[1],reverse=True)
ans = 0

if len(even)==1 and len(odd)==1:
  if even[0][0] == odd[0][0]:
    ans = even[0][1]
  else:
    ans = 0
elif len(even)==1 and len(odd)>1:
  if even[0][0] == odd[0][0]:
    ans = len(odd)-odd[1][1]
  else:
    ans = len(odd)-odd[0][1]
elif len(even)>1 and len(even)==1:
  if even[0][0] == odd[0][0]:
    ans = len(even)-even[1][1]
  else:
    ans = len(even)-even[0][1]
else:
  if even[0][0] == odd[0][0]:    
    cdt_1 = even[0][1] + odd[1][1]
    cdt_2 = even[1][1] + odd[0][1]
    ans = n- max(cdt_1,cdt_2)
  else:
    ans = n - (even[0][1] + odd[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ans = len(v) // 2
v1 = v[0::2]
v2 = v[1::2]
c1 = Counter(v1).most_common()
c2 = Counter(v2).most_common()

for c1_v, c1_c in c1:
    for c2_v, c2_c in c2:
        if c1_v != c2_v:
            ans = min(len(v1) - c1_c + len(v2) - c2_c, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ans = 0
v1 = v[0::2]
v2 = v[1::2]
c1 = Counter(v1).most_common()
c2 = Counter(v2).most_common()
if c1[0][1] < c2[0][1]:
    c1, c2 = c2, c1

v1_val, v1_c = c1[0]
ans += len(v1) - v1_c

for v2_val, v2_c in c2:
    if v1_val != v2_val:
        ans += len(v2) - v2_c
        break
else:
    ans += len(v2)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ans = 0
v1 = v[0::2]
v2 = v[1::2]
c1 = Counter(v1).most_common()
c2 = Counter(v2).most_common()
v1_val, v1_c = c1[0]
ans += len(v1) - v1_c

for v2_val, v2_c in c2:
    if v1_val != v2_val:
        ans += len(v2) - v2_c
        break
else:
    ans += len(v2)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = int(sys.stdin.readline())
v = list(map(int, sys.stdin.readline().split()))
count = 0
if v[0] != v[1]:
    for i in range(0,n,2):
        if v[i] != v[0]:
            count += 1
        elif v[i+1] != v[1]:
            count += 1
else:
    for i in range(1,n,2):
        if v[i] != v[1]:
            v[1] = v[i]
            break
    for i in range(0,n,2):
        if v[i] != v[0]:
            count += 1
        elif v[i+1] != v[1]:
            count += 1
    if v[0] == v[1]:
        count += n//2
print(count)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
even = v[0::2]
odd = v[1::2]
c_even = collections.Counter(even)
c_odd = collections.Counter(odd)

half = int(n/2)
even_num, even_count = c_even.most_common(1)[0]
odd_num, odd_count = c_odd.most_common(1)[0]

if len(c_even) == 1 and len(c_odd) == 1:
  if even_num == odd_num:
    print(half)
  else:
    print("0")
elif even_num == odd_num:
  if even_count > odd_count:
    print((half - even_count) + (half - c_odd.most_common(2)[0][1]))
  elif even_count == odd_count:
    if len(c_even) == 1 or c_odd.most_common(2)[0][1] > c_even.most_common(2)[0][1]:
      print((half - even_count) + (half - c_odd.most_common(2)[0][1]))
    else:
      print((half - odd_count) + (half - c_even.most_common(2)[0][1]))
  else:
    print((half - odd_count) + (half - c_even.most_common(2)[0][1]))
else:
  print((half - odd_count) + (half - even_count))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
even = v[0::2]
odd = v[1::2]
c_even = collections.Counter(even)
c_odd = collections.Counter(odd)

half = int(n/2)
even_num, even_count = c_even.most_common(1)[0]
odd_num, odd_count = c_odd.most_common(1)[0]

if len(c_even) == 1 and len(c_odd) == 1:
  if even_num == odd_num:
    print(half)
  else:
    print("0")
elif even_num == odd_num:
  if even_count > odd_count:
    print((half - even_count) + (half - c_odd.most_common(2)[0][1]))
  elif even_count == odd_count:
    if len(c_even) == 1 or c_odd.most_common(2)[0][1] > c_odd.most_common(2)[0][1]:
      print((half - even_count) + (half - c_odd.most_common(2)[0][1]))
    else:
      print((half - odd_count) + (half - c_even.most_common(2)[0][1]))
  else:
    print((half - odd_count) + (half - c_even.most_common(2)[0][1]))
else:
  print((half - odd_count) + (half - even_count))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
even = v[0::2]
odd = v[1::2]
c_even = collections.Counter(even)
c_odd = collections.Counter(odd)

half = int(n/2)
even_num, even_count = c_even.most_common(1)[0]
odd_num, odd_count = c_odd.most_common(1)[0]

if len(c_even) == 1 and len(c_odd) == 1:
  if even_num == odd_num:
    print(half)
  else:
    print("0")
elif even_num == odd_num:
  if even_count > odd_count:
    print((half - even_count) + (half - c_odd.most_common(2)[0][1]))
  elif even_count == odd_count:
    if c_odd.most_common(2)[0][1] > c_odd.most_common(2)[0][1]:
      print((half - even_count) + (half - c_odd.most_common(2)[0][1]))
    else:
      print((half - odd_count) + (half - c_even.most_common(2)[0][1]))
  else:
    print((half - odd_count) + (half - c_even.most_common(2)[0][1]))
else:
  print((half - odd_count) + (half - even_count))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
even = v[0::2]
odd = v[1::2]
c_even = collections.Counter(even)
c_odd = collections.Counter(odd)

half = int(n/2)
even_num, even_count = c_even.most_common(1)[0]
odd_num, odd_count = c_odd.most_common(1)[0]

if len(c_even) == 1 and len(c_odd) == 1:
  if even_num == odd_num:
    print(half)
  else:
    print("0")
elif even_num == odd_num:
  if even_count > odd_count:
    print((half - even_count) + (half - c_odd.most_common(2)[0][1]))
  else:
    print((half - odd_count) + (half - c_even.most_common(2)[0][1]))
else:
  print((half - odd_count) + (half - even_count))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
even = v[0::2]
odd = v[1::2]
c_even = collections.Counter(even)
c_odd = collections.Counter(odd)

half = int(n/2)
even_num, even_count = c_even.most_common(1)[0]
odd_num, odd_count = c_odd.most_common(1)[0]

if len(c_even) == 1 and len(c_odd) == 1:
  if even_num == odd_num:
  	print(half)
  else:
    print(0)
elif even_num == odd_num:
  if even_count > odd_count:
    print((half - even_count) + (half - c_odd.most_common(2)[0][1]))
  else:
    print((half - odd_count) + (half - c_even.most_common(2)[0][1]))
else:
  print((half - odd_count) + (half - even_count))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
even = v[0::2]
odd = v[1::2]
c_even = collections.Counter(even)
c_odd = collections.Counter(odd)

half = int(n/2)
even_num, even_count = c_even.most_common(1)[0]
odd_num, odd_count = c_odd.most_common(1)[0]

if len(c_even) == 1 and len(c_odd) == 1:
  print(half)
elif even_num == odd_num:
  if even_count > odd_count:
    print((half - even_count) + (half - c_odd.most_common(2)[0][1]))
  else:
    print((half - odd_count) + (half - c_even.most_common(2)[0][1]))
else:
  print((half - odd_count) + (half - even_count))

Submission status: Wrong Answer

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

odd = []
even = []
for i in range(n//2):
	odd.append(v[2*i+1])
	even.append(v[2*i])

odd = sorted(odd)
even = sorted(even)
def cnt(X):
	count = 0
	ans = 0
	for i in range(len(X)-1):
		if X[i+1] == X[i]:
			count += 1
			ans = max(ans,count)
		else:
			count = 0
	return ans+1
            
if odd == even:
  print(len(odd))
else:
  print(len(v)-cnt(odd)-cnt(even))

Submission status: Wrong Answer

Solution code:
# 2019/07/24

from collections import Counter

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

even=[]
odd=[]

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

e=Counter(even).most_common()[0][0]
o=Counter(odd).most_common()[0][0]

cnt=0
for i in range(n):
    if i%2==0 and v[i]!=e:cnt+=1
    elif i%2==1 and v[i]!=o:cnt+=1

print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
ans = 0
lia = v[::2]
lib = v[1::2]
tmp1 = len(lia)
tmp2 = len(lib)
lia.sort()
lib.sort()
if lia[0]==lib[-1]:
  print(n//2)
  exit()
lib.sort(reverse=True)
lia = collections.Counter(lia)
lib = collections.Counter(lib)
ans += tmp1-lia.most_common()[0][1]
ans += tmp2-lib.most_common()[0][1]
if lia.most_common()[0][1]%2==1 and lib.most_common()[0][1]%2==1:
  print(ans+1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
ans = 0
lia = v[::2]
lib = v[1::2]
tmp1 = len(lia)
tmp2 = len(lib)
lia.sort()
lib.sort()
if lia[0]==lib[-1]:
  print(n//2)
  exit()
lib.sort(reverse=True)
lia = collections.Counter(lia)
lib = collections.Counter(lib)
ans += tmp1-lia.most_common()[0][1]
ans += tmp2-lib.most_common()[0][1]
if lia.most_common()[0][1]%2==1 and lib.most_common()[0][1]:
  print(ans+1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
ans = 0
lia = v[::2]
lib = v[1::2]
lib.sort(reverse=True)
lia = collections.Counter(lia)
lib = collections.Counter(lib)
ans += n//2-lia.most_common()[0][1]
ans += n//2-lib.most_common()[0][1]
if lia==lib:
  print(n//2)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
ans = n
lia = v[::2]
lib = v[1::2]
lia = collections.Counter(lia)
lib = collections.Counter(lib)
ans -= lia.most_common()[0][1]
ans -= lib.most_common()[0][1]
if lia.most_common()[0][0] == lib.most_common()[0][0]:
  print(n//2)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
def func(li):
  n = 0
  for i in range(len(li)-1):
    if li[i]!=li[i+1]:
      n = len(li)-1-i
      break
  return n

n = int(input())
v = list(map(int,input().split()))
ans = 0
lia = v[::2]
lib = v[1::2]
lia.sort(reverse=True)
lib.sort(reverse=True)
ans += func(lia)
ans += func(lib)
if lia[0] == lib[0]:
  print(n//2)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
li = list(set(v))
li.sort()
for i in range(len(li)):
  li[i] = [li[i],v.count(li[i])]
li.sort(key=lambda x: x[1],reverse=True)
if len(li)==1:
  print(0)
else:
  ans = n-(li[0][1]+li[1][1])
  print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int, input().split()))
v1=v[0:n:2]
v2=v[1:n:2]
v10=collections.Counter(v1)
v11=v10.most_common()
v20=collections.Counter(v2)
v21=v20.most_common()
if v11[0][0]==v21[0][0] and v11[0][1]==n//2 and v21[0][1]==n//2:
    print(n//2)
else:
    x=n//2-v11[0][1]
    y=n//2-v21[0][1]
    print(x+y)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int, input().split()))
v1=v[0:n:2]
v2=v[1:n:2]
v10=collections.Counter(v1)
v11=v10.most_common()
v20=collections.Counter(v2)
v21=v20.most_common()
if v11[0][0]==v21[0][0] and v11[0][1]==n//2:
    print(n//2)
else:
    x=n//2-v11[0][1]
    y=n//2-v21[0][1]
    print(x+y)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int, input().split()))
v1=v[0:n:2]
v2=v[1:n:2]
v10=collections.Counter(v1)
v11=v10.most_common()
v20=collections.Counter(v2)
v21=v20.most_common()
if v11[0][0]==v21[0][0]:
    print(n//2)
else:
    x=abs(v11[0][1]-n//2)
    y=abs(v21[0][1]-n//2)
    print(x+y)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int, input().split()))
v1=collections.Counter(v)
v2=v1.most_common()
if v2[0][1]==n:
    print(n//2)
else:
    x=abs(v2[0][1]-n//2)
    y=abs(v2[1][1]-n//2)
    print(max(x,y))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

odd = v[::2]
even = v[1::2]

ac = Counter(odd).most_common(2)
bc = Counter(even).most_common(2)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

odd = v[::2]
even = v[1::2]

odd_c = Counter(odd).most_common(2)
even_c = Counter(even).most_common(2)

if odd_c[0][0] != even_c[0][0]:
    print(n-odd_c[0][1]-even_c[0][1])
else:
    if len(odd_c) == 1 or len(even_c) == 1:
        print(n//2)
    else:
        print(n-max(odd_c[0][1]-even_c[1][1], odd_c[1][1]-even_c[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

odd = v[::2]
even = v[1::2]

odd_c = Counter(odd).most_common(2)
even_c = Counter(even).most_common(2)

if odd_c[0][0] != even_c[0][0]:
    print(n-odd_c[0][1]-even_c[0][1])
else:
    if len(odd_c) == 1 and len(even_c) == 1:
        print(int(n/2))
    else:
        print(n-max(odd_c[0][1]-even_c[1][1], odd_c[1][1]-even_c[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

odd = v[::2]
even = v[1::2]

odd_c = Counter(odd).most_common(2)
even_c = Counter(even).most_common(2)

if odd_c[0][0] != even_c[0][0]:
    print(n-odd_c[0][1]-even_c[0][1])
else:
    if len(odd_c) == 1 or len(even_c) == 1:
        print(int(n/2))
    else:
        print(n-max(odd_c[0][1]-even_c[1][1], odd_c[1][1]-even_c[0][1]))

Submission status: Wrong Answer

Solution code:
import collections

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

odd = v[::2]
even = v[1::2]

odd_c = collections.Counter(odd)
even_c = collections.Counter(even)
ans = 0

if len(set(v)) == 1:
    print(int(n/2))
else:
    if len(odd) != max(odd_c.values()):
        ans += len(odd)-max(odd_c.values())
    if len(even) != max(even_c.values()):
        ans += len(even)-max(even_c.values())
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

odd = v[::2]
even = v[1::2]

odd_c = collections.Counter(odd)
even_c = collections.Counter(even)
ans = 0

if odd == even:
    print(int(len(v)/2))
else:
    if len(odd) != max(odd_c.values()):
        ans += len(odd)-max(odd_c.values())
    if len(even) != max(even_c.values()):
        ans += len(even)-max(even_c.values())
    print(ans)

Submission status: Wrong Answer

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

odd = set(v[::2])
even = set(v[1::2])
if odd == even:
    print(int(n/2))
else:
    print(len(odd)+len(even)-2)

Submission status: Wrong Answer

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

odd = set(v[::2])
even = set(v[1::2])
if odd == even:
    print(len(v)//2)
else:
    print(len(odd)+len(even)-2)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(map(int,input().split()))

import collections as col

x_e=[]
x_o=[]

for i in range(n):
	if i%2==0:
		x_e.append(x[i])
	else:
		x_o.append(x[i])

x_e_c=col.Counter(x_e).most_common()    
x_o_c=col.Counter(x_o).most_common()

if x_e_c[0][1]>x_o_c[0][1]:
	fst=x_e_c
	snd=x_o_c
else:
	fst=x_o_c
	snd=x_e_c

res=0

res+=n//2-fst[0][1]
if fst[0][0]!=snd[0][0]:
	res+=n//2-snd[0][1]
else:
	if len(snd)>1:
		res+=n//2-snd[1][1]
	else:
		res+=n//2

print(res)

Submission status: Wrong Answer

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

    v0 = assemble(v[::2])
    v1 = assemble(v[1::2])

    if len(v0) == 1 and len(v1) == 1:
        if v0[0][0] == v1[0][0]:
            print(n // 2)
        else:
            print(0)
        return
    elif len(v0) == 1:
        if v0[0][0] == v1[0][0]:
            print(sum_v(v1, 0))
        else:
            print(sum_v(v1, 1))
        return
    elif len(v1) == 1:
        if v0[0][0] == v1[0][0]:
            print(sum_v(v0, 0))
        else:
            print(sum_v(v0, 1))
        return

    score = [[0, 0], [0, 0]]
    for i in range(2):
        for j in range(2):
            score[i][j] = sum_v(v0, i) + sum_v(v1, j)
            if v0[i][0] == v1[j][0]:
                score[i][j] = 10 ** 9
    print(min([min(s) for s in score]))


def assemble(v):
    dct = {}
    for vel in v:
        if vel in dct:
            dct[vel] += 1
        else:
            dct[vel] = 1
    return sorted(list(dct.items()), key=lambda x: x[1], reverse=True)


def sum_v(v, ii):
    return sum([vv[1] for i, vv in enumerate(v) if i != ii])


main()

Submission status: Wrong Answer

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

    v0 = assemble(v[::2])
    v1 = assemble(v[1::2])

    if len(v0) == 1 and len(v1) == 1:
        if v0[0][0] == v1[0][0]:
            print(n // 2)
        else:
            print(0)
        return

    score = [[0, 0], [0, 0]]
    for i in range(2):
        for j in range(2):
            if i >= len(v0) or j >= len(v1):
                score[i][j] = 10 ** 9
                continue

            score[i][j] = sum_v(v0, i) + sum_v(v1, j)
            if v0[i][0] == v1[j][0]:
                score[i][j] = 10 ** 9
    print(min([min(s) for s in score]))


def assemble(v):
    dct = {}
    for vel in v:
        if vel in dct:
            dct[vel] += 1
        else:
            dct[vel] = 1
    return sorted(list(dct.items()), key=lambda x: x[1])


def sum_v(v, ii):
    return sum([vv[1] for i, vv in enumerate(v) if i != ii])


main()