Problem p03246 (python)

Fixed submission:
import numpy as np
import collections

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

if N == len(np.where(V == V[0])[0]):
    print(N // 2)
else:
    v0 = [V[i] for i in range(0, N - 1, 2)]
    v1 = [V[i] for i in range(1, N, 2)]
    v0_items = dict(collections.Counter(v0).items())
    v1_items = dict(collections.Counter(v1).items())
    v0_max_key = max(v0_items, key=v0_items.get)
    v1_max_key = max(v1_items, key=v1_items.get)
    
    if v0_max_key == v1_max_key:
        count = v0_items.pop(v0_max_key)
        count = (N // 2) - v1_items.pop(v1_max_key)
        tmp1 = v0_items.pop(max(v0_items, key=v0_items.get))
        tmp2 = v1_items.pop(max(v1_items, key=v1_items.get))
        count += (N // 2) - max(tmp1, tmp2)
        print(count)
    else:
        count = (N // 2) - max(collections.Counter(v0).values())
        count += (N // 2) - max(collections.Counter(v1).values())
        print(count)

Buggy submission (verdict: Runtime Error):
import numpy as np
import collections

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

if N == len(np.where(V == V[0])[0]):
    print(N // 2)
else:
    v0 = [V[i] for i in range(0, N - 1, 2)]
    v1 = [V[i] for i in range(1, N, 2)]
    v0_items = dict(collections.Counter(v0).items())
    v1_items = dict(collections.Counter(v1).items())
    v0_max_key = max(v0_items, key=v0_items.get)
    v1_max_key = max(v1_items, key=v1_items.get)
    
    if v0_max_key == v1_max_key:
        count = v0_items.pop(v0_max_key)
        count = (N // 2) - v1_items.pop(v1_max_key)
        tmp1 = v0_items.pop(v0_max_key)
        tmp2 = v1_items.pop(v1_max_key)
        count += (N // 2) - max(tmp1, tmp2)
        print(count)
    else:
        count = (N // 2) - max(collections.Counter(v0).values())
        count += (N // 2) - max(collections.Counter(v1).values())
        print(count)

Buggy submission (verdict: Runtime Error):
import numpy as np
import collections

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

if N == len(np.where(V == V[0])[0]):
    print(N // 2)
else:
    v0 = [V[i] for i in range(0, N - 1, 2)]
    v1 = [V[i] for i in range(1, N, 2)]
    v0_items = dict(collections.Counter(v0).items())
    v1_items = dict(collections.Counter(v1).items())
    v0_max_key = max(v0_items, key=v0_items.get)
    v1_max_key = max(v1_items, key=v1_items.get)
    
    if v0_max_key == v1_max_key:
        count = v0_items.pop(v0_max_key)
        count = (N // 2) - v1_items.pop(v1_max_key)
        tmp1 = v0_items.pop(v0_max_key)
        tmp2 = v1_items.pop(v1_max_key)
        count += max(tmp1, tmp2)
        print(count)
    else:
        count = (N // 2) - max(collections.Counter(v0).values())
        count += (N // 2) - max(collections.Counter(v1).values())
        print(count)

Buggy submission (verdict: Runtime Error):
import numpy as np
import collections

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

if N == len(np.where(V == V[0])[0]):
    print(N // 2)
else:
    v0 = [V[i] for i in range(0, N - 1, 2)]
    v1 = [V[i] for i in range(1, N, 2)]
    v0_items = dict(collections.Counter(v0).items())
    v1_items = dict(collections.Counter(v1).items())
    v0_max_key = max(v0_items, key=v0_items.get)
    v1_max_key = max(v1_items, key=v1_items.get)
    if v0_max_key == v1_max_key:
        count = v0_items.pop(v0_max_key)
        count = (N // 2) - v1_items.pop(v1_max_key)
        tmp1 = v0_items.pop(v0_max_key)
        tmp2 = v1_items.pop(v1_max_key)
        count += max(tmp1, tmp2)
        
    else:
        count = (N // 2) - max(collections.Counter(v0).values())
        count += (N // 2) - max(collections.Counter(v1).values())
        print(count)