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: Runtime Error

Solution code:
n = int(input())

a = list(map(int, input().split()))


dict_odd = {}
dict_even = {}

for i in range(n):
  #リストの奇数番目、０始まりなのであまりは０
  if i %2 == 0:
    dict_odd[a[i]] = dict_odd.get(a[i], 0) + 1
  else:
    dict_even[a[i]] = dict_even.get(a[i], 0) + 1
    
#print(dict_odd, dict_even)    

v_odd_sorted = sorted(dict_odd.values())
v_even_sorted = sorted(dict_even.values())

odd_sorted = sorted(dict_odd.items(), key=lambda x : x[1])
even_sorted = sorted(dict_even.items(), key=lambda x : x[1])

#print(v_odd_sorted, v_even_sorted)    
ans = 0
#数字が一種類しかない場合は、一方を置き換える必要がある
if len(set(a)) == 1:
  for i in range((n//2)-1):
    ans += odd_sorted[i][1]
  #print(sum(v_odd_sorted))
else:
  #偶数列と奇数列について、書き換えた後が同じ数字なら成立しないので、一方の書き換える先を次に多い数字にする
  if odd_sorted[-1][0] == even_sorted[-1][0]:
    if odd_sorted[-1][1] >= even_sorted[-1][1]:
      #偶数列を変更したほうが少ない場合
      ans = sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-2]) + v_even_sorted[-1]
    else:
      #奇数列を変更したほうが少ない場合
      ans = sum(v_even_sorted[:-1]) + sum(v_odd_sorted[:-2]) + v_odd_sorted[-1]
  else:
    ans = sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-1])
  #print(sum(v_odd_sorted[:-1]) + sum(v_even_sorted[:-1]))
print(ans)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
c_odd  = collections.Counter(v[::2])
c_even = collections.Counter(v[1::2])
odd    = c_odd.most_common()[:2]
even   = c_even.most_common()[:2]
if (len(odd) == 1) & (len(even) == 1):
	if odd[0][0] == even[0][0]:
		ans = odd[0][1]
	else:
		ans = 0
elif len(odd) == 1:
	if odd[0][0] == even[0][0]:
		ans = n - odd[0][1] - even[1][1]
	else:
		ans = n - odd[0][1] - even[0][1]
elif len(even) == 1:
	if odd[0][0] == even[0][0]:
		ans = n - odd[1][1] - even[0][1]
	else:
		ans = n - odd[0][1] - even[0][1]
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
v = list(map(int,input().split()))
w = v[0::2]
z = v[1::2]

ww = set(w)
zz = set(z)

x = list(map(ww.count,ww))
y = list(map(zz.count,zz))

if len(x) == 1 and len(y) == 1 and w != z:
  print(0)
