Problem p03244 (python)

Fixed submission:
import collections

n = int(input())

al = [int(l) for l in input().split()]

a = []
b = []
for i, x in enumerate(al):
    if i%2 == 0:
        a.append(x)
    else:
        b.append(x)

ac = collections.Counter(a).most_common()
bc = collections.Counter(b).most_common()

if ac[0][0] != bc[0][0]:
    print(n-ac[0][1]-bc[0][1])
else:
    if len(ac) == 1 and len(bc) == 1:
        print(n-max(ac[0][1], bc[0][1]))
    elif len(ac) == 1:
        print(n-max(ac[0][1], ac[1][1]+bc[0][1]))
    elif len(ac) == 1:
        print(n-max(bc[0][1], ac[0][1]+bc[1][1]))
    else:
        print(n-max(ac[1][1]+bc[0][1], ac[0][1]+bc[1][1]))

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())

al = [int(l) for l in input().split()]

a = []
b = []
for i, x in enumerate(al):
    if i%2 == 0:
        a.append(x)
    else:
        b.append(x)

ac = collections.Counter(a).most_common()
bc = collections.Counter(b).most_common()

if ac[0][0] != bc[0][0]:
    print(n-ac[0][1]-bc[0][1])
else:
    if len(ac) >= 2 and ac[0][1] == ac[1][1]:
        print(n-ac[0][1]-bc[0][1])
    elif len(bc) >= 2 and bc[0][1] == bc[1][1]:
        print(n-ac[0][1]-bc[0][1])

    min_c = n//2

    if len(bc) >= 1:
        min_c = min(min_c, n-ac[0][1]-bc[1][1])
    else:
        min_c = min(min_c, n-ac[0][1])
    if len(ac) >= 1:
        min_c = min(min_c, n-ac[1][1]-bc[0][1])
    else:
        min_c = min(min_c, n-bc[0][1])
        
    if len(ac) >= 1 and len(bc) >= 1:
        min_c = min(min_c, n-bc[1][1]-ac[1][1])
    print(min_c)

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())

al = [int(l) for l in input().split()]

a = []
b = []
for i, x in enumerate(al):
    if i%2 == 0:
        a.append(x)
    else:
        b.append(x)

ac = collections.Counter(a).most_common()
bc = collections.Counter(b).most_common()

if ac[0][0] != bc[0][0]:
    print(n-ac[0][1]-bc[0][1])
else:
    if len(ac) >= 2 and ac[0][1] == ac[1][1]:
        print(n-ac[0][1]-bc[0][1])
    elif len(bc) >= 2 and bc[0][1] == bc[1][1]:
        print(n-ac[0][1]-bc[0][1])

    min_c = n//2

    if len(bc) >= 1:
        min_c = min(min_c, n-ac[0][1]-bc[1][1])
    min_c = min(min_c, n-ac[0][1])
    if len(ac) >= 1:
        min_c = min(min_c, n-ac[1][1]-bc[0][1])
    min_c = min(min_c, n-bc[0][1])
    if len(ac) >= 1 and len(bc) >= 1:
        min_c = min(min_c, n-bc[1][1]-ac[1][1])
    print(min_c)

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())

al = [int(l) for l in input().split()]

a = []
b = []
for i, x in enumerate(al):
    if i%2 == 0:
        a.append(x)
    else:
        b.append(x)

ac = collections.Counter(a).most_common()
bc = collections.Counter(b).most_common()

if ac[0][0] != bc[0][0]:
    print(n-ac[0][1]-bc[0][1])
else:
    if len(ac) >= 2 and ac[0][1] == ac[1][1]:
        print(n-ac[0][1]-bc[0][1])
    elif len(bc) >= 2 and bc[0][1] == bc[1][1]:
        print(n-ac[0][1]-bc[0][1])

    min_c = n//2

    if len(bc) >= 1:
        min_c = min(min_c, n-ac[0][1]-bc[1][1])
    min_c = min(min_c, n-ac[0][1])
    if len(ac) >= 1:
        min_c = min(min_c, n-ac[1][1]-bc[0][1])
    min_c = min(min_c, n-bc[0][1])
    if len(ac) >= 1 and len(bc) >= 1:
        min_c = min(min_c, n-bc[1][1]-ac[1][1])
    print(min_c)

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())

al = [int(l) for l in input().split()]

a = []
b = []
for i, x in enumerate(al):
    if i%2 == 0:
        a.append(x)
    else:
        b.append(x)

ac = collections.Counter(a).most_common()
bc = collections.Counter(b).most_common()

if ac[0][0] != bc[0][0]:
    print(n-ac[0][1]-bc[0][1])
else:
    if len(ac) > 0 and ac[0][1] == ac[1][1]:
        print(n-ac[0][1]-bc[0][1])
    elif len(bc) > 0 and bc[0][1] == bc[1][1]:
        print(n-ac[0][1]-bc[0][1])
    elif ac[0][1] >= bc[0][1]:
        if len(bc) <= 1:
            print(n-ac[0][1])
        else:
            print(n-ac[0][1]-bc[1][1])
    else:
        if len(ac) <= 1:
            print(n-bc[0][1])
        else:
            print(n-ac[1][1]-bc[0][1])