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:
import collections
def los(x, y):
    if x < y:
        return -1
    elif x > y:
        return 1
    elif x == y:
        return 0
def fun1(list, i):
    if i%2 == 0 and i < n:
        e.append(list[i])
        fun1(list, i+1)
    elif i%2 == 1 and i < n:
        o.append(list[i])
        fun1(list, i+1)

n = int(input())
list = list(map(lambda x:int(x), input().split(' ')))
e = []
o = []
fun1(list, 0)

ec = collections.Counter(e)
oc = collections.Counter(o)

ec0, ec0n= ec.most_common()[0]
oc0, oc0n= oc.most_common()[0]
try:
    ec1, ec1n= ec.most_common()[1]
except:
    ec1, ec1n= None, None
try:
    oc1, oc1n= oc.most_common()[1]
except:
    oc1, oc1n= None, None


if ec0 == oc0:
    if ec1==None and oc1==None:
        not_change= ec0n
    elif ec1==None:
        d= los(ec0n + oc1n, oc0n)
        if d==0 or d==1:
            not_change= ec0n + oc1n
        elif d==-1:
            not_change= oc0n
    elif oc1==None:
        d= los(oc0n + ec1n, ec0n)
        if d==0 or d==1:
            not_change= oc0n + ec1n
        elif d==-1:
            not_change= ec0n
    else:
        d= los(ec0n+oc1n, ec1n+oc0n)
        if d==0 or d==1:
            not_change= ec0n+oc1n
        elif d==-1:
            not_change= ec1n+oc0n
elif ec0 != oc0:
    not_change= ec0n + oc0n

print(n-not_change)

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
v = list(map(int,input().split()))
a = [v[i] for i in range(n) if i%2==0]
b = [v[i] for i in range(n) if i%2==1]

a = collections.Counter(a)
b = collections.Counter(b)

A = a.most_common()[:2]
B = b.most_common()[:2]
if A[0][0]==B[0][0]:
    print(n-max(A[0][1]+B[1][1],A[1][1]+B[0][1]))
else:
    print(n-A[0][1]-B[0][1])

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
list = list(map(lambda x:int(x), input().split(' ')))
e = []
o = []
def fun1(list, i):
    if i%2 == 0 and i < n:
        e.append(list[i])
        fun1(list, i+1)
    elif i%2 == 1 and i < n:
        o.append(list[i])
        fun1(list, i+1)
fun1(list, 0)
#eとoの準備完了

ce = collections.Counter(e)
co = collections.Counter(o)
cen = ce.most_common()[0][1]
con = co.most_common()[0][1]
print(n-cen-con+2)

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
list = list(map(lambda x:int(x), input().split(' ')))
e = []
o = []
def fun1(list, i):
    if i%2 == 0 and i < n:
        e.append(list[i])
        fun1(list, i+1)
    elif i%2 == 1 and i < n:
        o.append(list[i])
        fun1(list, i+1)
fun1(list, 0)
#eとoの準備完了

ce = collections.Counter(e)
co = collections.Counter(o)
cen = ce.most_common()[0][1]
con = co.most_common()[0][1]
print(n-cen-con)

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
list = list(map(lambda x:int(x), input().split(' ')))
e = o = []
def fun1(list, i):
    if i%2 == 0 and i < n:
        e.append(list[i])
        fun1(list, i+1)
    if i%2 == 1 and i < n:
        o.append(list[i])
        fun1(list, i+1)
    else:
        pass
fun1(list, 0)
#eとoの準備完了

ce = collections.Counter(e)
co = collections.Counter(o)
cen = ce.most_common()[0][1]
con = co.most_common()[0][1]
print(n-cen-con)

Submission status: Runtime Error

Solution code:
import collections
def func(v1,v2):
    ans=0
    c1=dict(collections.Counter(v1))
    c1_val=list(c1.values())
    c1=list(c1.items())
    
    c2=dict(collections.Counter(v2))
    c2_val=list(c2.values())
    c2=list(c2.items())
    if len(c1)!=len(c2):

        if len(c1)==1:
            ans+=sum(c2_val[1:])
        else:
            if c1[0][0]==c2[0][0]:
                ans+= sum(c1_val[1:])+c2_val[0]+sum(c2_val[2:])
            else:
                ans+=sum(c2_val[1:])
    else:
        ans+=sum(c1_val[1:])+(c2_val[1:])
    return ans
