Problem p03244 (python)

Fixed submission:
from collections import Counter

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



if ac[0][0] != bc[0][0]:            #奇数列と偶数列の最頻数が同じ要素でない場合
    ans =  n - ac[0][1] - bc[0][1]  #全体の数から書き換える必要がない数（それぞれの最頻値）を引けばよい
else:                               #奇数列と偶数列の最頻数が同じ要素の数の場合
    if len(bc) == 1 or len(ac) == 1:#全部同じ数の場合 
        ans = n // 2
    else: #２番目の最頻数を比較し、大きいほうの列の最も多大きい最頻数ともう一方の列の2番目に大きい最頻数を書き換える
        ans = n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
V =  list(map(int,input().split()))
l = V[0::2]
r = V[1::2]
#print(l,r)
from collections import Counter

l = list(Counter(l).most_common(2))
r = list(Counter(r).most_common(2))

if l[0][0] != r[0][0]:
    ans = N -( l[0][1] + r[0][1])
elif l[0][0] == r[0][0]:
    if len(l) == 1 and len(r) == 1:
        ans = N//2
    elif l[1][1] > r[1][1]:
        ans = N-(l[0][1] +  r[1][1])
    elif l[1][1] < r[1][1]:
        ans = N-(l[1][1] +  r[0][1])

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
V =  list(map(int,input().split()))
l = V[0::2]
r = V[1::2]
#print(l,r)
from collections import Counter

l = list(Counter(l).most_common(2))
r = list(Counter(r).most_common(2))

if l[0][0] != r[0][0]:
    ans = N -( l[0][1] + r[0][1])
elif l[0][0] == r[0][0]:
    if len(l) == 1 or len(r) == 1:
        ans = N//2
    elif l[1][1] > r[1][1]:
        ans = N-(l[0][1] +  r[1][1])
    elif l[1][1] < r[1][1]:
        ans = N-(l[1][1] +  r[0][1])

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
V = list(map(int, input().split()))

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

even =Counter(even)
even = list(even.items())
even = sorted(even,key=itemgetter(1),reverse = True)

odd =Counter(odd)
odd = list(odd.items())
odd = sorted(odd,key=itemgetter(1),reverse = True)

cnt = 0
if len(odd) == 0 :
    if len(even) == 1:
        cnt = N // 2
    else:
        cnt = 0
elif len(even) == 0 :
    if len(odd) == 1:
        cnt = N // 2
    else:
        cnt = 0
#書き換える数は最頻出の上位２つ以外、つまりn-(even[0][1]+even[1][1])
elif even[0][1] != odd[0][1]:
    cnt = N - (even[0][1] + odd[0][1])
elif odd[0][1] == even[0][1]:
    if even[1][1] > odd[1][1]:
        cnt = N- (odd[0][1] + even[1][1])
    elif odd[1][1] > even[1][1]:
        cnt = N- (even[0][1] + odd[1][1])

print(cnt)

Buggy submission (verdict: Runtime Error):
from collections import Counter
from operator import itemgetter

N = int(input())
V = Counter(map(int, input().split()))

C = list(V.items())
C = sorted(C,key=itemgetter(1),reverse = True)
#print(C)

even = []
odd = []
for i in range(min(len(C),100)):
    if C[i][0] % 2 ==0:
        even.append(C[i])
    else:
        odd.append(C[i])
cnt = 0
if even[0][1] != odd[0][1]:
    for i in range(1,len(odd)):
        cnt += even[i][1]
    for i in range(1,len(even)):
        cnt += odd[i][1]
print(cnt)

Buggy submission (verdict: Runtime Error):
from collections import Counter
from operator import itemgetter

N = int(input())
V = Counter(map(int, input().split()))

#print(V)
#A = list(V.keys())
#B = list(V.values())
C = list(V.items())
C = sorted(C,key=itemgetter(0))

if len(C) == 3:
    ans = abs(C[0][1]- C[2][1])
elif len(C) == 2:
    ans = 0
elif len(C) == 1:
    ans = 2
print(ans)