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

array1 = v[::2]
array2 = v[1::2]

dict1 = {}
dict2 = {}
for i in array1:
  if i not in dict1:
    dict1[i] = 1
  else:
    dict1[i] = dict1[i] + 1

for i in array2:
  if i not in dict2:
    dict2[i] = 1
  else:
    dict2[i] = dict2[i] + 1

sort_array1 = []
sort_array2 = []
for k, v in sorted(dict1.items(), key=lambda x: -x[1]):
    sort_array1.append({k:v})
for k, v in sorted(dict2.items(), key=lambda x: -x[1]):
    sort_array2.append({k:v})

one_num1 = 0
one_num2 = 0

for k1,v1 in sort_array1[0].items():
  if len(sort_array1) != 1:
    one_num1 = len(array1) - v1
  for k2,v2 in sort_array2[0].items():
    if len(sort_array2) != 1:
      one_num2 = len(array2) - v2
    if k1 != k2:
      print(one_num1 + one_num2)
      break

    if len(sort_array1) == 1 and len(sort_array2) == 1:
      print(1)
      break
    if len(sort_array1) == 1:
      for k,v in sort_array2[1].items():
        two_num2 = v
      print(1+two_num2)
      break
    if len(sort_array2) == 1:
      for k,v in sort_array1[1].items():
        two_num1 = v
      print(1+two_num1)
      break

    for k,v in sort_array1[1].items():
      two_num1 = len(array1) - v
    for k,v in sort_array2[1].items():
      two_num2 = len(array2) - v
    if two_num1 <= two_num2:
      print (one_num2 + two_num1)
    else:
      print (one_num1 + two_num2)

Submission status: Wrong Answer

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

array1 = v[::2]
array2 = v[1::2]

dict1 = {}
dict2 = {}
for i in array1:
  if i not in dict1:
    dict1[i] = 1
  else:
    dict1[i] = dict1[i] + 1

for i in array2:
  if i not in dict2:
    dict2[i] = 1
  else:
    dict2[i] = dict2[i] + 1

sort_array1 = []
sort_array2 = []
for k, v in sorted(dict1.items(), key=lambda x: -x[1]):
    sort_array1.append({k:v})
for k, v in sorted(dict2.items(), key=lambda x: -x[1]):
    sort_array2.append({k:v})

one_num1 = 0
one_num2 = 0

print (sort_array1)
print (sort_array2)

for k1,v1 in sort_array1[0].items():
  if len(sort_array1) != 1:
    one_num1 = len(array1) - v1
  for k2,v2 in sort_array2[0].items():
    if len(sort_array2) != 1:
      one_num2 = len(array2) - v2
    if k1 != k2:
      print(one_num1 + one_num2)
      break

    if len(sort_array1) == 1 and len(sort_array2) == 1:
      print(1)
      break
    if len(sort_array1) == 1:
      for k,v in sort_array2[1].items():
        two_num2 = v
      print(1+two_num2)
      break
    if len(sort_array2) == 1:
      for k,v in sort_array1[1].items():
        two_num1 = v
      print(1+two_num1)
      break

    for k,v in sort_array1[1].items():
      two_num1 = len(array1) - v
    for k,v in sort_array2[1].items():
      two_num2 = len(array2) - v
    if two_num1 <= two_num2:
      print (one_num2 + two_num1)
    else:
      print (one_num1 + two_num2)

Submission status: Wrong Answer

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

array1 = v[::2]
array2 = v[1::2]

dict1 = {}
dict2 = {}
for i in array1:
  if i not in dict1:
    dict1[i] = 1
  else:
    dict1[i] = dict1[i] + 1

for i in array2:
  if i not in dict2:
    dict2[i] = 1
  else:
    dict2[i] = dict2[i] + 1

sort_array1 = []
sort_array2 = []
for k, v in sorted(dict1.items(), key=lambda x: -x[1]):
    sort_array1.append({k:v})
for k, v in sorted(dict2.items(), key=lambda x: -x[1]):
    sort_array2.append({k:v})

one_num1 = 0
one_num2 = 0

