Problem p03244 (python)

Fixed submission:
import collections
n = int(input())
v = list(map(int,input().split()))
ve = [v[2*i] for i in range(n//2)]
vo = [v[2*i + 1] for i in range(n//2)]
Cve = collections.Counter(ve)
Cvo = collections.Counter(vo)
Cve1 = Cve.most_common()[0]
Cvo1 = Cvo.most_common()[0]
if len(Cve) == 1 and len(Cvo) == 1: #eo両方1種類
    if Cve1[0] == Cvo1[0]: ans = n//2 #eo top同じ
    else: ans = 0 #eo異なる
elif len(Cve) == 1 and len(Cvo) > 1: #eのみ1種類
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cvo2[1] #eo top同じ
    else: ans = n//2 - Cvo1[1] #eo top異なる
elif len(Cve) > 1 and len(Cvo) == 1: #oのみ1種類
    Cve2 = Cve.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cve2[1] #eo top同じ
    else: ans = n//2 - Cve1[1] #eo top異なる
else:
    Cve2 = Cve.most_common()[1]
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] != Cvo1[0]: ans = n - Cve1[1] - Cvo1[1] #top異なる
    if Cve1[0] == Cvo1[0]:
        if Cve1[1] < Cvo1[1]: ans = n - Cve2[1] - Cvo1[1]
        elif Cve2[1] > Cvo2[1] : ans = n - Cve2[1] - Cvo1[1]
        else: ans = n - Cve1[1] - Cvo2[1]
print(ans)

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
v = list(map(int,input().split()))
ve = [v[2*i] for i in range(n//2)]
vo = [v[2*i + 1] for i in range(n//2)]
Cve = collections.Counter(ve)
Cvo = collections.Counter(vo)
Cve1 = Cve.most_common()[0]
Cvo1 = Cvo.most_common()[0]
if len(Cve) == 1 and len(Cvo) == 1:
    if Cve1[0] == Cvo1[0]: ans = n//2
    else: ans = 0
elif len(Cve) == 1 and len(Cvo) != 1:
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cvo2[1]
    else: ans = n//2 - Cvo1[1]
elif len(Cve) != 1 and len(Cvo) == 1:
    Cve2 = Cve.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cve2[1]
    else: ans = n//2 - Cve1[2]
else:
    Cve2 = Cve.most_common()[1]
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] != Cvo1[0]: ans = n - Cve1[1] - Cvo1[1] 
    if Cve1[0] == Cvo1[0]:
        if Cve1[1] > Cvo1[1]: ans = n - Cve1[1] - Cvo2[1]
        else: ans = n - Cve2[1] - Cvo1[1]
print(ans)

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
v = list(map(int,input().split()))
ve = [v[2*i] for i in range(n//2)]
vo = [v[2*i + 1] for i in range(n//2)]
Cve = collections.Counter(ve)
Cvo = collections.Counter(vo)
Cve1 = Cve.most_common()[0]
Cvo1 = Cvo.most_common()[0]
if len(Cve) == 1 and len(Cvo) == 1:
    if Cve1[0] == Cvo1[0]: ans = n//2
    else: ans = 0
elif len(Cve) == 1 and len(Cvo) != 1:
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cvo2[1]
    else: ans = n//2 - Cvo1[1]
elif len(Cve) != 1 and len(Cvo) == 1:
    Cve2 = Cve.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cve2[1]
    else: ans = n//2 - Cve1[2]
else:
    Cve2 = Cve.most_common()[1]
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] != Cvo1[0]: ans = n - Cve1[1] - Cvo1[1] 
    if Cve1[0] == Cvo1[0]:
        if Cve1[1] > Cvo1[1]: ans = n - Cve1[1] - Cvo2[1]
        else: ans = n - Cve2[1] - Cvo1[1]
print(ans)

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
v = list(map(int,input().split()))
ve = [v[2*i] for i in range(n//2)]
vo = [v[2*i + 1] for i in range(n//2)]
Cve = collections.Counter(ve)
Cvo = collections.Counter(vo)
Cve1 = Cve.most_common()[0]
Cvo1 = Cvo.most_common()[0]
if len(Cve) == 1 and len(Cvo) == 1:
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cvo1[1]
    else: ans = 0
elif len(Cve) == 1 and len(Cvo) != 1:
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cvo2[1]
    else: ans = n//2 - Cvo1[1]
elif len(Cve) != 1 and len(Cvo) == 1:
    Cve2 = Cve.most_common()[1]
    if Cve1[0] == Cvo1[0]: ans = n//2 - Cve2[1]
    else: ans = n//2 - Cve1[2]
else:
    Cve2 = Cve.most_common()[1]
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] != Cvo1[0]: ans = n - Cve1[1] - Cvo1[1] 
    if Cve1[0] == Cvo1[0]:
        if Cve1[1] > Cvo1[1]: ans = n - Cve1[1] - Cvo2[1]
        else: ans = n - Cve2[1] - Cvo1[1]
print(ans)

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
v = list(map(int,input().split()))
ve = [v[2*i] for i in range(n//2)]
vo = [v[2*i + 1] for i in range(n//2)]
Cve = collections.Counter(ve)
Cvo = collections.Counter(vo)
Cve1 = Cve.most_common()[0]
Cvo1 = Cvo.most_common()[0]

# eとoが1種しか数字をもたない
if len(Cve) == 1 and len(Cvo) == 1:
    if Cve1[0] == Cvo1[0]:
        ans = n//2 - Cvo1[1]
    else:
        ans = 0
elif len(Cve) == 1 and len(Cvo) != 1:
    Cvo2 = Cvo.most_common()[1]
    if Cve1[0] == Cvo1[0]:
        ans = n//2 - Cvo2[1]
    else:
        ans = n//2 - Cvo1[1]

elif len(Cve) != 1 and len(Cvo) == 1:
    Cve2 = Cve.most_common()[1]
    if Cve1[0] == Cvo1[0]:
        ans = n//2 - Cve2[1]
    else:
        ans = n//2 - Cve1[2]
else:
    Cve2 = Cve.most_common()[1]
    Cvo2 = Cvo.most_common()[1]

    if Cve1[0] != Cvo1[0]:
        ans = n - Cve1[1] - Cvo1[1] 
    if Cve1[0] == Cvo1[0]:
        if Cve1[1] > Cvo1[1]:
            ans = n - Cve1[1] - Cvo2[1]
        else:
            an