Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    S = list(map(int, input().split()))
    odd = {}
    even = {}
    for i in range(N):
        if i % 2 == 0:
            if S[i] not in even:
                even[S[i]] = 1
            else:
                even[S[i]] += 1
        else:
            if S[i] not in odd:
                odd[S[i]] = 1
            else:
                odd[S[i]] += 1

    n = 1000000000
    even_max1 = None
    even_max2 = None
    for ek, ev in even.items():
        if even_max1 is None:
            even_max1 = ek
        elif even_max2 is None:
            even_max2 = ek
        elif ev > even[even_max1]:
            even_max1 = ek
        elif ev > even[even_max2]:
            even_max2 = ek

    odd_max1 = None
    odd_max2 = None
    for ok, ov in odd.items():
        if odd_max1 is None:
            odd_max1 = ok
        elif odd_max2 is None:
            odd_max2 = ok
        elif ov > odd[odd_max1]:
            odd_max1 = ok
        elif ov > odd[odd_max2]:
            odd_max2 = ok

    n = min(n, N - even[even_max1] - odd[odd_max1] if even_max1 != odd_max1 else
            N - max(even[even_max1], odd[odd_max1]))
    if even_max2 is not None:
        n = min(n, N - even[even_max1] - odd[odd_max2] if even_max1 != odd_max2 else
                N - max(even[even_max1], odd[odd_max2]))
        n = min(n, N - even[even_max2] - odd[odd_max1] if even_max2 != odd_max1 else
                N - max(even[even_max2], odd[odd_max1]))
        n = min(n, N - even[even_max2] - odd[odd_max2] if even_max2 != odd_max2 else
                N - max(even[even_max2], odd[odd_max2]))

    print(n)

main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    S = list(map(int, input().split()))
    odd = {}
    even = {}
    for i in range(N):
        if i % 2 == 0:
            if S[i] not in even:
                even[S[i]] = 1
            else:
                even[S[i]] += 1
        else:
            if S[i] not in odd:
                odd[S[i]] = 1
            else:
                odd[S[i]] += 1

    n = 1000000000
    emk = None
    ev1 = None
    ev2 = 0
    for ek, ev in even.items():
        if emk is None:
            emk = ek
            ev1 = ev
        elif ev > ev1:
            emk = ek
            ev2 = ev1
            ev1 = ev
        elif ev > ev2:
            ev2 = ev

    omk = None
    ov1 = None
    ov2 = 0
    for ok, ov in odd.items():
        if omk is None:
            omk = ok
            ov1 = ov
        elif ov > ov1:
            omk = ok
            ov2 = ov1
            ov1 = ov
        elif ov > ov2:
            ov2 = ov

    if emk != omk:
        n = min(n, N - ev1 - ov1)
    else:
        n = min(n, N - ev1 - ov2, N - ev2 - ov1)

    print(n)

main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    S = list(map(int, input().split()))
    odd = {}
    even = {}
    for i in range(N):
        if i % 2 == 0:
            if S[i] not in even:
                even[S[i]] = 1
            else:
                even[S[i]] += 1
        else:
            if S[i] not in odd:
                odd[S[i]] = 1
            else:
                odd[S[i]] += 1

    n = 1000000000
    even_max1 = None
    even_max2 = None
    for ek, ev in even.items():
        if even_max1 is None:
            even_max1 = ek
        elif even_max2 is None:
            even_max2 = ek
        elif ev > even[even_max1]:
            even_max1 = ek
        elif ev > even[even_max2]:
            even_max2 = ek

    odd_max1 = None
    odd_max2 = None
    for ok, ov in odd.items():
        if odd_max1 is None:
            odd_max1 = ok
        elif odd_max2 is None:
            odd_max2 = ok
        elif ov > odd[odd_max1]:
            odd_max1 = ok
        elif ov > odd[odd_max2]:
            odd_max2 = ov

    n = min(n, N - even[even_max1] - odd[odd_max1] if even_max1 != odd_max1 else
            N - max(even[even_max1], odd[odd_max1]))
    if even_max2 is not None:
        n = min(n, N - even[even_max1] - odd[odd_max2] if even_max1 != odd_max2 else
                N - max(even[even_max1], odd[odd_max2]))
        n = min(n, N - even[even_max2] - odd[odd_max1] if even_max2 != odd_max1 else
                N - max(even[even_max2], odd[odd_max1]))
        n = min(n, N - even[even_max2] - odd[odd_max2] if even_max2 != odd_max2 else
                N - max(even[even_max2], odd[odd_max2]))

    print(n)