print (sort_array1)
print (sort_array2)

for k1,v1 in sort_array1[0].items():
  if len(sort_array1) != 1:
    one_num1 = len(array1) - v1
  for k2,v2 in sort_array2[0].items():
    if len(sort_array2) != 1:
      one_num2 = len(array2) - v2
    if k1 != k2:
      print(one_num1 + one_num2)
      break

    if len(sort_array1) == 1 and len(sort_array2) == 1:
      print(1)
      break
    if len(sort_array1) == 1:
      for k,v in sort_array2[1].items():
        two_num2 = v
      print(1+two_num2)
      break
    if len(sort_array2) == 1:
      for k,v in sort_array1[1].items():
        two_num1 = v
      print(1+two_num1)
      break

    for k,v in sort_array1[1].items():
      two_num1 = len(array1) - v
    for k,v in sort_array2[1].items():
      two_num2 = len(array2) - v
    if two_num1 <= two_num2:
      print (one_num1 + two_num2)
    else:
      print (one_num2 + two_num1)

Submission status: Wrong Answer

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

array1 = v[::2]
array2 = v[1::2]

dict1 = {}
dict2 = {}
for i in array1:
  if i not in dict1:
    dict1[i] = 1
  else:
    dict1[i] = dict1[i] + 1

for i in array2:
  if i not in dict2:
    dict2[i] = 1
  else:
    dict2[i] = dict2[i] + 1

sort_array1 = []
sort_array2 = []
for k, v in sorted(dict1.items(), key=lambda x: -x[1]):
    sort_array1.append({k:v})
for k, v in sorted(dict2.items(), key=lambda x: -x[1]):
    sort_array2.append({k:v})

one_num1 = 0
one_num2 = 0

for k1,v1 in sort_array1[0].items():
  if len(sort_array1) != 1:
    one_num1 = len(array1) - v1
  for k2,v2 in sort_array2[0].items():
    if len(sort_array2) != 1:
      one_num2 = len(array2) - v2
    if k1 != k2:
      print(one_num1 + one_num2)
      break

    if len(sort_array1) == 1 and len(sort_array2) == 1:
      print(1)
      break
    if len(sort_array1) == 1:
      for k,v in sort_array2[1].items():
        two_num2 = v
      print(1+two_num2)
      break
    if len(sort_array2) == 1:
      for k,v in sort_array1[1].items():
        two_num1 = v
      print(1+two_num1)
      break

    for k,v in sort_array1[1].items():
      two_num1 = v
    for k,v in sort_array2[1].items():
      two_num2 = v
    if two_num1 <= two_num2:
      print (one_num1 + two_num2)
    else:
      print (one_num2 + two_num1)

Submission status: Wrong Answer

Solution code:
n=int(input())
EVEN=[]
ODD=[]
TOTAL=[int(i) for i in input().split()]
for j in range(n):
  v=TOTAL[j]
  if j%2==0:
    EVEN.append(v)
  else:
    ODD.append(v)
EVEN_SET=list(set(EVEN))
ODD_SET=list(set(ODD))
n_e=0
n_o=0
for i in EVEN_SET:
  m=EVEN.count(i)
  n_e=max(m,n_e)
for i in ODD_SET:
  m=ODD.count(i)
  n_o=max(m,n_o)
if n_e==n and n_o==n:
  if EVEN_SET==ODD_SET:
    print(int(n/2))
  else:
    print(0)
else:
  print(n-n_e-n_o)

Submission status: Wrong Answer

Solution code:
n = int(input())
v_list = list(map(int, input().split()))
nums_even = {-1: 0}
nums_odd = {-1: 0}
for i, v in enumerate(v_list):
    if i % 2 == 0:
        nums_even.setdefault(v, 0)
        nums_even[v] += 1
    else:
        nums_odd.setdefault(v, 0)
        nums_odd[v] += 1
even_max = -1
even_max2 = -1
for key, val in nums_even.items():
    if val > nums_even[even_max]:
        even_max = key
    elif val > nums_even[even_max2]:
        even_max2 = key
