Problem p03246 (python)

Fixed submission:
import collections
n = int(input())
v = list(map(int, input().split()))
a = []
b = []
for i in range(n // 2):
    a.append(v[(i+1)*2-1])
    b.append(v[(i+1)*2-2])
a = collections.Counter(a)
b = collections.Counter(b)


if a.most_common()[0][0] != b.most_common()[0][0]:
    print(n - a.most_common()[0][1] - b.most_common()[0][1])
elif len(a.most_common()) == 1 and len(b.most_common()) == 1:
    print(n//2)
elif a.most_common()[1][1] + b.most_common()[0][1] > a.most_common()[0][1] + b.most_common()[1][1]:
    print(n - a.most_common()[1][1] - b.most_common()[0][1])
else:
    print(n - a.most_common()[0][1] - b.most_common()[1][1])

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
v = list(map(int, input().split()))
a = []
b = []
for i in range(n // 2):
    a.append(v[(i+1)*2-1])
    b.append(v[(i+1)*2-2])
a = collections.Counter(a)
b = collections.Counter(b)


if a.most_common()[0][0] != b.most_common()[0][0]:
    print(n - a.most_common()[0][1] - b.most_common()[0][1])
elif len(a.most_common()) == 1:
    print(n - a.most_common()[0][1] - b.most_common()[1][1])
elif len(b.most_common()) == 1:
    print(n - a.most_common()[1][1] - b.most_common()[0][1])
elif a.most_common()[1][1] + b.most_common()[0][1] > a.most_common()[0][1] + b.most_common()[1][1]:
    print(n - a.most_common()[1][1] - b.most_common()[0][1])
else:
    print(n - a.most_common()[0][1] - b.most_common()[1][1])

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
v = list(map(int, input().split()))
a = []
b = []
for i in range(n // 2):
    a.append(v[(i+1)*2-1])
    b.append(v[(i+1)*2-2])
a = collections.Counter(a)
b = collections.Counter(b)


if a.most_common()[0][0] != b.most_common()[0][0]:
    print(n-a.most_common()[0][1]-b.most_common()[0][1])
elif a.most_common()[1][1] + b.most_common()[0][1] > a.most_common()[0][1] + b.most_common()[1][1]:
    print(n-a.most_common()[1][1] - b.most_common()[0][1])
else:
    print(n-a.most_common()[0][1] - b.most_common()[1][1])

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
v = list(map(int, input().split()))
a = []
b = []
for i in range(n // 2):
    a.append(v[(i+1)*2-1])
    b.append(v[(i+1)*2-2])
a = collections.Counter(a)
b = collections.Counter(b)


if a.most_common()[0][0] != b.most_common()[0][0]:
    print(n-a.most_common()[0][1]-b.most_common()[0][1])
elif a.most_common()[1][0] + b.most_common()[0][0] > a.most_common()[0][0] + b.most_common()[1][0]:
    print(n-a.most_common()[1][0] - b.most_common()[0][0])
else:
    print(n-a.most_common()[0][0] - b.most_common()[1][0])

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
v = list(map(int, input().split()))
a = []
b = []
for i in range(n // 2):
    a.append(v[(i+1)*2-1])
    b.append(v[(i+1)*2-2])
a = collections.Counter(a)
b = collections.Counter(b)


if a.most_common()[0][0] != b.most_common()[0][0]:
    print(n-a.most_common()[0][1]-b.most_common()[0][1])
elif a.most_common()[1][0] + b.most_common()[0][0] > a.most_common()[0][0] + b.most_common()[1][0]
    print(n-a.most_common()[1][0] - b.most_common()[0][0])
else:
    print(n-a.most_common()[0][0] - b.most_common()[1][0])