n=int(input())
v=list(map(int,input().split()))
v1,v2=v[::2],v[1::2]
if set(v1)==set(v2):
    print(len(v1))
else:
    if set(v1)<set(v2):
        print(func(v1,v2))
    else:
        print(func(v2,v1))

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
v1,v2=v[::2],v[1::2]
c1=collections.Counter(v1)
c2=collections.Counter(v2)
c=[c1,c2]
ans=0
for i in c:
    if len(i)==1:
        val=list(i.keys())[0]
        continue
    else:
        a=list(i.values())
        a.sort(reverse=True)
        if a[0]==val:
            ans+= a[0]+sum(a[:2])
        else:
            ans+=sum(a[:1])
if v1==v2:
    print(len(v1))
else:
    print(ans)

Submission status: Runtime Error

Solution code:
def get_second(a):
	if len(a) == 1:
		return 0
	else:
		a[1][0]

n = int(input())
a = [int(v) for v in input().split()]
nums = [{}, {}]
for i, v in enumerate(a):
	if v in nums[i % 2]:
		nums[i % 2][v] += 1
	else:
		nums[i % 2][v] = 1
evens = sorted([(v, k) for k, v in nums[0].items()], reverse=True)
odds = sorted([(v, k) for k, v in nums[1].items()], reverse=True)
if evens[0][1] != odds[0][1]:
	print(n - evens[0][0] - odds[0][0])
else:
	print(n - max(evens[0][0] + get_second(odds), get_second(evens) + odds[0][0]))

Submission status: Runtime Error

Solution code:
import sys
 
N = int(input())
seq = list(map(int, input().rstrip().split(' ')))

odd = [0] * int(1e5)
even = [0] * int(1e5)

for i in range(0, N, 2):
    even[seq[i]] += 1
    
for i in range(1, N, 2):
    odd[seq[i]] += 1

type_number = 0
for i in range(0, int(1e5)):
    if odd[i] + even[i] > 0:
        type_number += 1

max_even = max(even)
max_odd = max(odd)

count = 0
count += N // 2 - max_even
count += N // 2 - max_odd

if type_number == 1:
    print(N // 2)
else:
    print(count)

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter
 
def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    #偶数列 奇数列
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    #頻値を取り出す
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    ans = -1
    
    #print(even_c)
    #print(odd_c)
    
    #最頻値の比較
    if even_c[0][0] != odd_c[0][0]:
        ans = len(m) - (even_c[0][1] + odd_c[0][1])
    
    #偶数列と奇数列の最頻値の数字が同じかつ、全て同じ数字じゃない
    elif even_c[0][0] == odd_c[0][0] and len(even_c) > 0:
        ans1 = len(m) - (even_c[0][1] + odd_c[1][1])
        ans2 = len(m) - (even_c[1][1] + odd_c[0][1])
        ans = ans1 if ans1 <= ans2 else ans2
    
    #全て同じ
    else:
        ans = even_c[0][1]
        
    #出力
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))

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

def change(list):
    counter = Counter(list)
    m_ap1, m_ap2 = counter.most_common()[0][0], counter.most_common()[1][0]
    l = len(list)
    cnt = 0
    for i in range(l):
        if list[i] != m_ap1:
            cnt1 += 1
        if list[i] != m_ap2:
            cnt2 += 1
    return cnt1, cnt2, m_ap1, m_ap2
ca1, ca2, ma1, ma2 = change(a)
cb1, cb2, mb1, mb2 = change(b)

if ca1+cb1:
    if ma1 != mb1:
        print(ca1+cb1)
    else:
        print(min(ca1+cb2,cb1+ca2))
else:
    print(n//2)

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())
V = list(map(int,input().split()))
even = Counter(V[1::2]).most_common()+([0, 0])
odd = Counter(V[::2]).most_common()+([0, 0])
if(even[0][0] != odd[0][0]):
  print(N-even[0][1]-odd[0][1])
else:
  print(min(N-even[1][1]-odd[0][1], N-even[0][1]-odd[1][1]))

Submission status: Runtime Error

Solution code:
from collections import Counter