odd_max = -1
odd_max2 = -1
for key, val in nums_odd.items():
    if val > nums_odd[odd_max]:
        odd_max = key
    elif val > nums_odd[odd_max2]:
        odd_max2 = key
if even_max != odd_max:
    print(n - nums_even[even_max] - nums_odd[odd_max])
else:
    m = max(nums_even[even_max] + nums_odd[odd_max2], nums_even[even_max2] + nums_odd[odd_max])
    print(n - m)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-

def solve():
    n = int(input())
    V = [None]
    V.extend(list(map(int, input().split(" "))))
    
    # 1種類の数字で構成されているか？
    tmp = V[1]
    flag = True
    for i in range(2, n+1):
        if tmp == V[i]:
            continue
        flag = False
        break
    if flag:
        print(int(n/2))
        return

    odd_dict = {}
    for i in range(1, n+1, 2):
        # 奇数番目のもので、最も多い数字を調べる
        if V[i] in odd_dict.keys():
            odd_dict[V[i]] += 1
            continue
        odd_dict[V[i]] = 1

    # 奇数番目のもので、最も多い数字は？
    ans = 0
    sorted_odds = sorted(odd_dict.items(), key=lambda x: x[1], reverse=True)
    odd_most = sorted_odds[0][1]
    ans += int(n/2) - odd_most

    even_dict = {}
    for i in range(2, n+1, 2):
        # 偶数番目のもので、最も多い数字を調べる
        if V[i] in even_dict.keys():
            even_dict[V[i]] += 1
            continue
        even_dict[V[i]] = 1
    
    # 偶数番目のもので、最も多い数字は？
    sorted_evens = sorted(even_dict.items(), key=lambda x: x[1], reverse=True)
    even_most = sorted_evens[0][1]
    ans += int(n/2) - even_most

    print(ans)



if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int,input().split()))
from collections import Counter as c

e,o = 0,0
ans = 0
E,O = [],[]
for v,i in zip(V,range(N)):
    if i%2 == 0:
        E.append(v)
    else:
        O.append(v)
EC = c(E).most_common()
OC = c(O).most_common()
n = N//2

EC01=EC[0][1]

OC01=OC[0][1]

if len(EC) == 1:
    EC11 = 0
else:
    EC11=EC[1][1]
if len(OC) == 1:
    OC11 = 0
else:
    OC11=OC[1][1]
if len(EC) == 1 and len(OC) == 1 and EC[0][0]==OC[0][0]:
    ans = EC01
elif EC01+OC11 > EC11+OC01:
    ans += n - EC01
    ans += n - OC11
elif EC01+OC11 < EC11+OC01:
    ans += n - EC11
    ans += n - OC01
