Problem p03244 (python)

Fixed submission:
import collections

n = int(input())
v = list(map(int, input().split()))
v1 = []
v2 = []
ans = 0

for i in range(n):
    if i % 2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])

c1 = collections.Counter(v1)
mostChar1, mostCount1 = c1.most_common()[0]
#ndChar1, ndCount1 = c1.most_common()[1]

c2 = collections.Counter(v2)
mostChar2, mostCount2 = c2.most_common()[0]
#ndChar2, ndCount2 = c2.most_common()[1]

if mostChar1 == mostChar2:
    if len(c1.most_common()) == 1 and len(c1.most_common()) == 1:
        ans = n // 2
    elif len(c1.most_common()) == 1:
        ndChar2, ndCount2 = c2.most_common()[1]
        ans = n - mostCount1 - ndCount2
    elif len(c2.most_common()) == 1:
        ndChar1, ndCount1 = c1.most_common()[1]
        ans = n - mostCount2 - ndCount1
    else:
        ndChar1, ndCount1 = c1.most_common()[1]
        ndChar2, ndCount2 = c2.most_common()[1]
        temp1 = n - mostCount1 - ndCount2
        temp2 = n - mostCount2 - ndCount1
        ans = min(temp1, temp2)
else:
    ans = n - mostCount1 - mostCount2

print(ans)

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())
v = list(map(int, input().split()))
v1 = []
v2 = []
ans = 0

for i in range(n):
    if i % 2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])

c1 = collections.Counter(v1)
mostChar1, mostCount1 = c1.most_common()[0]
ndChar1, ndCount1 = c1.most_common()[1]

c2 = collections.Counter(v2)
mostChar2, mostCount2 = c2.most_common()[0]
ndChar2, ndCount2 = c2.most_common()[1]

if mostChar1 == mostChar2:
    temp1 = n - mostCount1 - ndCount2
    temp2 = n - mostCount2 - ndCount1
    ans = min(temp1, temp2)
else:
    ans = n - mostCount1 - mostCount2

print(ans)

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())
v = list(map(int, input().split()))
v1 = []
v2 = []
ans = 0

for i in range(n):
    if i % 2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])

c1 = collections.Counter(v1)
mostChar1, mostCount1 = c1.most_common()[0]
2ndChar1, 2ndCount1 = c1.most_common()[1]

c2 = collections.Counter(v2)
mostChar2, mostCount2 = c2.most_common()[0]
2ndChar2, 2ndCount2 = c2.most_common()[1]

if mostChar1 == mostChar2:
    temp1 = n - mostCount1 - 2ndCount2
    temp2 = n - mostCount2 - 2ndCount1
    ans = min(temp1, temp2)
else:
    ans = n - mostCount1 - mostCount2

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
v = list(map(int, input().split()))
v1 = []
v2 = []
ans = 0

for i in range(n):
    if i % 2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])

mostCount1 = 0
mostChar1 = 0
dp1 = [None] * 10000

for i in range(n//2):
    count = 0
    if dp1[v1[i]] is not None:
        count = dp1[v1[i]]
    else:
        dp1[v1[i]] = v1.count(v1[i])
        count = dp1[v1[i]]
#    count = v1.count(v1[i])
    if count > mostCount1:
        mostCount1 = count
        mostChar1 = v1[i]
        if mostCount1 > n//2:
            break

mostCount2 = 0
mostChar2 = 0
dp2 = [None] * 10000

for i in range(n//2):
#    count = v2.count(v2[i])
    count = 0
    if dp2[v2[i]] is not None:
        count = dp2[v2[i]]
    else:
        dp2[v2[i]] = v2.count(v2[i])
        count = dp2[v2[i]]

    if count > mostCount2:
        mostCount2 = count
        mostChar2 = v2[i]
        if mostCount2 > n//2:
            break

if mostChar1 == mostChar2:
    ans = n//2
else:
    ans = n - mostCount1 - mostCount2

print(ans)