n=input()
l=input().split(' ')

p1=l[::2]
p2=l[1::2]

a1=Counter(p1).most_common()
a2=Counter(p2).most_common()

an=0
bn=0
for i in range(len(a1)):
  an = an+a1[i][1]
for i in range(len(a2)):
  bn = bn+a2[i][1]
if a1[0][0] == a2[0][0]:
  ann=an-int(a1[i][1])
  bnn=an-int(b1[i][1])
  if ann>bnn:out=an+bnn
  else: out=ann+bn
else:
  if an>bn:out=bn
  else:out=an
print(out)

Submission status: Runtime Error

Solution code:
from collections import Counter


def main():
    n = int(input())
    v_n = input().split(' ')
    
    gu = Counter(v_n[::2])
    ki = Counter(v_n[1::2])

    guusuu = gu.most_common()
    kisuu = ki.most_common()
    
    if guusuu[0][0]==kisuu[0][0]:
        print(min(n - guusuu[0][1] - kisuu[1][1], n - guusuu[1][1] - kisuu[0][1]))
    else:
        print(n - guusuu[0][1] - kisuu[0][1])

main()

Submission status: Runtime Error

Solution code:
n = int(input())
lst = str(input()).split(' ')

p1 = [0]*10
p2 = [0]*10
for idx in range(n):
	if idx%2 == 0:
		p1[int(lst[idx])] += 1
	else:
		p2[int(lst[idx])] += 1


pp1 = p1.index(max(p1))
pp2 = p2.index(max(p2))
if pp1 == pp2:

	if max(p1) >= max(p2):

		pp1 = p1.index(max(p1))
		pp2 = p2.index(sorted(p2)[-2])
	elif max(p2) > max(p1):
		pp1 = p1.index(sorted(p1)[-2])
		pp2 = p2.index(max(p2))


cnt1 = 0
cnt2 = 0
for idx in range(n):
	if idx%2 == 0:
		if not lst[idx] == str(pp1):
			cnt1 += 1
	else:
		if not lst[idx] == str(pp2):
			cnt2 += 1

print(cnt1 + cnt2)

Submission status: Runtime Error

Solution code:
n = int(input())
lst = str(input()).split(' ')

p1 = [0]*10
p2 = [0]*10
for idx in range(n):
	if idx%2 == 0:
		p1[int(lst[idx])] += 1
	else:
		p2[int(lst[idx])] += 1

pp1 = p1.index(max(p1))
pp2 = p2.index(max(p2))
if pp1 == pp2:
	if max(p1) >= max(p2):
		pp1 = p1.index(max(p1))
		pp2 = p2.index(sorted(p2)[-2])
	elif max(p2) > max(p1):
		pp1 = p1.index(sorted(p1)[-2])
		pp2 = p2.index(max(p2))

cnt1 = 0
cnt2 = 0
for idx in range(n):
	if idx%2 == 0:
		if not lst[idx] == str(pp1):
			cnt1 += 1
	else:
		if not lst[idx] == str(pp2):
			cnt2 += 1

print(cnt1 + cnt2)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]

if len(set(a)) == 1:
    p = int(n/2)
else:
    b0 = set(a[::2])
    if len(b0)==1:
        q0 = 0
        mark00 = a[0]
        count00, count01 = n/2, 0
    else:
        c = Counter(l)
        q0 =  int(n/2) - c.most_common(1)[0][1]
        mark00, mark01 = c.most_common(2)[0][0], c.most_common(2)[1][0]
        count00, count01 = c.most_common(2)[0][1], c.most_common(2)[1][1]

    b1 = set(a[1::2])
    if len(b1)==1:
        q1 = 0
        mark10 = a[1]
        count10, count11 = n/2, 0
    else:
        c = Counter(l)
        q1 =  int(n/2) - c.most_common(1)[0][1]
        mark10, mark11 = c.most_common(2)[0][0], c.most_common(2)[1][0]
        count10, count11 = c.most_common(2)[0][1], c.most_common(2)[1][1]
    if mark00==mark10:
        if count00+count01>count10+count11:
            p = n - (count00+count01)
        else:
            p = n - (count10+count11)
    else:
        p = n - (count00 + count10)

print(p)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]

