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: 
        ans = n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
odd = v[::2 ]
even = v[1::2]
# def count(aaa):
#     if len(set(aaa))!=1:
#         aaa_max = Counter(aaa).most_common(1)[0][1]
#         aaa_min = len(aaa)-aaa_max
#         most_aaa = Counter(aaa).most_common(1)[0][0]
#     else:
#         aaa_min = 0
#         most_aaa = set(aaa)[0]
#     return int(aaa_min),most_aaa
if len(set(v))==1:
    print(int(n/2))
else:
    if len(set(even))!=1:
        even_max = Counter(even).most_common(1)[0][1]
        even_min = len(even)-even_max
        even_most = Counter(even).most_common(1)[0][0]
    else:
        even_min = 0
        even_most = even[0]
    if len(set(odd))!=1:
        odd_most = Counter(odd).most_common()
        for key in odd_most:
            if key[0]!=even_most:
                odd_max = key[1]
                dd_min = len(odd)-odd_max
                break
    else:
        odd_most = odd[0]
        if odd_most != even_most:
            odd_min = 0
        else:
            odd_min = len(odd)
    print(even_min+odd_min)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
odd = v[::2 ]
even = v[1::2]
# def count(aaa):
#     if len(set(aaa))!=1:
#         aaa_max = Counter(aaa).most_common(1)[0][1]
#         aaa_min = len(aaa)-aaa_max
#         most_aaa = Counter(aaa).most_common(1)[0][0]
#     else:
#         aaa_min = 0
#         most_aaa = set(aaa)[0]
#     return int(aaa_min),most_aaa
if len(set(v))==1:
    print(int(n/2))
else:
    if len(set(even))!=1:
        even_max = Counter(even).most_common(1)[0][1]
        even_min = len(even)-even_max
        even_most = Counter(even).most_common(1)[0][0]
    else:
        aaa_min = 0
        even_most = even[0]
    if len(set(odd))!=1:
        odd_most = Counter(odd).most_common()
        for key in odd_most:
            if key[0]!=even_most:
                odd_max = key[1]
                odd_min = len(odd)-odd_max
                break
    else:
        odd_most = odd[0]
        if odd_most != even_most:
            odd_min = 0
        else:
            odd_min = len(odd)
    print(even_min+odd_min)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
odd = v[::2 ]
even = v[1::2]
# def count(aaa):
#     if len(set(aaa))!=1:
#         aaa_max = Counter(aaa).most_common(1)[0][1]
#         aaa_min = len(aaa)-aaa_max
#         most_aaa = Counter(aaa).most_common(1)[0][0]
#     else:
#         aaa_min = 0
#         most_aaa = set(aaa)[0]
#     return int(aaa_min),most_aaa
if len(set(v))==1:
    print(int(n/2))
else:
    if len(set(even))!=1:
        even_max = Counter(even).most_common(1)[0][1]
        even_min = len(even)-even_max
        even_most = Counter(even).most_common(1)[0][0]
    else:
        aaa_min = 0
        even_most = set(even)[0]
    if len(set(odd))!=1:
        odd_most = Counter(odd).most_common()
        for key in odd_most:
            if key[0]!=even_most:
                odd_max = key[1]
                odd_min = len(odd)-odd_max
                break
    else:
        odd_min = 0
        odd_most = set(odd)[0]
    print(even_min+odd_min)