Problem p03244 (python)

Fixed submission:
from collections import Counter


def solve(V):
    n = len(V)
    ac = Counter(V[::2]).most_common(2)
    bc = Counter(V[1::2]).most_common(2)

    if ac[0][0] != bc[0][0]:
        return n - ac[0][1] - bc[0][1]
    else:
        if len(bc) == 1 or len(ac) == 1:
            return n // 2
        else:
            return n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))

Buggy submission (verdict: Runtime Error):
def main(n:int,lst:list)->int:
    lst1 = lst[::2]
    lst2 = lst[1::2]
    ans1 =count2(lst1)
    ans2 =count2(lst2)
    if ans1[0][0] == ans2[0][0]:
        if ans1[1] and ans2[1]:
            return n - max(ans1[0][1] + ans2[1],ans2[0][1] + ans1[1])
        else:
            return n//2
    else:
        return n - ans1[0][1] - ans2[0][1]
def count2(lst):
    lst.sort()
    ans = [["",0],0]
    last =lst[0]
    a = 0
    for e in lst:
        if last == e:
            a +=1
        else:
            ans = check(a,ans)
            last = e
            a = 1
    return check(a,ans)
def check(a,ans):
    if a > ans[0][1]:
        ans[1] = ans[0][1]
        ans[0][0] = e
        ans[0][1] = a
    elif a > ans[1]:
        ans[1] = a
    return ans
n = int(input())
lst = input().split()
print(main(n,lst))

Buggy submission (verdict: Runtime Error):
from collections import Counter
def main(n:int,lst:list)->int:
    lst1 = lst[::2]
    lst2 = lst[1::2]
    c1 = Counter(lst1).most_common()
    c2 = Counter(lst2).most_common()
    if c1[0][0] == c2[0][0]:
        if len(c1)!=1 and len(c2)!=1:
            return n - max(c1[0][1] + c2[1],c2[0][1] + c1[1])
        else:
            return n//2
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = input().split()
print(main(n,lst))

Buggy submission (verdict: Runtime Error):
from collections import Counter
def main(n:int,lst:list)->int:
    lst1 = lst[::2]
    lst2 = lst[1::2]
    c1 = Counter(lst1).most_common(2)
    c2 = Counter(lst2).most_common(2)
    if c1[0][0] == c2[0][0]:
        if len(c1)!=1 and len(c2)!=1:
            return n - max(c1[0][1] + c2[1],c2[0][1] + c1[1])
        else:
            return n//2
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = input().split()
print(main(n,lst))

Buggy submission (verdict: Runtime Error):
from collections import Counter
def main(n:int,lst:list)->int:
    lst1 = [::2]
    lst2 = [1::2]
    c1 = Counter(lst1).most_common(2)
    c2 = Counter(lst2).most_common(2)
    if c1[0][0] == c2[0][0]:
        if len(c1)!=1 and len(c2)!=1:
            return n - max(c1[0][1] + c2[1],c2[0][1] + c1[1])
        else:
            return n//2
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = input().split()
print(main(n,lst))

Buggy submission (verdict: Runtime Error):
def main(n:int,lst:list)->int:
    b = True
    lst1 = []
    lst2 = []
    for e in lst:
        if b:
            lst1.append(e)
        else:
            lst2.append(e)
        b = not b
    lst1.sort()
    lst2.sort()
    c1 = [["",0],0]
    c2 = [["",0],0]
    last =lst1[0]
    a = 0
    for e in lst1:
        if last == e:
            a +=1
        else:
            if a >= c1[0][1]:
                c1[1] = c1[0][1]
                c1[0][0] = e
                c1[0][1] = a
            elif a > c1[1]:
                c1[1] = a
            last = e
            a = 1
    if a >= c1[0][1]:
        c1[1] = c1[0][1]
        c1[0][0] = e
        c1[0][1] = a
    elif a > c1[1]:
        c1[1] = a

    last =lst2[0]
    a = 0
    for e in lst2:
        if last == e:
            a +=1
        else:
            if a >= c2[0][1]:
                c2[1] = c2[0][1]
                c2[0][0] = e
                c2[0][1] = a
            elif a > c2[1]:
                c2[1] = a
            last = e
            a = 1
    if a >= c2[0][1]:
        c2[1] = c2[0][1]
        c2[0][0] = e
        c2[0][1] = a
    elif a > c2[1]:
        c2[1] = a

    if c1[0][0] == c2[0][0]:
        if c1[0][1] > c2[0][1] or(c1[0][1] == c2[0][1] and c2[1] > c1[1]):
            return n - c1[0][1] - c2[1]
        else:
            return n - c2[0][1] - c1[1]
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = input().split())
print(main(n,lst))

Buggy submission (verdict: Runtime Error):
def main(n:int,lst:list)->int:
    b = True
    lst1 = []
    lst2 = []
    for e in lst:
        if b:
            lst1.append(e)
        else:
            lst2.append(e)
        b = not b
    lst1.sort()
    lst2.sort()
    c1 = [["",0],0]
    c2 = [["",0],0]
    last =lst1[0]
    a = 0
    for e in lst1:
        if last == e:
            a +=1
        else:
            if a > c1[0][1]:
                c1[1] = c1[0][1]
                c1[0][0] = e
                c1[0][1] = a
            elif a > c1[1]:
                c1[1] = a
            last = e
            a = 1
    if a > c1[0][1]:
        c1[0][0] = e
        c1[0][1] = a
    elif a > c1[1][1]:
        c1[1][0] = e
        c1[1][1] = a

    last =lst2[0]
    a = 0
    for e in lst2:
        if last == e:
            a +=1
        else:
            if a > c2[0][1]:
                c2[1] = c2[0][1]
                c2[0][0] = e
                c2[0][1] = a
            elif a > c2[1]:
                c2[1] = a
            last = e
            a = 1
    if a > c2[0][1]:
        c2[1] = c2[0][1]
        c2[0][0] = e
        c2[0][1] = a
    elif a > c2[1]:
        c2[1] = a

    if c1[0][0] == c2[0][0]:
        if c1[0][1] > c2[0][1] or(c1[0][1] == c2[0][1] and c2[1][1] > c1[1][1]):
            return n - c1[0][1] - c2[1][1]
        else:
            return n - c2[0][1] - c1[1][1]
    else:
        return n - c1[0][1] - c2[0][1]

n = int(input())
lst = list(map(int,input().split()))
print(main(n,lst))