if len(set(a)) == 1:
    p = int(n/2)
else:
    b0 = set(a[::2])
    if len(b0)==1:
        q0 = 0
        mark00 = b0[0]
        count00, count01 = n/2, 0
    else:
        c = Counter(l)
        q0 =  int(n/2) - c.most_common(1)[0][1]
        mark00, mark01 = c.most_common(2)[0][0], c.most_common(2)[1][0]
        count00, count01 = c.most_common(2)[0][1], c.most_common(2)[1][1]

    b1 = set(a[1::2])
    if len(b1)==1:
        q1 = 0
        mark10 = b1[0]
        count10, count11 = n/2, 0
    else:
        c = Counter(l)
        q1 =  int(n/2) - c.most_common(1)[0][1]
        mark10, mark11 = c.most_common(2)[0][0], c.most_common(2)[1][0]
        count10, count11 = c.most_common(2)[0][1], c.most_common(2)[1][1]
    if mark00==mark10:
        if count00+count01>count10+count11:
            p = n - (count00+count01)
        else:
            p = n - (count10+count11)
    else:
        p = n - (count00 + count10)

print(p)

Submission status: Runtime Error

Solution code:
from collections import Counter

def calculate_mode(data):
    c = Counter(data)
    # すべての要素とその出現回数を取り出します。
    freq_scores = c.most_common()
    #c.most_common内の最も多い要素[0]の最大出現回数[1]を[0][1]で指定
    max_count = freq_scores[0][1]

    modes = []
    #出現回数と最大出現回数が等しいかを確認します。
    for num in freq_scores:
        if num[1] == max_count:
            modes.append(num[0])
    return(modes)



n = int(input())
v = list(map(int, input().split()))
a = v[0::2]
b = v[1::2]
c = v[0::2]
d = v[1::2]
ans = 0

f = max(calculate_mode(a))
g = max(calculate_mode(b))
print(f,g)
if f == g :
    for i in range(len(a)):
        if f == a[i]:
            a.remove(f)
        if g == b[i]:
            b.remove(g)
    f = calculate_mode(a)
    g = calculate_mode(b)


for i in range(len(a)):
    if f != c[i]:
        ans += 1
    if g != d[i]:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
import statistics

def calculate_mode(data):
    c = Counter(data)
    # すべての要素とその出現回数を取り出します。
    freq_scores = c.most_common()
    #c.most_common内の最も多い要素[0]の最大出現回数[1]を[0][1]で指定
    max_count = freq_scores[0][1]

    modes = []
    #出現回数と最大出現回数が等しいかを確認します。
    for num in freq_scores:
        if num[1] == max_count:
            modes.append(num[0])
    return(modes)

n = int(input())
v = list(map(int, input().split()))
a = []
b = []
c = []
d = []
ans = 0
for i in range(len(v)):
    if i%2 == 1:
        a.append(v[i])
        c.append(v[i])
    if i%2 == 0:
        b.append(v[i])
        d.append(v[i])
f = statistics.mode(a)
g = statistics.mode(b)

#if f == g :
    #for i in range(len(a)):
        #if f == a[i]:
            #a.remove(f)
        #if g == b[i]:
            #b.remove(g)
    #f = calculate_mode(a)
    #g = calculate_mode(b)


for i in range(len(a)):
    if f != c[i]:
        ans += 1
    if g != d[i]:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import collections as c
N = int(input())
a = list(map(int,input().split()))
ue = a[0::2]
sita = a[1::2]
dictue = c.defaultdict(int)
dictsita = c.defaultdict(int)
for i in ue:
    dictue[i] += 1
for i in sita:
    dictsita[i] += 1