elif len(x) == 1 and len(y) == 1 and w == z:
  print(n//2)
else:
  print(sum(x)-max(x)+sum(y)-max(y))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

counted_v1 = Counter(v[::2])
counted_v2 = Counter(v[1::2])

most_v1 = counted_v1.most_common()[0]
most_v2 = counted_v2.most_common()[0]

if  most_v1[0] != most_v2[0]:
    print(n - most_v1[1] - most_v2[1])


elif len(counted_v1) == 1 and len(counted_v2) == 1:
    print(n // 2)

elif most_v1[1] > most_v2[1]:
    second_v2 = counted_v2.most_common()[1] if len(counter_v2) >= 2 else most_v2[1]
    print(n - most_v1[1] - second_v2[1])

else:
    second_v1 = counted_v1.most_common()[1] if len(counter_v1) >= 2 else most_v1[1]
    print(n - second_v1[1] - most_v2[1])

Submission status: Runtime Error

Solution code:
n = input()
v = [int(x) for x in input().split()]
w = v[0::2]
z = v[1::2]

x = [w.count(a) for a in set(w)]
y = [z.count(a) for a in set(z)]

if len(x) == 1 and len(y) == 1:
  print(0)
  exit()
elif len(x) == 1:
  print(min(y))
  exit()
elif len(y) == 1:
  print(min(X))
  exit()
else:
  print(min(X)+min(y))

Submission status: Runtime Error

Solution code:
n = int(input())
v = [i for i in input().split()]

e,o = v[0],v[1]
v = list(set(v))

v.remove(e)
if v:
    v.remove(o)
    print(len(v))
else:
    print(n//2)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
V = input().split(' ')

EVEN = V[0::2]
ODD = V[1::2]
EVEN_V = collections.Counter(EVEN)
ODD_V = collections.Counter(ODD)
Count_EVEN_V = EVEN_V.most_common()
Count_ODD_V =ODD_V.most_common()


if Count_EVEN_V[0][1] >= Count_ODD_V[0][1]:
  MAX_ELE = Count_EVEN_V[0][0]
  count_max = Count_EVEN_V[0][1]
  for i in range(int(N/2)):
    if MAX_ELE != Count_ODD_V[i][1]:
      SECOND_ELE = Count_ODD_V[i][0]
      count_SEC = Count_ODD_V[i][1]
      break
    else:
      pass
  
else:
  MAX_ELE = Count_ODD_V[0][0]
  count_max = Count_ODD_V[0][1]
  for i in range(N/2):
    if MAX_ELE != Count_EVEN_V[i][1]:
      SECOND_ELE = Count_EVEN_V[i][0]
      count_SEC = ount_EVEN_V[i][1]
      break
    else:
      pass
print((N- int(count_max) - int(count_SEC)))

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(map(int,input().split()))
d1=dict()
d2=dict()
for i in range(0,n,2):
  if i not in d1:
    d1[i]=1
  else:
    d1[i]+=1
for i in range(1,n,2):
  if i not in d2:
    d2[i]=1
  else:
    d2[i]+=1
dmk,dm,dmmk,dmm=[],0,[],0
for i in d1.keys():
  if dm<d1[i]:
    dmm=dm
    dmmk=dmk
    dm=d1[i]
    dmk=[i]
  elif d1==d1[i]:
    dmk+=[i]
  elif dmm<d1[i]:
    dmm=d1[i]
    dmmk=[i]
  elif dmm=d1[i]:
    dmmk+=[i]
d1=[len(dmk),len(dmmk)]
dmk,dm,dmmk,dmm=[],0,[],0
for i in d2.keys():
  if dm<d2[i]:
    dmm=dm
    dmmk=dmk
    dm=d2[i]
    dmk=[i]
  elif d2==d2[i]:
    dmk+=[i]
  elif dmm<d2[i]:
    dmm=d2[i]
    dmmk=[i]
  elif dmm=d2[i]:
    dmmk+=[i]
d2=[len(dmk),len(dmmk)]
if d1[0]>1 or d2[0]>1:
  print(n-d1[0]-d2[0])
else:
  print(n-max(d1[0]+d2[1],d1[1]+d2[0]))

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
vo=v[0::2]
ve=v[1::2]
co=collections.Counter(vo)
ce=collections.Counter(ve)
cmo=co.most_common()
cme=ce.most_common()
ans=n-cmo[0][1]-cme[0][1]
if cmo[0][0]==cme[0][0]:
    if cmo[0][1]>cme[0][1]:
       if cmo[0][1]!=n//2:
           ans=n-cmo[0][1]-cme[1][1]
    elif cmo[0][1]<cme[0][1]:
        if cme[0][1]!=n//2:
            ans=n-cmo[1][1]-cme[0][1]
    else:
        ans=n-cmo[0][1]-max(cmo[1][1],cme[1][1])
print(ans)

Submission status: Runtime Error

Solution code:
import heapq

n = int(input())
v = list(map(int,input().split()))
a_odd = []
a_even = []
check_a_odd = []
check_a_even = []
count_a_odd = []
count_a_even = []

for i in range(len(v)):
    if i%2 == 0:
        a_odd.append(v[i])
    else:
        a_even.append(v[i])

#print(a_odd)
#print(a_even)

for j in range(int(n/2)):
    if a_odd[j] not in check_a_odd:
        count_a_odd.append([-1*a_odd.count(a_odd[j]),a_odd[j]])
        check_a_odd.append(a_odd[j])
    if a_even[j] not in check_a_even:
        count_a_even.append([-1*a_even.count(a_even[j]),a_even[j]])
        check_a_even.append(a_even[j])
count_a_odd.sort()
count_a_even.sort()

#count_a_odd.append([0,0])
#count_a_even.append([0,0])

print(count_a_odd)
print(count_a_even)

if int(count_a_odd[0][1]) != int(count_a_even[0][1]):
    print(n + int(count_a_odd[0][0]) + int(count_a_even[0][0]))
else:
    ans1 = n + int(count_a_odd[0][0]) + int(count_a_even[1][0])
    ans2 = n + int(count_a_odd[1][0]) + int(count_a_even[0][0])
    print(min(ans1,ans2))

Submission status: Runtime Error

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

vv = [[], []]
for i in range(n):
    vv[i % 2].append(v[i])

import collections
items0 = sorted(collections.Counter(vv[0]).items(), key=lambda x: -x[1])
items1 = sorted(collections.Counter(vv[1]).items(), key=lambda x: -x[1])
key0 = [x[0] for x in items0]
key1 = [x[0] for x in items1]
val0 = [x[1] for x in items0]
val1 = [x[1] for x in items1]

if key0[0] == key1[0]:
    if len(items0) == 1:
        print(n//2)
    else:
        print(min(n - val0[0] - val1[1], min(n - val0[1] - val1[0])))
else:
    print(n - val0[0] - val1[0])

Submission status: Runtime Error

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

vv = [[], []]
for i in range(n):
    vv[i % 2].append(v[i])

import collections
items0 = sorted(collections.Counter(vv[0]).items(), key=lambda x: -x[1])
items1 = sorted(collections.Counter(vv[1]).items(), key=lambda x: -x[1])
key0 = [x[0] for x in items0]
key1 = [x[0] for x in items1]
val0 = [x[1] for x in items0]
val1 = [x[1] for x in items1]

if key0[0] = ! key1[0]:
    if len(items0) == 1:
        print(n//2)
    else:
        print(min(n - val0[0] - val1[1], min(n - val0[1] - val1[0])))
else key0[0] != key1[0]:
    print(n - val0[0] - val1[0])

Submission status: Runtime Error

Solution code:
from collections import Counter

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

va = v[::2]
vb = v[1::2]

va_ = Counter(va).most_common(2)
vb_ = Counter(vb).most_common(2)

if va_[0][0] == vb_[0][0]:
    if va_[0][1] + vb_[1][1] > va_[1][1] + vb_[0][1]:
        print(len(va) - va_[0][1] + len(vb) - vb_[1][1])
    else:
        print(len(va) - va_[1][1] + len(vb) - vb_[0][1])
else:
    print(len(va) - va_[0][1] + len(vb) - vb_[0][1])

Submission status: Runtime Error

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(len(array1))
      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: Runtime Error

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

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: Runtime Error

Solution code:
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: Runtime Error

Solution code:
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(EC01,EC11,OC01,OC11)
print(ans)

Submission status: Runtime Error

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: Runtime Error

Solution code:
n = int(input())

odd = range(0,n,2)
even = range(1,n+1,2)

v = list(map(int,input().split()))
odd_list = len(odd)*[0]
even_list = len(even)*[0]
for i, odd_num in enumerate(odd):
    odd_list[i] = v[odd_num]
for i, even_num in enumerate(even):
    even_list[i] = v[even_num]

ans = 0

for list_ in [odd_list, even_list]:
    unique_list = []
    for i in list_:
        if i not in unique_list:
            unique_list.append(i)
    count_list = len(unique_list)*[0]
    unique_list_all.append(unique_list)
    for i,unique_num in enumerate(unique_list):
        count_list[i] = list_.count(unique_num)
    ans += sum(count_list)
    ans -= max(count_list)

if all(v[i] == v[0] for i in range(n)):
    print(int(n/2))
else:
    print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

odd = range(0,n,2)
even = range(1,n+1,2)

v = list(map(int,input().split()))
odd_list = len(odd)*[0]
even_list = len(even)*[0]
for i, odd_num in enumerate(odd):
    odd_list[i] = v[odd_num]
for i, even_num in enumerate(even):
    even_list[i] = v[even_num]

ans = 0

for list_ in [odd_list, even_list]:
    unique_list = []
    for i in list_:
        if i not in unique_list:
            unique_list.append(i)
    count_list = len(unique_list)*[0]
    unique_list_all.append(unique_list)
    for i,unique_num in enumerate(unique_list):
        count_list[i] = list_.count(unique_num)
        ans += sum(count_list)
        ans -= max(count_list)

if all(v[i] == v[0] for i in range(n)):
    print(int(n/2))
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
v = list(map(int,input().rstrip().split()))
list_odd = v[1::2]
list_even = v[0::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[0][0] != max_flq_even[0][0] or len(max_flq_odd) > 1 or len(max_flq_even) > 1:
    #最大値のキーが違うものは最初にはじいた方が良い？
    print(N-max_flq_odd[0][1]-max_flq_even[0][1])
elif len(odd_count) == 1 and len(even_count) == 1:
    #数字が一種類しかない
    print(N//2)
elif len(odd_count) == 1:
    even_count.pop(max_flq_even[0][0])
    secondmax_even = max(even_count.values())
    print(N//2-secondmax_even)
elif len(even_count) == 1:
    odd_count.pop(max_flq_odd[0][0])
    secondmax_odd = max(odd_count.values())
    print(N//2-secondmax_odd)
else:
    even_count.pop(max_flq_even[0][0])
    secondmax_even = max(even_count.values())
    odd_count.pop(max_flq_odd[0][0])
    secondmax_odd = max(odd_count.values())
    print(min(N-max_flq_odd-secondmax_even, N-max_flq_even-secondmax_odd))

Submission status: Runtime Error

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 odd_count == even_count and len(odd_count) == 1:
    #数字が一種類しかない
    print(N//2)
elif max_flq_odd == max_flq_even and len(max_flq_odd) == 1:
    #最大値が同じで一種類しかない
    odd_wo_max = [kv for kv in odd_count if kv[1] != max(odd_count.values())]
    secondmax_odd = [kv for kv in odd_wo_max.items() if kv[1] == max(odd_wo_max.values())]
    even_wo_max = [kv for kv in odd_count if kv[1] != max(odd_count.values())]
    secondmax_even = [kv for kv in even_wo_max.items() if kv[1] == max(even_wo_max.values())]
    secondmax = max(secondmax_odd,secondmax_even)
    print(N-max_flq_odd-secondmax)
else:
    #最大値が違うか、最大値をとるキーが複数あり代替がきく
    print(N-max_flq_odd[0][1]-max_flq_even[0][1])

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
i_num = 0
two_0 = []
two_1 = []
for i in v:
    if i_num % 2 == 0:
        two_0.append(i)
    else:
        two_1.append(i)
    i_num += 1
two_1_counter = Counter(two_1)
t1_elem = two_1_counter.most_common()[0][0]
t1 = two_1_counter.most_common()[0][1]
two_0_counter = Counter(two_0)
if two_0_counter.most_common()[0][0] == t1_elem:
    if two_0_counter.most_common()[0][1] != len(two_0):
        if two_1_counter.most_common()[0][0] == len(two_1):
            if two_0_counter.most_common()[1][1] > two_1_counter.most_common()[1][1]:
                t0 = two_0_counter.most_common()[1][1]
            else:
                t1 = two_1_counter.most_common()[1][1]
        else:
            t1 = 0
    else:
        t0 = 0
else:
    t0 = two_0_counter.most_common()[0][1]
print(n - (t0+t1))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
i_num = 0
two_0 = []
two_1 = []
for i in v:
    if i_num % 2 == 0:
        two_0.append(i)
    else:
        two_1.append(i)
    i_num += 1
two_1_counter = Counter(two_1)
t1_elem = two_1_counter.most_common()[0][0]
t1 = two_1_counter.most_common()[0][1]
two_0_counter = Counter(two_0)
if two_0_counter.most_common()[0][0] == t1_elem:
    if two_0_counter.most_common()[0][1] != len(two_0):
        if two_0_counter.most_common()[1][1] > two_1_counter.most_common()[1][1]:
            t0 = two_0_counter.most_common()[1][1]
        else:
            t1 = two_1_counter.most_common()[1][1]
    else:
        t0 = 0
else:
    t0 = two_0_counter.most_common()[0][1]
print(n - (t0+t1))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

mo = cnt_o[0][0]
me = cnt_e[0][0]
if mo == me:
    print(n - cnt_o[0][1] - cnt_e[0][1])
else:
    del1 = cnt_o[0][1] - cnt_o[1][1]
    del2 = cnt_e[0][1] - cnt_e[1][1]
    print(n - cnt_o[0][1] - cnt_e[0][1] + min(del1, del2))

Submission status: Runtime Error

Solution code:
import bisect
from collections import deque
from collections import defaultdict
#from math import factorial
from math import sqrt
n=int(input())
v=map(int,input().split())

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

A=defaultdict(int)
B=defaultdict(int)
for i in a:
    A[i]+=1
for i in b:
    B[i]+=1
A[0]=0
B[0]=0
Amax=0
Akey=0
Bmax=0
Bkey=0

for key in A.keys():
    if Amax<A[key]:
        Akey=key
        Amax=A[key]
for key in B.keys():
    if Bmax<B[key]:
        Bkey=key
        Bmax=B[key]
min=10**5
n_=n/2
for i in B.keys():
    min_=(n_-Amax)+(n_-B[i])
    if Akey!=i and min>min_:
        min=min_
for i in A.keys():
    min_=(n_-A[i])+(n_-Bmax)
    if Bkey!=i and min>min_:
        min=min_
print(min)

Submission status: Runtime Error

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

from statistics import mode

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

g = []
k = []

for i in range(n):
    if i % 2 == 1:
        k.append(v[i])
    else:
        g.append(v[i])

kave = mode(k)
gave = mode(g)
if kave == gave:
    kave += 1

print(kave)
print(gave)

ans = 0

for i in range(len(k)):
    if k[i] != kave:
        ans += 1
    if g[i] != gave:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
v = [int(_) for _ in input().split()]
oddcnt = [[0, i] for i in range(1, 10**5+1)]
evencnt = [[0, i] for i in range(1, 10**5+1)]

for i, j in enumerate(v):
    if i % 2 == 0:
        oddcnt[j][0] += 1
    else:
        evencnt[j][0] += 1

oddcnt = sorted(oddcnt, key=lambda x: (-x[0], x[1]))
evencnt = sorted(evencnt, key=lambda x: (-x[0], -x[1]))

if oddcnt[0][1] != evencnt[0][1]:
    print(n-oddcnt[0][0]-evencnt[0][0])
elif oddcnt[0][0] > evencnt[0][0]:
    print(n-oddcnt[0][0]-evencnt[1][0])
else:
    print(n-oddcnt[1][0]-evencnt[0][0])

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
vs = input().split()
even = []
odd = []
if not even == odd:
  for i, v in enumerate(vs):
  	if i % 2 == 0:
    	even.append(int(v))
    else:
    	odd.append(int(v))
  counter_even = Counter(even)
  counter_odd = Counter(odd)

  res = len(even) - counter_even.most_common()[0][1] + len(odd) - counter_odd.most_common()[0][1] 
else:
  res = len(even)
print(res)

Submission status: Runtime Error

Solution code:
from operator import itemgetter
from collections import Counter
def main():
    va = []
    vb = []
    n = int(input())
    *v, = map(int, input().split())
    for i in range(len(v)):
        if i % 2 == 0:
            va.append(v[i])
        else:
            vb.append(v[i])
    a1 = Counter(va).most_common()
    a2 = Counter(vb).most_common()
    how_many_a1 = a1[0][1]
    how_many_a2 = a2[0][1]
    if a1[0][0] != a2[0][0]:
        print(n - how_many_a1 - how_many_a2)
    else:
        if (len(va) - how_many_a1) + (len(vb) - how_many_a2[0][1])  > (len(vb) - how_many_a2) + (len(va) - how_many_a1[0][1]):
            print((len(vb) - how_many_a2) + (len(va) - how_many_a1[0][1]))
        else:
            print((len(va) - how_many_a1) + (len(vb) - how_many_a2[0][1]))
main()

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
V = list(int(i) for i in input().split())
even = V[0::2]
odd =  V[1::2]
all_length = len(V)
even = collections.Counter(even).most_common(2)
odd = collections.Counter(odd).most_common(2)
if (even[0][0] != odd[0][0]):
    print(all_length - even[0][1] - odd[0][1])
else:
    if(len(even)==1 and len(odd)==1):
        print(all_length//2)
    elif(len(even)==1):
        print(all_length - odd[0][1])
    elif(len(odd)==1):
        print(all_length - even[0][1])    
    else:
        print(min(all_length - even[0][1] - odd[0][2], all_length - even[0][2] - odd[0][1]))

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
V = list(int(i) for i in input().split())
even = V[0::2]
odd =  V[1::2]
all_length = len(V)
even = collections.Counter(even).most_common(2)
odd = collections.Counter(odd).most_common(2)
if (even[0][0] != odd[0][0]):
    print(all_length - even[0][1] - odd[0][1])
else:
    if not(len(even)!=1 and len(odd)!=1):
        print(min(all_length - even[0][1] - odd[0][2], all_length - even[0][2] - odd[0][1]))
    elif(len(even)==1):
        print(all_length - odd[0][1])
    else:
        print(all_length - even[0][1])

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
V = list(int(i) for i in input().split())
even = V[0::2]
odd =  V[1::2]
all_length = len(V)
even = collections.Counter(even).most_common(2)
odd = collections.Counter(odd).most_common(2)
if (even[0][0] != odd[0][0]):
    print(all_length - even[0][1] - odd[0][1])
else:
    out1 = all_length - even[0][1] - odd[0][2]
    out2 = all_length - even[0][2] - odd[0][1]
    if(out1 > out2):
        print(out2)
    else:
        print(out1)

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
V = list(int(i) for i in input().split())
even = V[0::2]
odd =  V[1::2]
half_count = len(even)
even = collections.Counter(even).most_common(1)
even_elem = even[0][0]
even_count = even[0][1]
odd = collections.Counter(odd).most_common(1)
odd_elem = odd[0][0]
odd_count = odd[0][1]

if (even_count > odd_count):
    print((half_count - even_count) + (half_count + len(odd.count(even_elem))))
elif (even_count < odd_count):
    print((half_count - odd_count) + (half_count + len(even.count(odd_elem))))
else:
    print(0)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
v1 = v[::2]
v2 = v[1::2]
c1 = collections.Counter(v1).most_common()
c2 = collections.Counter(v2).most_common()

if c1[0][0] != c2[0][0]:
  print(len(v1)-c1[0][1] + len(v2)-c2[0][1])
else:
  if len(set(v1)) == len(set(v2)) == 1:
    print(min(len(v1), len(v2)))
  elif len(set(v1))==1:
    print(len(v2)-c2[1][1])
  elif len(set(v2))==1:
    print(len(v1)-c1[1][1])
  else:
    print(min(len(v1)-c1[0][1]+len(v2)-c2[1][1]),
                len(v1)-c1[1][1]+len(v2)-c2[0][1])

Submission status: Runtime Error

Solution code:
from itertools import accumulate
from collections import Counter

N = int(input())
v = list(map(int,input().split()))
d = Counter(v).most_common()
most_common = d[0][0]
try:
    second_common = d[1][0]
except:
    print(N//2)
    exit()
try:
    third_common = d[2][0]
except:
    third_common = float('Inf')

def f(v,m,s):
    cnt = 0
    for j in range(N):
        if j % 2 != 0:
            if v[j] != m:
                cnt += 1
        else:
            if v[j] != s:
                cnt += 1
    return cnt

p = [most_common,second_common,third_common]
p = list(product(p,p))
p = [i for i in p if i[0] != i[1]]
ans = float('inf')
for i in p:
    tmp = f(v,i[0],i[1])
    ans = min(ans,tmp)
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int, input().split()))
import collections
v1=v[0::2]
v11=collections.Counter(v1)
v2=v[1::2]
v22=collections.Counter(v2)
ans=0
o=v11.most_common()[0][0]
e=v22.most_common()[0][0]
if e!=o:
    for x in v1:
        if x!=o:
            ans+=1
    for y in v2:
        if y!=e:
            ans+=1
else:
    if v1.count(o)>v2.count(e):
        for x in v1:
            if x!=o:
                ans+=1
        for y in v2:
            if y!=v22.most_common()[1][0]:
                ans+=1
    else:
        for x in v1:
            if x!=v11.most_common()[1][0]:
                ans+=1
        for y in v2:
            if y!=v2:
                ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
V = list(map(int,input().split()))
even = [0] * 100001
odd  = [0] * 100001

for v in V[1::2]:
    even[v] += 1
for v in V[::2]:
    odd[v]  += 1
maxeven = max(even)
maxodd  = max(odd)
if(even.index(maxeven) != odd.index(maxodd)):
    print(n - maxeven - maxodd)
else:
    even.sort()
    odd.sort()
    print(min(n-even[-1]-odd[-2]),n-even[-2]-odd[-1])

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
V = list(int(i) for i in input().split())
even = V[0::2]
odd =  V[1::2]
even_count = collections.Counter(even).most_common(2)
odd_count = collections.Counter(odd).most_common(2)

if even_count == N/2:
    print(N / 2 - odd_count)
elif odd_count == N/2:
    print(N / 2 - even_count)
else:
    print(N - odd_count - even_count)

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import collections as c
n = int(input())
vls = [int(x) for x in input().split()]
number = set(vls)
countls = []
for i in number:
    ls1 = vls[::2]
    ls2 = vls[1::2]
    a = sum(1 for x in ls1 if x != i)
    mostcommon = ls2.most_common()[0][1]
    b = n/2-mostcommon
    c = sum(1 for x in ls2 if x != i)
    mostcommon = ls1.most_common()[0][1]
    d = n/2-mostcommon
    countls.append(a+b)
    countls.append(c+d)

print(min(countls))

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
vls = [int(x) for x in input().split()]
countls =[]
for i in range(10):
    for j in range(10):
        als = []
        for k in range(n):
            if n % 2 ==0:
                als.append(i)
            else:
                als.append(j)
        count = 0
        for l in range(n):
            if als[l] != vls[l]:
                count += 1
        countls.appen(count)
        count = 0

print(min(countls))

Submission status: Runtime Error

Solution code:
from collections import Counter
 
n = int(input())
v = list(map(int,input().split()))
vo = v[::2]
ve = v[1::2]
co = Counter(vo).most_common()
ce = Counter(ve).most_common()
co.append((-1, 0)) #vが[1,1,1,1]のようなケースへの対応
ce.append((-2, 0)) #頻度の降順に並んでいるのでこの書き方で十分
if co[0][0] != ce[0][0]: #偶奇の最頻の要素が異なる場合
    print(n - co[0][1] - ce[0][1])
else:
    res1 = n - co[0][1] - ce[1][1] #偶数側を書き換える場合
    res2 = n - co[1][1] - ce[0][1] #奇数側を書き換える場合
print(min(res1, res2))