Problem p03244 (python)

Fixed submission:
n = int(input())
v = list(map(int, input().split()))

vo = [0]*(10**5+1)
ve = [0]*(10**5+1)

for i in range(n):
    if i % 2 == 0:
        vo[v[i]] += 1
    else:
        ve[v[i]] += 1

if vo.index(max(vo)) == ve.index(max(ve)):
    ans1 = sum(vo) - max(vo) + sum(ve) - sorted(ve)[-2]
    ans2 = sum(vo) - sorted(vo)[-2] + sum(ve) - max(ve)
    print(min(ans1, ans2))
else:
    print(sum(vo) - max(vo) + sum(ve) - max(ve))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

N = int(input())
L = list(map(int, input().split()))

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


d_even = defaultdict(int)
d_odd = defaultdict(int)

for i in range(N):
    v = L[i]
    if i % 2 == 0:
        d_even[v] += 1
    else:
        d_odd[v] += 1

l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

odd_1 = l_even[0]
even_1 = l_even[0]

if even_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

even_2 = l_even[1]
odd_2 = l_odd[1]

ans = N
ans = min(N, N - odd_1[1] - even_2[1])
ans = min(N, N - odd_2[1] - even_1[1])
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
L = list(map(int, input().split()))
odd = [v for i, v in enumerate(L) if i % 2 == 0]
even = [v for i, v in enumerate(L) if i % 2 == 1]

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


c_odd = sorted(dict(Counter(odd)).items(), key=lambda x: -x[1])
c_even = sorted(dict(Counter(even)).items(), key=lambda x: -x[1])

odd_1 = c_odd[0]
even_1 = c_even[0]
even_2 = c_even[1]

if odd_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

even_2 = c_even[1]
odd_2 = c_odd[1]

ans = N
ans = min(N, N - odd_1[1] - even_2[1])
ans = min(N, N - odd_2[1] - even_1[1])
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
L = list(map(int, input().split()))
odd = [v for i, v in enumerate(L) if i % 2 == 0]
even = [v for i, v in enumerate(L) if i % 2 == 1]

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


c_odd = sorted(dict(Counter(odd)).items(), key=lambda x: -x[1])
c_even = sorted(dict(Counter(even)).items(), key=lambda x: -x[1])

odd_1 = c_odd[0]
odd_2 = c_odd[1]
even_1 = c_even[0]
even_2 = c_even[1]

if odd_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

ans = N
ans = min(N, N - odd_1[1] - even_2[1])
ans = min(N, N - odd_2[1] - even_1[1])
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

N = int(input())
V = list(map(int, input().split()))

if N == 2:
    if V[0] == V[1]:
        print(0)
    else:
        print(1)
    exit()

d_even = defaultdict(int)
d_odd = defaultdict(int)

for i in range(N):
    v = V[i]
    if i % 2 == 0:
        d_even[v] += 1
    else:
        d_odd[v] += 1

l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

if l_even[0][0] != l_odd[0][0]:
    print(N - l_even[0][1] - l_odd[0][1])
else:
    ans1 = N - l_even[0][1] - l_odd[1][1]
    ans2 = N - l_even[1][1] - l_odd[0][1]
    print(min(ans1, ans2))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

N = int(input())
V = list(map(int, input().split()))

d_even = defaultdict(int)
d_odd = defaultdict(int)

for i in range(N):
    v = V[i]
    if i % 2 == 0:
        d_even[v] += 1
    else:
        d_odd[v] += 1

l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

if l_even[0][0] != l_odd[0][0]:
    print(N - l_even[0][1] - l_odd[0][1])
else:
    print(min(N - l_even[0][1] - l_odd[1][1], N - l_even[1][1] - l_odd[0][1]))