elif EC01 == OC01:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def main():
	N = int(input())
	V = input().split(" ")
	
	K = []
	G = []
	for i, val in enumerate(V):
		if i % 2 == 0:
			G.append(val)
		else:
			K.append(val)
	
	k = collections.Counter(K)
	k = sorted(k.items(), key=lambda x:x[1], reverse=True)
	g = collections.Counter(G)
	g = sorted(g.items(), key=lambda x:x[1], reverse=True)
	
	aaa, bbb = k[0]
	ccc, ddd = g[0]
	
	if aaa == ccc:
		if bbb >= ddd and len(g) > 1:
			tmp1, tmp2 = g[1]
			g[0] = (tmp1, tmp2)
			g[1] = (ccc, ddd)
		elif bbb <= ddd and len(k) > 1:
			tmp1, tmp2 = k[1]
			k[0] = (tmp1, tmp2)
			k[1] = (aaa, bbb)
	
	#print(k)
	#print(g)
		
	ans = 0
	sono1 = 0
	sono2 = 0
	for a, b in enumerate(k):
		i, j = b
		if a == 0:
			sono1 = i
			continue
		ans += j
	
	for a, b in enumerate(g):
		i, j = b
		if a == 0:
			sono2 = i
			continue
		ans += j
		
	if ans > 0:
		print(ans)
	elif sono1 != sono2:
		print(ans)
	else:
		print(len(K))
		
		
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def main():
	N = int(input())
	V = input().split(" ")
	
	K = []
	G = []
	for i, val in enumerate(V):
		if i % 2 == 0:
			G.append(val)
		else:
			K.append(val)
	
	k = collections.Counter(K)
	k = sorted(k.items(), key=lambda x:x[1], reverse=True)
	g = collections.Counter(G)
	g = sorted(g.items(), key=lambda x:x[1], reverse=True)
	
	aaa, bbb = k[0]
	ccc, ddd = g[0]
	
	if aaa == ccc:
		if bbb > ddd and len(g) > 0:
			tmp1, tmp2 = g[1]
			g[0] = (tmp1, tmp2)
			g[1] = (ccc, ddd)
		elif bbb < ddd and len(k) > 0:
			tmp1, tmp2 = k[1]
			k[0] = (tmp1, tmp2)
			k[1] = (aaa, bbb)
	
	#print(k)
	#print(g)
		
	ans = 0
	sono1 = 0
	sono2 = 0
	for a, b in enumerate(k):
		i, j = b
		if a == 0:
			sono1 = i
			continue
		ans += j
	
	for a, b in enumerate(g):
		i, j = b
		if a == 0:
			sono2 = i
			continue
		ans += j
		
	if ans > 0:
		print(ans)
	elif sono1 != sono2:
		print(ans)
	else:
		print(len(K))
		
		
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def main():
	N = int(input())
	V = input().split(" ")
	
	K = []
	G = []
	for i, val in enumerate(V):
		if i % 2 == 0:
			G.append(val)
		else:
			K.append(val)
	
	k = collections.Counter(K)
	k = sorted(k.items(), key=lambda x:x[1], reverse=True)
	g = collections.Counter(G)
	g = sorted(g.items(), key=lambda x:x[1], reverse=True)
	
	#print(k)
	#print(g)
	
	aaa, bbb = k[0]
	ccc, ddd = g[0]
	
	if aaa == ccc and len(k) < 1:
		if bbb > ddd:
			tmp1, tmp2 = g[1]
			g[0] = (tmp1, tmp2)
			g[1] = (ccc, ddd)
		else:
			tmp1, tmp2 = k[1]
			k[0] = (tmp1, tmp2)
			k[1] = (aaa, bbb)
	
	ans = 0
	sono1 = 0
	sono2 = 0
	for a, b in enumerate(k):
		i, j = b
		if a == 0:
			sono1 = i
			continue
		ans += j
	
	for a, b in enumerate(g):
		i, j = b
		if a == 0:
			sono2 = i
			continue
		ans += j
		
	if ans > 0:
		print(ans)
	elif sono1 != sono2:
		print(ans)
	else:
		print(len(K))
		
		
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def main():
	N = int(input())
	V = input().split(" ")
	
	K = []
	G = []
	for i, val in enumerate(V):
		if i % 2 == 0:
			G.append(val)
		else:
			K.append(val)
	
	k = collections.Counter(K)
	k = sorted(k.items(), key=lambda x:x[1], reverse=True)
	g = collections.Counter(G)
	g = sorted(g.items(), key=lambda x:x[1], reverse=True)
	
	#print(k)
	#print(g)
	
	ans = 0
	sono1 = 0
	sono2 = 0
	for a, b in enumerate(k):
		i, j = b
		if a == 0:
			sono1 = i
			continue
		ans += j
	
	for a, b in enumerate(g):
		i, j = b
		if a == 0:
			sono2 = i
			continue
		ans += j
		
	if ans > 0:
		print(ans)
	elif sono1 != sono2:
		print(ans)
	else:
		print(len(K))
		
		
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def main():
	N = int(input())
	V = input().split(" ")
	
	K = []
	G = []
	for i, val in enumerate(V):
		if i % 2 == 0:
			G.append(val)
		else:
			K.append(val)
	
	k = collections.Counter(K)
	k = sorted(k.items(), key=lambda x:x[1], reverse=True)
	g = collections.Counter(G)
	g = sorted(g.items(), key=lambda x:x[1], reverse=True)
	
	#print(k)
	#print(g)
	
	ans = 0
	sono1 = 0
	sono2 = 0
	for a, b in enumerate(k):
		if a == 0:
			sono1 = a
			continue
		i, j = b
		ans += j
	
	for a, b in enumerate(g):
		if a == 0:
			sono2 = a
			continue
		i, j = b
		ans += j
		
	if ans > 0:
		print(ans)
	elif sono1 != sono2:
		print(ans)
	else:
		print(len(K))
		
		
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def main():
	N = int(input())
	V = input().split(" ")
	
	K = []
	G = []
	for i, val in enumerate(V):
		if i % 2 == 0:
			G.append(val)
		else:
			K.append(val)
	
	k = collections.Counter(K)
	k = sorted(k.items(), key=lambda x:x[1], reverse=True)
	g = collections.Counter(G)
	g = sorted(g.items(), key=lambda x:x[1], reverse=True)
	
	ans = 0
	sono1 = 0
	sono2 = 0
	for a, b in enumerate(k):
		if a == 0:
			sono1 = b
			continue
		i, j = b
		ans += j
	
	for a, b in enumerate(g):
		if a == 0:
			sono2 = b
			continue
		i, j = b
		ans += j
		
	if ans > 0:
		print(ans)
	elif sono1 != sono2:
		print(ans)
	else:
		print(len(K))
		
		
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left