ue = list(dictue.items())
ue.sort(key=lambda x:x[1])
sita = list(dictsita.items())
sita.sort(key=lambda x:x[1])
m = ue[len(ue)-1]
n = sita[len(sita)-1]
if m[0] == n[0]:
    if len(ue) == 1:
        if len(sita) == 1:
            print(N//2)
        else:
            print(N-sita[len(sita)-2][1])
    else:
        if len(sita) == 1:
            print(N-ue[len(ue)-2])
        else:
            print(min(N-ue[len(ue)-2],N-sita[len(sita)-2]))
else:
    print(N-m[1]-n[1])

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    v = LI()

    vset = set(v)
    if len(vset) == 1:
        print(len(v)//2)
        exit()

    #  n = 10**5
    #  #  v = [10**5 - i%18 for i in range(n)]
    #  v = [random.randint(0, 100) for i in range(n)]
    #  print(v[:10])

    odd = []
    even = []
    for idx, i in enumerate(v):
        if idx % 2 == 0:
            even.append(i)
        else:
            odd.append(i)

    # Counterが速い
    odd_count = collections.Counter(odd)
    even_count = collections.Counter(even)

    #  print(odd_count, even_count)
    if len(odd_count) == len(even_count) == 1:
        # 変更の必要なし
        print(0)
        exit()

    if odd_count.most_common(1)[0][0] != even_count.most_common(1)[0][0]:
        # 楽なほう
        if len(odd_count) == 1:
            even_result = sum([i[1] for i in even_count.most_common(len(even_count))[1:]])
            print(even_result)
        elif len(even_count) == 1:
            odd_result = sum([i[1] for i in odd_count.most_common(len(odd_count))[1:]])
            print(odd_result)
        else:
            odd_result = sum([i[1] for i in odd_count.most_common(len(odd_count))[1:]])
            even_result = sum([i[1] for i in even_count.most_common(len(even_count))[1:]])
            print(odd_result + even_result)
    else:
        # 全部同じ数字にならないようにしたい
        # ２個め同士で比べて、２個めをより多く含んでる方はそっちにしちゃう
        if len(odd_count) == 1:
            even_result = even_count.most_common(1)[0][1]
            even_result += sum([i[1] for i in even_count.most_common(len(even_count))[2:]])
            print(even_result)
        elif len(even_count) == 1:
            odd_result = odd_count.most_common(1)[0][1]
            odd_result += sum([i[1] for i in odd_count.most_common(len(odd_count))[2:]])
            print(odd_result)
        elif odd_count[1][1] > even_count[1][1]:
            # oddは２つめに多いものを不変にする
            # evenは１つめを不変に
            odd_result = odd_count.most_common(1)[0][1]
            even_result = sum([i[1] for i in even_count.most_common(len(even_count))[1:]])
            print(odd_result + even_result)
        else:
            odd_result = sum([i[1] for i in odd_count.most_common(len(odd_count))[1:]])
            even_result = even_count.most_common(1)[0][1]
            print(odd_result + even_result)

main()

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

n = I()
v = LI()

vset = set(v)
if len(vset) == 1:
    print(len(v)//2)
    exit()

#  n = 10**5
#  v = [10**5 - i%18 for i in range(n)]

odd = []
even = []
for idx, i in enumerate(v):
    if idx % 2 == 0:
        even.append(i)
    else:
        odd.append(i)

# Counterが速い
odd_count = collections.Counter(odd)
even_count = collections.Counter(even)

#  print(odd_count, even_count)
if len(odd_count) == len(even_count) == 1:
    # 変更の必要なし
    print(0)
    exit()

if odd_count.most_common(1)[0][0] != even_count.most_common(1)[0][0]:
    # 楽なほう
    if len(odd_count) == 1:
        even_result = sum([i[1] for i in even_count.most_common(len(even_count))[1:]])
        print(even_result)
    elif len(even_count) == 1:
        odd_result = sum([i[1] for i in odd_count.most_common(len(odd_count))[1:]])
        print(odd_result)
    else:
        odd_result = sum([i[1] for i in odd_count.most_common(len(odd_count))[1:]])
        even_result = sum([i[1] for i in even_count.most_common(len(even_count))[1:]])
        print(odd_result + even_result)
else:
    # 全部同じ数字にならないようにしたい
    # ２個め同士で比べて、２個めをより多く含んでる方はそっちにしちゃう
    if len(odd_count) == 1:
        even_result = even_count.most_common(1)[0][1]
        even_result += sum([i[1] for i in even_count.most_common(len(even_count))[2:]])
        print(even_result)
    elif len(even_count) == 1:
        odd_result = odd_count.most_common(1)[0][1]
        odd_result += sum(i[1] for i in odd_count.most_common(len(odd_count))[2:])
        print(odd_result)
    elif odd_count[1][1] > even_count[1][1]:
        # oddは２つめに多いものを不変にする
        # evenは１つめを不変に
        odd_result = odd_count.most_common(1)[0][1]
        even_result = sum([i[1] for i in even_count.most_common(len(even_count))[1:]])
        print(odd_result + even_result)
    else:
        odd_result = sum(i[1] for i in odd_count.most_common(len(odd_count))[1:])
        even_result = even_count.most_common(1)[0][1]
        print(odd_result + even_result)

Submission status: Runtime Error

Solution code:
def ans():
  N = int(input())
  V = list(map(int,input().split()))
  even = [0]*10001
  odd = [0]*10001
  for v in V[1::2]:
    even[v] += 1
  for v in V[::2]:
    odd[v] += 1
  me = max(even)
  mo = max(odd)
  if(even.index(me) != odd.index(mo)):
    print(N - me - mo)
  else:
    even.sort()
    odd.sort()
    print(min(N-even[-1]-odd[-2], N-even[2]-odd[-1]))
ans()

Submission status: Runtime Error

Solution code:
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    even = Counter(v[::2]).most_common()
    odd = Counter(v[1::2]).most_common()
    v_count = Counter(v)

    if len(v_count) == 1:
        print(int(n/2))
    elif even[0][0] != odd[0][0]:
        print(n - even[0][1] - odd[0][1])

    # oddとevenで文字が一緒
    else:
        # 大きい方を採用するのです
        # evenの方が大きかったら
        if even[0][1] > odd[0][1]:
            # oddは2番めに頻出を使うよ
            print(n - even[0][1] - odd[1][1])
        elif even[0][1] < odd[0][1]:
            print(n - even[1][1] - odd[0][1])
        else:
            raise Exception


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    even = Counter(v[::2]).most_common()
    odd = Counter(v[1::2]).most_common()
    v_count = Counter(v)

    if len(v_count) == 1:
        print(int(n/2))

    # oddとevenで文字が一緒
    elif even[0][0] == odd[0][0]:
        # 大きい方を採用するのです
        # evenの方が大きかったら
        if even[0][1] > odd[0][1]:
            # oddは2番めに頻出を使うよ
            print(n - even[0][1] - odd[1][1])
        elif even[0][1] < odd[0][1]:
            print(n - even[1][1] - odd[0][1])
        else:
            raise Exception

    else:
        print(n - even[0][1] - odd[0][1])


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print('{}, {}'.format(x, y))
    
    #x yがlengthを超えたとき
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
    
    #それぞれの出現値が同じ場合
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            return selection(l1, l2, x + 1 , y + 1)
    
    #出現回数を比較
    if l1[x][1] > l2[y][1]:
        return x , y - 1
        
    if l1[x][1] < l2[y][1]:
        return x - 1  , y
    
    return 0, 0

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    #print(even_c)
    #print(odd_c)
    
    e, o = selection(even_c, odd_c, 0 ,0)
    
    e = 0 if e < 0 else e
    o = 0 if o < 0 else o
    
    #print('{}, {}'.format(e, o))
    
    #全部ばらばら
    if (even_c[e][1] + odd_c[o][1] == 2):
        
        #0にならない
        ans = len(m) - 2
        ans = 1 if ans == 0 else ans
        print(ans)
        return
    
    #全部一緒
    if even_c[e][1] == odd_c[o][1] and even_c[e][0] == odd_c[o][0]:
        print(len(m) - even_c[e][1])
        return
    
    print( len(m) - (even_c[e][1] + odd_c[o][1]) )
    
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print('{}, {}'.format(x, y))
    
    x = 0 if x < 0 else x
    y = 0 if y < 0 else y
    
    #x yがlengthを超えたとき
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
    
    #それぞれの出現値が同じ場合
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            return selection(l1, l2, x + 1 , y + 1)
    
    #出現回数を比較
    if l1[x][1] > l2[y][1]:
        return x , y - 1
        
    if l1[x][1] < l2[y][1]:
        return x - 1  , y
    
    return x, y

def main():
    input = sys.stdin.readline
    
    n = int(input())
    if n == 0 : return 0
    
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    #print(even_c)
    #print(odd_c)
    
    e, o = selection(even_c, odd_c, 0 ,0)
    
    #print('{}, {}'.format(e, o))
    
    #全部ばらばら
    if (even_c[e][1] + odd_c[o][1] == 2):
        
        #0にならない
        ans = len(m) - 2
        ans = 1 if ans == 0 else ans
        print(ans)
        return
    
    #全部一緒
    if even_c[e][1] == odd_c[o][1] and even_c[e][0] == odd_c[o][0]:
        print(len(m) - even_c[e][1])
        return
    
    print( len(m) - (even_c[e][1] + odd_c[o][1]) )
    
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print('{}, {}'.format(x, y))
    
    #x yがlengthを超えたとき
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
    
    #それぞれの出現値が同じ場合
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            return selection(l1, l2, x + 1 , y + 1)
    
    #出現回数を比較
    if l1[x][1] > l2[y][1]:
        return x , y - 1
        
    if l1[x][1] < l2[y][1]:
        return x - 1  , y
    
    return x, y

def main():
    input = sys.stdin.readline
    
    n = int(input())
    if n == 0 : return 0
    
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    #print(even_c)
    #print(odd_c)
    
    e, o = selection(even_c, odd_c, 0 ,0)
    
    e = 0 if e < 0 else e
    o = 0 if o < 0 else o
    
    #print('{}, {}'.format(e, o))
    
    #全部ばらばら
    if (even_c[e][1] + odd_c[o][1] == 2):
        
        #0にならない
        ans = len(m) - 2
        ans = 1 if ans == 0 else ans
        print(ans)
        return
    
    #全部一緒
    if even_c[e][1] == odd_c[o][1] and even_c[e][0] == odd_c[o][0]:
        print(len(m) - even_c[e][1])
        return
    
    print( len(m) - (even_c[e][1] + odd_c[o][1]) )
    
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print('{}, {}'.format(x, y))
    
    #x yがlengthを超えたとき
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
    
    #それぞれの出現値が同じ場合
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            return selection(l1, l2, x + 1 , y + 1)
    
    #出現回数を比較
    if l1[x][1] > l2[y][1]:
        return x , y - 1
        
    if l1[x][1] < l2[y][1]:
        return x - 1  , y
    
    return x, y

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    #print(even_c)
    #print(odd_c)
    
    e, o = selection(even_c, odd_c, 0 ,0)
    
    e = 0 if e < 0 else e
    o = 0 if o < 0 else o
    
    #print('{}, {}'.format(e, o))
    
    #全部ばらばら
    if(even_c[e][1] + odd_c[o][1] == 2):
        print(len(m) - 2)
        return
    
    #全部一緒
    if even_c[e][1] == odd_c[o][1] and even_c[e][0] == odd_c[o][0]:
        print(int(len(m) / 2) )
        return
    
    print( len(m) - (even_c[e][1] + odd_c[o][1]) )
    
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter

#[(105, 3), (120, 1), (106, 1), (119, 1)]
def selection(l1, l2, x ,y):
    
    #print('{}, {}'.format(x, y))
    
    #x yがlengthを超えたとき
    if x >= len(l1) or y >= len(l2):
        return x - 1, y - 1
    
    #それぞれの出現値が同じ場合
    if l1[x][0] == l2[y][0]:
            
        #出現回数が同じとき
        if l1[x][1] == l2[y][1]:
            x += 1
            y += 1
            return selection(l1, l2, x ,y)
    
    #出現回数を比較
    if l1[x][1] > l2[y][1]:
        y -= 1
        return x , y
        
    if l1[x][1] < l2[y][1]:
        x -= 1
        return x , y
    
    return x, y

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    #print(even_c)
    #print(odd_c)
    
    e, o = selection(even_c, odd_c, 0 ,0)
    
    e = 0 if e < 0 else e
    o = 0 if o < 0 else o
    
    #print('{}, {}'.format(e, o))
    
    #全部ばらばら
    if(even_c[e][1] + odd_c[o][1] == 2):
        print(len(m) - 2)
        return
    
    #全部一緒
    if even_c[e][1] == odd_c[o][1] and even_c[e][0] == odd_c[o][0]:
        print(int(len(m) / 2) )
        return
    
    print( len(m) - (even_c[e][1] + odd_c[o][1]) )
    
    
if __name__ == '__main__':
    main()