Problem p02862 (python)

Fixed submission:
def getComb(n, k, MOD):
    if n < k:
        return 0
    if n-k < k:
        k = n-k
    comb = 1
    for x in range(n-k+1, n+1):
        comb = (comb * x) % MOD
    d = 1
    for x in range(1, k+1):
        d = (d * x) % MOD
    comb *= pow(d, MOD-2, MOD)
    return comb % MOD
    
X,Y = [int(i) for i in input().split()]
def check(x,y):
    if x/2 == y:
        return 0
    elif x/2 < y:
        return 1
    else:
        return 9
cnt = 0
possible = True
MOD = 10**9 + 7

while True:
    check_num =  check(X,Y)
    if check_num == 0:
        break
    elif check_num == 1:
        X += 1
        Y -= 1
        cnt += 1
    else:
        possible = False
        break
if possible == True:
    n = X // 2 
    r = cnt
    print(getComb(n,r,MOD))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as dt
def factorization(NUM,DICT):
    temp = NUM
    for i in range(2, int(-(-NUM**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //=i
            DICT[i] += cnt
    
    if temp != 1:
        DICT[temp] += 1
    return DICT
    
def nCr(n,r,mod):
    multiple_list = [i for i in range(n,n-r,-1)]
    devide_list = [i for i in range(r,0,-1)]
    
    multiple_dict = dt(int)
    devide_dict = dt(int)
    
    for multiple in multiple_list:
        multiple_dict = factorization(multiple,multiple_dict)
    for devide in devide_list:
        devide_dict = factorization(devide,devide_dict)
    
    for key in devide_dict:
        multiple_dict[key] -= devide_dict[key]
    
    ncr = 1
    
    for key in multiple_dict:
        ncr *= key ** multiple_dict[key]
        ncr %= mod
    
    return ncr
    
X,Y = [int(i) for i in input().split()]
def check(x,y):
    if x/2 == y:
        return 0
    elif x/2 < y:
        return 1
    else:
        return 9
cnt = 0
possible = True
MOD = 10**9 + 7

while True:
    check_num =  check(X,Y)
    if check_num == 0:
        break
    elif check_num == 1:
        X += 1
        Y -= 1
        cnt += 1
    else:
        possible = False
        break
if possible == True:
    n = X // 2 
    r = cnt
    print(nCr(n,r,MOD))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
X,Y = [int(i) for i in input().split()]
def check(x,y):
    if x/2 == y:
        return 0
    elif x/2 < y:
        return 1
    else:
        return 9
cnt = 0
possible = True

def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

def cmb(n,r):
    m = 10**9+7
    res = 1
    for i in range(1,n+1):
        res = res*i%m
    for i in range(1,r+1):
        res = res*mod_inv(i,m)%m
    for i in range(1,n-r+1):
        res = res*mod_inv(i,m)%m
    return res

while True:
    check_num =  check(X,Y)
    if check_num == 0:
        break
    elif check_num == 1:
        X += 1
        Y -= 1
        cnt += 1
    else:
        possible = False
        break
if possible == True:
    n = X / 2 
    r = cnt
    print(cmb(n,r))
else:
    print(0)