def main():
	N = int(input())
	V = input().split(" ")
	
	K = []
	G = []
	for i, val in enumerate(V):
		if i % 2 == 0:
			G.append(val)
		else:
			K.append(val)
	
	k = collections.Counter(K)
	k = sorted(k.items(), key=lambda x:x[1], reverse=True)
	g = collections.Counter(G)
	g = sorted(g.items(), key=lambda x:x[1], reverse=True)
	
	ans = 0
	sono1 = 0
	sono2 = 0
	for a, b in enumerate(k):
		if a == 0:
			sono1 = b
			continue
		i, j = b
		ans += j
	
	for a, b in enumerate(g):
		if a == 0:
			sono2 = b
			continue
		i, j = b
		ans += j
		
	if ans > 0:
		print(ans)
	elif sono1 != sono2:
		print(ans)
	else:
		print(2)
		
		
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
from bisect import bisect_left

def main():
	N = int(input())
	V = input().split(" ")
	
	counts = 0
	syu_count = 0
	syu = V[0]
	for i in range(len(V)):
		if i == len(V)-2:
			break
		
		#print("{} {}".format(V[i], V[i+2]))
		if V[i] != V[i+2]:
			counts += 1
		if syu != V[i]:
			syu_count += 1
			
	if syu_count == 0:
		print(2)
	else:
		print(counts)
		
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*10**5
b=[0]*10**5
v=list(map(int,input().split()))
v1=[]
v2=[]
if len(set(v))==1:
    print(n//2)
else:
    for i in range(n):
        if i%2==0:
            a[v[i]-1]+=1
            v1.append(v[i])
        else:
            b[v[i]-1]+=1
            v2.append(v[i])
    max1=0
    max2=0
    for j in range(len(a)):
        if max1<a[j]:
            max1=a[j]
            c1=j
    for k in range(len(b)):
        if max2<b[k]:
            max2=b[k]
            c2=k
    if c1!=c2:
        print(len(v1)+len(v2)-max1-max2)
    else:
        if max1>=max2:
            b=sorted(b)
            print(len(v1)+len(v2)-max1-b[-2])
        else:
            a=sorted(a)
            print(len(v1)+len(v2)-max2-a[-2])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*10**5
b=[0]*10**5
v=list(map(int,input().split()))
v1=[]
v2=[]
if len(set(v))==1:
    print(n//2)
else:
    for i in range(n):
        if i%2==0:
            a[v[i]-1]+=1
            v1.append(v[i])
        else:
            b[v[i]-1]+=1
            v2.append(v[i])
    max1=max(a)
    max2=max(b)
    ans=len(v1)-max1+len(v2)-max2
    print(ans)

Submission status: Wrong Answer

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

mEven={"Z":0}
mOdd={"Z":0}

for i in range(0, n, 2):
	e = v[i]
	if e not in mEven:
		mEven[e] = 1
	else:
		mEven[e] += 1

for i in range(1, n+1, 2):
	e = v[i]
	if e not in mOdd:
		mOdd[e] = 1
	else:
		mOdd[e] += 1

lEven = sorted(mEven.items(), key=lambda x: x[1], reverse=True)
lOdd = sorted(mOdd.items(), key=lambda x: x[1], reverse=True)

if lEven[0][0] == lOdd[0][0]:
	if lEven[1] > lOdd[1]:
		lOdd.pop(0)
	else:
		lEven.pop(0)

print(n-lEven[0][1]-lOdd[0][1])

Submission status: Wrong Answer

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

mEven={"Z":0}
mOdd={"Z":0}

for i in range(0, n, 2):
	e = v[i]
	if e not in mEven:
		mEven[e] = 1
	else:
		mEven[e] += 1

for i in range(1, n, 2):
	e = v[i]
	if e not in mOdd:
		mOdd[e] = 1
	else:
		mOdd[e] += 1

lEven = sorted(mEven.items(), key=lambda x: x[1], reverse=True)
lOdd = sorted(mOdd.items(), key=lambda x: x[1], reverse=True)

if lEven[0][0] == lOdd[0][0]:
	if lEven[1] > lOdd[1]:
		lOdd.pop(0)
	else:
		lEven.pop(0)

print(n-lEven[0][1]-lOdd[0][1])

Submission status: Wrong Answer

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

mEven={"Z":0}
mOdd={"Z":0}

for i in range(0, n, 2):
	e = v[i]
	if e not in mEven:
		mEven[e] = 1
	else:
		mEven[e] += 1

for i in range(1, n, 2):
	e = v[i]
	if e not in mOdd:
		mOdd[e] = 1
	else:
		mOdd[e] += 1

lEven = sorted(mEven.items(), key=lambda x: x[1], reverse=True)
lOdd = sorted(mOdd.items(), key=lambda x: x[1], reverse=True)

if lEven[0] == lOdd[0]:
	if lEven[1] > lOdd[1]:
		lOdd.pop(0)
	else:
		lEven.pop(0)

print(n-lEven[0][1]-lOdd[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
from sys import stdin
n = int(stdin.readline().rstrip())
vl = [int(_) for _ in stdin.readline().rstrip().split()]
odds=Counter(vl[0::2]).most_common()
evens=Counter(vl[1::2]).most_common()
odd_f = odds[0]
even_f = evens[0]
if odd_f != even_f:
    print(n-odd_f[1]-even_f[1])
else:
    try:
        odd_se = odds[1]
    except:
        odd_se = [0,0]
    try:
        even_se = evens[1]
    except:
        even_se = [0,0]
    print(n - max(odd_f[1]+even_se[1], odd_se[1], even_f[1]))

Submission status: Wrong Answer

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

vv = list(set(v))

if len(vv) >= 2:
    vvv = vv.copy()

    min = 10**6
    for i in vv:
        vvv.remove(i)
        for j in vvv:
            if 10-(v.count(i)+v.count(j)) > min:
                pass
            else:
                ct = 0
                a = [i if k % 2 == 0 else j for k in range(n)]
                print(' '.join(a))
                for k in range(n):
                    if a[k] != v[k]:
                        ct += 1
                if ct < min:
                    min = ct
        vvv.append(i)
    print(min)
else:
    print(int(n/2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

vv = list(set(v))
vvv = vv.copy()

min = 10**6
for i in vv:
    vvv.remove(i)
    for j in vvv:
        ct = 0
        a = [i if k % 2 == 0 else j for k in range(n)]
        for k in range(n):
            if a[k] != v[k]:
                ct += 1
        if ct < min:
            min = ct
    vvv.append(i)
print(min)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
v = list(map(int,input().rstrip().split()))
list_odd = v[0::2]
list_even = v[1::2]

odd_count = collections.Counter(list_odd)
even_count = collections.Counter(list_even)


max_flq_odd = [kv for kv in odd_count.items() if kv[1] == max(odd_count.values())]
max_flq_even = [kv for kv in even_count.items() if kv[1] == max(even_count.values())]

if max_flq_odd == max_flq_even:
    print(N//2)
else:
    print(N-max_flq_odd[0][1]-max_flq_even[0][1])

Submission status: Wrong Answer

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

vv = list(set(v))

min = 10**6
for i in vv:
    vvv = vv.copy()
    vvv.remove(i)
    for j in vvv:
        ct = 0
        a = [i if k % 2 == 0 else j for k in range(n)]
        for k in range(n):
            if a[k] != v[k]:
                ct += 1
        if ct < min:
            min = ct
print(min)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(m) for m in input().split()]
a = v[::2]
b = v[1::2]
a = sorted(a)
b = sorted(b)
atop = a[0]
btop = b[0]

countera1 = a.count(a[0])
countera2 = 0
counterb1 = b.count(b[0])
counterb2 = 0

ia = 0
ib = 0

while len(a) > 0:
	i = 0
	while a[0] == a[i]:
		i += 1
		if i >= len(a) - 1:
			break
	acount = i

	if acount > countera1:
		countera1, countera2 = acount, countera1
		atop = a[0]
	elif acount > countera2 and ia != 0:
		countera2 = acount
		ia += 1
	a = a[acount:]

while len(b) > 0:
	j = 0
	while b[0] == b[j]:
		j += 1
		if j >= len(b) - 1:
			break
	bcount = j
	if bcount > counterb1:
		counterb1, counterb2 = bcount, counterb1
		btop = b[0]
		counterb2 = bcount
	elif bcount > counterb2 and ib != 0:
		ib += 1
	b = b[bcount:]
if atop == btop:
	if countera1 + counterb2 > counterb1 + countera2:
		print(n - (countera1 + counterb2))
	else:
		print(n - (countera2 + counterb1))
else:
	print(n - countera1 - counterb1)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(m) for m in input().split()]
a = []
b = []
for i in range(n):
	if i % 2 == 0:
		a.append(v[i])
	else:
		b.append(v[i])

a = sorted(a)
b = sorted(b)

atop = a[0]
btop = b[0]
atop2 = 0
btop2 = 0
acurrent = a[0]
bcurrent = b[0]
countera1 = a.count(a[0])
countera2 = 0
counterb1 = b.count(b[0])
counterb2 = 0
ia = 0
ib = 0

while len(a) > 0:
	acount = a.count(a[0])
	if acount > countera1:
		countera1, countera2 = acount, countera1
		atop, atop2 = a[0], atop
	elif acount > countera2 and ia != 0:
		countera2 = acount
		atop2 = a[0]
		ia += 1
	a = a[acount:]

while len(b) > 0:
	bcount = b.count(b[0])
	if bcount > counterb1:
		counterb1, counterb2 = bcount, counterb1
		btop, btop2 = b[0], btop
	elif bcount > counterb2 and ib != 0:
		counterb2 = bcount
		btop2 = b[0]
		ib += 1
	b = b[bcount:]
if atop == btop:
	if countera1 + counterb2 > counterb1 + countera2:
		print(n - (countera1 + counterb2))
	else:
		print(n - (countera2 + counterb1))
else:
	print(n - countera1 - counterb1)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
lst = list(map(int,input().split()))
odd = [0]*(n//2)
even = [0]*(n//2)
leng = 0
for i in range(n//2):
    odd[i]=lst[leng]
    leng+=1
    even[i]=lst[leng]
    leng+=1
o = collections.Counter(odd).most_common()[0]
e = collections.Counter(even).most_common()[0]
if o[0] != e[0]:
    ans = n - (o[1] + e[1])
else:
    ans = n // 2

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
vs = list(map(int, input().split()))
veven = vs[0:n:2]
vodd = vs[1:n:2]
mins = []
flag = False
if veven == vodd:
    print(n //2)
else:
    ce = collections.Counter(veven)
    co = collections.Counter(vodd)
    cem = ce.most_common()
    com = co.most_common()
    for i, j in cem:
        for k, h in com:
            if i != k:
                mins.append(n-j-h)
                flag = True
                break
        if flag:
            break
    flag = False
    for i, j in com:
        for k, h in cem:
            if i != k:
                mins.append(n-j-h)
                flag = True
                break
        if flag:
            break
    print(min(mins))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
vs = list(map(int, input().split()))
veven = vs[0:n:2]
vodd = vs[1:n:2]
mins = []
flag = False
if veven == vodd:
    print(n //2)
else:
    ce = collections.Counter(veven)
    co = collections.Counter(vodd)
    cem = ce.most_common()
    com = co.most_common()
    for i, j in cem:
        for k, h in com:
            if i != k:
                mins.append(n-j-h)
                flag = True
                break
        if flag:
            break
    for i, j in com:
        for k, h in cem:
            if i != k:
                mins.append(n-j-h)
                flag = True
                break
        if flag:
            break
    print(min(mins))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()
v = LIST()

v_odd = sorted([v[i] for i in range(n) if i % 2 == 1])
v_even = sorted([v[i] for i in range(n) if i % 2 == 0])

count_odd = Counter(v_odd)
count_even = Counter(v_even)

if count_odd.most_common()[0][0] != count_even.most_common()[0][0]:
	print(int(n/2-count_odd.most_common()[0][1] + n/2 - count_even.most_common()[0][1]))
else:
	if len(count_odd) == 1 and len(count_even) == 1:
		print(int(n/2))
	else:
		if len(count_odd) == 1:
			print(int(n/2 - count_even.most_common()[1][1]))
		elif len(count_even) == 1:
			print(int(n/2 - count_odd.most_common()[1][1]))
		else:
			tmp1 = int(n/2-count_odd.most_common()[1][1] + n/2 - count_even.most_common()[0][1])
			tmp2 = int(n/2-count_odd.most_common()[0][1] + n/2 - count_even.most_common()[1][0])
			print(min(tmp1, tmp2))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()
v = LIST()

v_odd = [v[i] for i in range(n) if i % 2 == 1]
v_even = [v[i] for i in range(n) if i % 2 == 0]

count_odd = Counter(v_odd)
count_even = Counter(v_even)

if count_odd.most_common()[0][0] != count_even.most_common()[0][0]:
	print(int(n/2-count_odd.most_common()[0][1] + n/2 - count_even.most_common()[0][1]))
else:
	if len(count_odd) == 1 and len(count_even) == 1:
		print(int(n/2))
	else:
		if len(count_odd) == 1:
			print(int(n/2 - count_even.most_common()[1][1]))
		elif len(count_even) == 1:
			print(int(n/2 - count_odd.most_common()[1][1]))
		else:
			tmp1 = int(n/2-count_odd.most_common()[1][1] + n/2 - count_even.most_common()[0][1])
			tmp2 = int(n/2-count_odd.most_common()[0][1] + n/2 - count_even.most_common()[1][0])
			print(min(tmp1, tmp2))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()
v = LIST()

v_odd = [v[i] for i in range(n) if i % 2 == 1]
v_even = [v[i] for i in range(n) if i % 2 == 0]

count_odd = Counter(v_odd)
count_even = Counter(v_even)

if count_odd.most_common()[0][0] != count_even.most_common()[0][0]:
	print(int(n/2-count_odd.most_common()[0][1] + n/2 - count_even.most_common()[0][1]))
else:
	if len(count_odd) == 1 and len(count_even) == 1:
		print(int(n/2))
	else:
		if len(count_odd) == 1:
			print(int(n/2 - count_even.most_common()[0][1]))
		elif len(count_even) == 1:
			print(int(n/2 - count_odd.most_common()[0][1]))
		else:
			tmp1 = int(n/2-count_odd.most_common()[1][1] + n/2 - count_even.most_common()[0][1])
			tmp2 = int(n/2-count_odd.most_common()[0][1] + n/2 - count_even.most_common()[1][0])
			print(min(tmp1, tmp2))