Problem p03244 (python)

Fixed submission:
import math
import sys
from itertools import accumulate
from functools import reduce
from collections import Counter
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    L = list(map(int, sys.stdin.readline().split()))
    l = N // 2
    eL = Counter([L[i] for i in range(N) if i % 2 != 0])
    oL = Counter([L[i] for i in range(N) if i % 2 == 0])
    eLc = eL.most_common() # even list most common
    oLc = oL.most_common() # odd  list most common

    if len(eLc) == 1 or len(oLc) == 1:
        if len(eLc) == 1 and len(oLc) == 1:
            if eLc[0] != oLc[0]:
                print(0)
            else:
                print(l)
        elif len(eLc) == 1:
            print((l - oLc[0][1]))
        else:
            print((l - eLc[0][1]))
    else:
        if eLc[0][0] != oLc[0][0]:
            print((l - eLc[0][1]) + (l - oLc[0][1]))
        else:
            print(min((l - eLc[1][1]) + (l - oLc[0][1]), (l - eLc[0][1]) + (l - oLc[1][1])))

Buggy submission (verdict: Runtime Error):
import sys
import math
from fractions import gcd
# import queue
from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

# 奇数側と偶数側でリストを分ける
# それぞれの最大値で置き換える
# 数値が一致してしまった時にどうするか
# 出現数順にソート、辞書を持つ
# 一致している場合とそうでない場合で分ける
# 療法試してmax取る


N =  int(sys.stdin.readline())
L =  list(map(int, sys.stdin.readline().split()))

E = L[::2]
O = L[1::2]

ce = Counter(E)
co = Counter(O)

cem = ce.most_common()
com = co.most_common()

if cem[0] != com[0]:
    print(N - cem[0][1] - com[0][1])
else:
    if len(cem) == 1 or len(com) == 1:
        print(N // 2)
    else:
        print(min(N - (len(E) - cem[0][1]) - (len(O) - cem[0][2]), N - (len(E) - cem[0][2]) - (len(O) - cem[0][1])))

Buggy submission (verdict: Runtime Error):
import math
import sys
from itertools import accumulate
from functools import reduce
from collections import Counter
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    L = list(map(int, sys.stdin.readline().split()))
    eL = Counter([L[i] for i in range(N) if i % 2 != 0])
    oL = Counter([L[i] for i in range(N) if i % 2 == 0])
    eLc = eL.most_common() # even list most common
    oLc = oL.most_common() # odd  list most common

    if eLc[0][0] != oLc[0][0]:
        print(N - (eLc[0][1] + oLc[0][1]))
    else:
        if eLc[0][1] == 1 or oLc[0][1] == 1:
            print(N // 2)
        else:
            print(min(N - (eLc[1][1] + oLc[0][1]), N - (eLc[0][1] + oLc[1][1])))

"""
if len(eLc) == 1 or len(oLc) == 1:
    if len(eLc) == 1 and len(oLc) == 1:
        if eLc[0] != oLc[0]:
            print(0)
        else:
            print(l)
    elif len(eLc) == 1:
        print((l - oLc[0][1]))
    else:
        print((l - eLc[0][1]))
else:
    if eLc[0][0] != oLc[0][0]:
        print((l - eLc[0][1]) + (l - oLc[0][1]))
    else:
        print(min((l - eLc[1][1]) + (l - oLc[0][1]), (l - eLc[0][1]) + (l - oLc[1][1])))
"""