main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    S = list(map(int, input().split()))
    odd = {}
    even = {}
    for i in range(N):
        if i % 2 == 0:
            if S[i] not in even:
                even[S[i]] = 1
            else:
                even[S[i]] += 1
        else:
            if S[i] not in odd:
                odd[S[i]] = 1
            else:
                odd[S[i]] += 1

    n = 1000000000
    emk = None
    ev1 = None
    ev2 = 0
    for ek, ev in even.items():
        if emk is None:
            emk = ek
            ev1 = ev
        elif ev > ev1:
            emk = ek
            ev2 = ev1
            ev1 = ev
        elif ev > ev2:
            ev2 = ev

    omk = None
    ov1 = None
    ov2 = 0
    for ok, ov in odd.items():
        if omk is None:
            omk = ok
            ov1 = ov
        elif ov > ov1:
            omk = ok
            ov2 = ov1
            ov1 = ov
        elif ov > ov2:
            ov2 = ov

    if emk != omk:
        n = min(n, N - ev1 - ov1)
    else:
        n = min(n, N - ev1 - ov2, N - ev2 - ov1)

    print(n)

main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    S = list(map(int, input().split()))
    odd = {}
    even = {}
    for i in range(N):
        if i % 2 == 0:
            if S[i] not in even:
                even[S[i]] = 1
            else:
                even[S[i]] += 1
        else:
            if S[i] not in odd:
                odd[S[i]] = 1
            else:
                odd[S[i]] += 1

    n = 1000000000
    even_max1 = 0
    even_max2 = 0
    odd_max1 = 0
    odd_max2 = 0
    for ek, ev in even.items():
        if ev > even_max1:
            even_max1 = ev
        elif ev > even_max2:
            even_max2 = ev

    for ok, ov in odd.items():
        if ov > odd_max1:
            odd_max1 = ov
        elif ov > odd_max2:
            odd_max2 = ov

    for ek, ev in even.items():
        if ev < even_max2:
            continue
        for ok, ov in odd.items():
            if ov < odd_max2:
                continue
            if ek == ok:
                n = min(n, N - max(even[ek], odd[ok]))
            else:
                n = min(n, N - even[ek] - odd[ok])
    print(n)

main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    S = list(map(int, input().split()))
    odd = {}
    even = {}
    for i in range(N):
        if i % 2 == 0:
            if S[i] not in even:
                even[S[i]] = 1
            else:
                even[S[i]] += 1
        else:
            if S[i] not in odd:
                odd[S[i]] = 1
            else:
                odd[S[i]] += 1

    n = 1000000000
    emk = None
    ev1 = None
    ev2 = 0
    for ek, ev in even.items():
        if emk is None:
            emk = ek
            ev1 = ev
        elif ev > ev1:
            emk = ek
            ev2 = ev1
            ev1 = ev
        elif ev > ev2:
            ev2 = ev

    omk = None
    ov1 = None
    ov2 = 0
    for ok, ov in odd.items():
        if omk is None:
            omk = ok
            ov1 = ov
        elif ov > ov1:
            omk = ok
            ov2 = ov1
            ov1 = ov
        elif ov > ov2:
            ov2 = ov

    if emk != omk:
        n = min(n, N - ev1 - ov1)
    else:
        n = min(n, N - ev1 - ov2, N - ev2 - ov1)

    print(n)

main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    S = list(map(int, input().split()))
    odd = {}
    even = {}
    for i in range(N):
        if i % 2 == 0:
            if S[i] not in even:
                even[S[i]] = 1
            else:
                even[S[i]] += 1
        else:
            if S[i] not in odd:
                odd[S[i]] = 1
            else:
                odd[S[i]] += 1

    n = 1000000000
    for ek, ev in even.items():
        for ok, ov in odd.items():
            if ek == ok:
                n = min(n, N - max(even[ek], odd[ok]))
            else:
                n = min(n, N - even[ek] - odd[ok])
    print(n)

main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    S = list(map(int, input().split()))
    odd = {}
    even = {}
    for i in range(N):
        if i % 2 == 0:
            if S[i] not in even:
                even[S[i]] = 1
            else:
                even[S[i]] += 1
        else:
            if S[i] not in odd:
                odd[S[i]] = 1
            else:
                odd[S[i]] += 1

    n = 1000000000
    emk = None
    ev1 = None
    ev2 = 0
    for ek, ev in even.items():
        if emk is None:
            emk = ek
            ev1 = ev
        elif ev > ev1:
            emk = ek
            ev2 = ev1
            ev1 = ev
        elif ev > ev2:
            ev2 = ev

    omk = None
    ov1 = None
    ov2 = 0
    for ok, ov in odd.items():
        if omk is None:
            omk = ok
            ov1 = ov
        elif ov > ov1:
            omk = ok
            ov2 = ov1
            ov1 = ov
        elif ov > ov2:
            ov2 = ov

    if emk != omk:
        n = min(n, N - ev1 - ov1)
    else:
        n = min(n, N - ev1 - ov2, N - ev2 - ov1)

    print(n)

main()